mirror of
https://github.com/opensim/opensim.git
synced 2026-08-06 17:32:42 +08:00
my broken version of vehicle mouse steer on ubOde (no bank,needs better damp)
This commit is contained in:
@@ -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,57 +1032,107 @@ 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;
|
||||
}
|
||||
else
|
||||
m_amEfect = 0;
|
||||
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;
|
||||
}
|
||||
|
||||
// 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;
|
||||
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
|
||||
{
|
||||
// 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 (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0)
|
||||
{
|
||||
torque.X -= curLocalAngVel.X * 10f;
|
||||
torque.Y -= curLocalAngVel.Y * 10f;
|
||||
torque.Z -= curLocalAngVel.Z * 10f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// angular friction
|
||||
if (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0)
|
||||
else
|
||||
{
|
||||
torque.X -= curLocalAngVel.X * m_amdampX;
|
||||
torque.Y -= curLocalAngVel.Y * m_amdampY;
|
||||
torque.Z -= curLocalAngVel.Z * m_amdampZ;
|
||||
// angular motor
|
||||
if (m_amEfect > 0.01 && m_angularMotorTimescale < 1000)
|
||||
{
|
||||
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;
|
||||
|
||||
m_amEfect *= m_amDecay;
|
||||
}
|
||||
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
|
||||
{
|
||||
// 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 (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;
|
||||
|
||||
Reference in New Issue
Block a user