From 804d4971e236a0e75a51358f3d9c43313d140e5f Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 28 Aug 2016 03:51:20 +0100 Subject: my broken version of vehicle mouse steer on ubOde (no bank,needs better damp) --- OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs | 142 +++++++++++++++------ 1 file changed, 103 insertions(+), 39 deletions(-) (limited to 'OpenSim/Region/PhysicsModules/ubOde') diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs b/OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs index d8a2272..456d9e9 100644 --- a/OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs +++ b/OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs @@ -648,6 +648,10 @@ namespace OpenSim.Region.PhysicsModule.ubOde break; } + // disable mouse steering + m_flags &= ~(VehicleFlag.MOUSELOOK_STEER | + VehicleFlag.MOUSELOOK_BANK | + VehicleFlag.CAMERA_DECOUPLED); m_lmDecay = (1.0f - 1.0f / m_linearMotorDecayTimescale); m_amDecay = 1.0f - 1.0f / m_angularMotorDecayTimescale; @@ -794,6 +798,16 @@ namespace OpenSim.Region.PhysicsModule.ubOde float ldampZ = 0; + bool mousemode = false; + if((m_flags & (VehicleFlag.MOUSELOOK_STEER |VehicleFlag.MOUSELOOK_BANK)) != 0 ) + mousemode = true; + + float bankingEfficiency; + if(mousemode) + bankingEfficiency = 0; + else + bankingEfficiency = m_bankingEfficiency; + // linear motor if (m_lmEfect > 0.01 && m_linearMotorTimescale < 1000) { @@ -967,7 +981,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde torque.Y += effpitch * ftmp; } - if (m_bankingEfficiency != 0 && Math.Abs(effroll) > 0.01) + if (bankingEfficiency != 0 && Math.Abs(effroll) > 0.01) { float broll = effroll; @@ -1018,58 +1032,108 @@ namespace OpenSim.Region.PhysicsModule.ubOde m_amdampZ = 1 / m_angularFrictionTimescale.Z; } - // angular motor - if (m_amEfect > 0.01 && m_angularMotorTimescale < 1000) + if(mousemode) { - tmpV = m_angularMotorDirection - curLocalAngVel; // velocity error - tmpV *= m_amEfect / m_angularMotorTimescale; // error to correct in this timestep - torque.X += tmpV.X * m_ampwr; - torque.Y += tmpV.Y * m_ampwr; - torque.Z += tmpV.Z; + CameraData cam = rootPrim.TryGetCameraData(); + if(cam.Valid && cam.MouseLook) + { + Vector3 dirv = cam.CameraAtAxis * irotq; - m_amEfect *= m_amDecay; + float tmp; + if(Math.Abs(dirv.X) > 0.01f) + { + if (Math.Abs(dirv.Z) > 0.01) + { + tmp = -(float)Math.Atan2(dirv.Z, dirv.X) * m_angularMotorDirection.Y; + if(tmp < -4f) + tmp = -4f; + else if(tmp > 4f) + tmp = 4f; + torque.Y += (tmp - curLocalAngVel.Y) / m_angularMotorTimescale; + } + + if (Math.Abs(dirv.Y) > 0.01) + { + tmp = (float)Math.Atan2(dirv.Y, dirv.X) * m_angularMotorDirection.Z; + if(tmp < -4f) + tmp = -4f; + else if(tmp > 4f) + tmp = 4f; + torque.Z += (tmp - curLocalAngVel.Z) / m_angularMotorTimescale; + } + } + // angular friction + if (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0) + { + torque.X -= curLocalAngVel.X * m_amdampX; + torque.Y -= curLocalAngVel.Y * m_amdampY; + torque.Z -= curLocalAngVel.Z * m_amdampZ; + } + } + else + { + if (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0) + { + torque.X -= curLocalAngVel.X * 10f; + torque.Y -= curLocalAngVel.Y * 10f; + torque.Z -= curLocalAngVel.Z * 10f; + } + } } else - m_amEfect = 0; - - // angular deflection - if (m_angularDeflectionEfficiency > 0) { - Vector3 dirv; - - if (curLocalVel.X > 0.01f) - dirv = curLocalVel; - else if (curLocalVel.X < -0.01f) - // use oposite - dirv = -curLocalVel; - else + // angular motor + if (m_amEfect > 0.01 && m_angularMotorTimescale < 1000) { - // make it fall into small positive x case - dirv.X = 0.01f; - dirv.Y = curLocalVel.Y; - dirv.Z = curLocalVel.Z; - } + tmpV = m_angularMotorDirection - curLocalAngVel; // velocity error + tmpV *= m_amEfect / m_angularMotorTimescale; // error to correct in this timestep + torque.X += tmpV.X * m_ampwr; + torque.Y += tmpV.Y * m_ampwr; + torque.Z += tmpV.Z; - float ftmp = m_angularDeflectionEfficiency / m_angularDeflectionTimescale; + m_amEfect *= m_amDecay; + } + else + m_amEfect = 0; - if (Math.Abs(dirv.Z) > 0.01) + // angular deflection + if (m_angularDeflectionEfficiency > 0) { - torque.Y += - (float)Math.Atan2(dirv.Z, dirv.X) * ftmp; + Vector3 dirv; + + if (curLocalVel.X > 0.01f) + dirv = curLocalVel; + else if (curLocalVel.X < -0.01f) + // use oposite + dirv = -curLocalVel; + else + { + // make it fall into small positive x case + dirv.X = 0.01f; + dirv.Y = curLocalVel.Y; + dirv.Z = curLocalVel.Z; + } + + float ftmp = m_angularDeflectionEfficiency / m_angularDeflectionTimescale; + + if (Math.Abs(dirv.Z) > 0.01) + { + torque.Y += - (float)Math.Atan2(dirv.Z, dirv.X) * ftmp; + } + + if (Math.Abs(dirv.Y) > 0.01) + { + torque.Z += (float)Math.Atan2(dirv.Y, dirv.X) * ftmp; + } } - if (Math.Abs(dirv.Y) > 0.01) + if (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0) { - torque.Z += (float)Math.Atan2(dirv.Y, dirv.X) * ftmp; + torque.X -= curLocalAngVel.X * m_amdampX; + torque.Y -= curLocalAngVel.Y * m_amdampY; + torque.Z -= curLocalAngVel.Z * m_amdampZ; } } - - // angular friction - if (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0) - { - torque.X -= curLocalAngVel.X * m_amdampX; - torque.Y -= curLocalAngVel.Y * m_amdampY; - torque.Z -= curLocalAngVel.Z * m_amdampZ; - } force *= dmass.mass; -- cgit v1.1