c# things on physics; remove unused file (runprebuild)

This commit is contained in:
UbitUmarov
2022-10-16 22:36:09 +01:00
parent bce31bda7d
commit 65925027f1
9 changed files with 283 additions and 489 deletions

View File

@@ -53,8 +53,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
get { return m_type; }
}
private OdePrim rootPrim;
private ODEScene _pParentScene;
private readonly OdePrim rootPrim;
private readonly ODEScene _pParentScene;
// Vehicle properties
// WARNING this are working copies for internel use
@@ -77,27 +77,27 @@ namespace OpenSim.Region.PhysicsModule.ubOde
// Linear properties
private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time
private Vector3 m_linearFrictionTimescale = new Vector3(1000, 1000, 1000);
private float m_linearMotorDecayTimescale = 120;
private float m_linearMotorTimescale = 1000;
private Vector3 m_linearFrictionTimescale = new(1000f, 1000f, 1000f);
private float m_linearMotorDecayTimescale = 120f;
private float m_linearMotorTimescale = 1000f;
private Vector3 m_linearMotorOffset = Vector3.Zero;
//Angular properties
private Vector3 m_angularMotorDirection = Vector3.Zero; // angular velocity requested by LSL motor
private float m_angularMotorTimescale = 1000; // motor angular velocity ramp up rate
private float m_angularMotorDecayTimescale = 120; // motor angular velocity decay rate
private Vector3 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000); // body angular velocity decay rate
private float m_angularMotorTimescale = 1000f; // motor angular velocity ramp up rate
private float m_angularMotorDecayTimescale = 120f; // motor angular velocity decay rate
private Vector3 m_angularFrictionTimescale = new(1000f, 1000f, 1000f); // body angular velocity decay rate
//Deflection properties
private float m_angularDeflectionEfficiency = 0;
private float m_angularDeflectionTimescale = 1000;
private float m_linearDeflectionEfficiency = 0;
private float m_linearDeflectionTimescale = 1000;
private float m_angularDeflectionEfficiency = 0f;
private float m_angularDeflectionTimescale = 1000f;
private float m_linearDeflectionEfficiency = 0f;
private float m_linearDeflectionTimescale = 1000f;
//Banking properties
private float m_bankingEfficiency = 0;
private float m_bankingMix = 0;
private float m_bankingTimescale = 1000;
private float m_bankingEfficiency = 0f;
private float m_bankingMix = 0f;
private float m_bankingTimescale = 1000f;
//Hover and Buoyancy properties
private float m_VhoverHeight = 0f;
@@ -122,8 +122,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
private float m_ffactor = 1.0f;
private float m_timestep = 0.02f;
private float m_invtimestep = 50;
private readonly float m_timestep = 0.02f;
private readonly float m_invtimestep = 50;
float m_ampwr;
@@ -687,10 +687,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
return vec;
}
private const float pi = (float)Math.PI;
private const float halfpi = 0.5f * (float)Math.PI;
private const float twopi = 2.0f * pi;
private const float pi = MathF.PI;
private const float halfpi = 0.5f * MathF.PI;
public static Vector3 ubRot2Euler(Quaternion rot)
{
// returns roll in X
@@ -707,28 +706,28 @@ namespace OpenSim.Region.PhysicsModule.ubOde
{
vec.X = 0;
vec.Y = -halfpi;
vec.Z = (float)(-2d * Math.Atan(rot.X / rot.W));
vec.Z = -2f * MathF.Atan(rot.X / rot.W);
}
else if (zX > 0.49999f)
{
vec.X = 0;
vec.Y = halfpi;
vec.Z = (float)(2d * Math.Atan(rot.X / rot.W));
vec.Z = 2f * MathF.Atan(rot.X / rot.W);
}
else
{
vec.Y = (float)Math.Asin(2 * zX);
vec.Y = MathF.Asin(2 * zX);
float sqw = rot.W * rot.W;
float minuszY = rot.X * rot.W - rot.Y * rot.Z;
float zZ = rot.Z * rot.Z + sqw - 0.5f;
vec.X = (float)Math.Atan2(minuszY, zZ);
vec.X = MathF.Atan2(minuszY, zZ);
float yX = rot.Z * rot.W - rot.X * rot.Y; //( have negative ?)
float yY = rot.X * rot.X + sqw - 0.5f;
vec.Z = (float)Math.Atan2(yX, yY);
vec.Z = MathF.Atan2(yX, yY);
}
return vec;
}
@@ -752,25 +751,23 @@ namespace OpenSim.Region.PhysicsModule.ubOde
}
else
{
pitch = (float)Math.Asin(2 * zX);
pitch = MathF.Asin(2 * zX);
float minuszY = rot.X * rot.W - rot.Y * rot.Z;
float zZ = rot.Z * rot.Z + rot.W * rot.W - 0.5f;
roll = (float)Math.Atan2(minuszY, zZ);
roll = MathF.Atan2(minuszY, zZ);
}
return ;
}
internal void Step()
{
IntPtr Body = rootPrim.Body;
SafeNativeMethods.Mass dmass;
SafeNativeMethods.BodyGetMass(Body, out dmass);
SafeNativeMethods.BodyGetMass(Body, out SafeNativeMethods.Mass dmass);
SafeNativeMethods.Quaternion rot = SafeNativeMethods.BodyGetQuaternion(Body);
Quaternion objrotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W); // rotq = rotation of object
Quaternion objrotq = new(rot.X, rot.Y, rot.Z, rot.W); // rotq = rotation of object
Quaternion rotq = objrotq; // rotq = rotation of object
rotq *= m_referenceFrame; // rotq is now rotation in vehicle reference frame
Quaternion irotq = Quaternion.Inverse(rotq);
@@ -781,7 +778,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
Vector3 curAngVel; // angular velocity in world
Vector3 force = Vector3.Zero; // actually linear aceleration until mult by mass in world frame
Vector3 torque = Vector3.Zero;// actually angular aceleration until mult by Inertia in vehicle frame
SafeNativeMethods.Vector3 dtorque = new SafeNativeMethods.Vector3();
SafeNativeMethods.Vector3 dtorque = new();
dvtmp = SafeNativeMethods.BodyGetLinearVel(Body);
curVel.X = dvtmp.X;
@@ -946,7 +943,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
tmpV.Z = -curLocalVel.Z / m_linearFrictionTimescale.Z;
tmpV *= rotq; // to world
if(ldampZ != 0 && Math.Abs(ldampZ) > Math.Abs(tmpV.Z))
if(ldampZ != 0 && MathF.Abs(ldampZ) > MathF.Abs(tmpV.Z))
tmpV.Z = ldampZ;
force.X += tmpV.X;
force.Y += tmpV.Y;
@@ -956,18 +953,14 @@ namespace OpenSim.Region.PhysicsModule.ubOde
// vertical atractor
if (verticalAttractionTimescale < 300)
{
float roll;
float pitch;
float ftmp = m_invtimestep / verticalAttractionTimescale / verticalAttractionTimescale;
float ftmp2 = 0.5f * m_verticalAttractionEfficiency * m_invtimestep;
float ftmp2;
ftmp2 = 0.5f * m_verticalAttractionEfficiency * m_invtimestep;
m_amdampX = ftmp2;
m_ampwr = 1.0f - 0.8f * m_verticalAttractionEfficiency;
GetRollPitch(irotq, out roll, out pitch);
GetRollPitch(irotq, out float roll, out float pitch);
if (roll > halfpi)
roll = pi - roll;
@@ -991,7 +984,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
torque.Y += effpitch * ftmp;
}
if (bankingEfficiency != 0 && Math.Abs(effroll) > 0.01)
if (bankingEfficiency != 0 && MathF.Abs(effroll) > 0.01f)
{
float broll = effroll;
@@ -1004,7 +997,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
broll *= m_bankingEfficiency;
if (m_bankingMix != 0)
{
float vfact = Math.Abs(curLocalVel.X) / 10.0f;
float vfact = MathF.Abs(curLocalVel.X) / 10.0f;
if (vfact > 1.0f) vfact = 1.0f;
if (curLocalVel.X >= 0)
@@ -1014,7 +1007,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
}
// make z rot be in world Z not local as seems to be in sl
broll = broll / m_bankingTimescale;
broll /= m_bankingTimescale;
tmpV = Zrot(irotq);
@@ -1024,7 +1017,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
torque.Y += tmpV.Y;
torque.Z += tmpV.Z;
m_amdampZ = Math.Abs(m_bankingEfficiency) / m_bankingTimescale;
m_amdampZ = MathF.Abs(m_bankingEfficiency) / m_bankingTimescale;
m_amdampY = m_amdampZ;
}
@@ -1053,12 +1046,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde
float tmp;
// get out of x == 0 plane
if(Math.Abs(dirv.X) < 0.001f)
if(MathF.Abs(dirv.X) < 0.001f)
dirv.X = 0.001f;
if (Math.Abs(dirv.Z) > 0.01)
if (MathF.Abs(dirv.Z) > 0.01f)
{
tmp = -(float)Math.Atan2(dirv.Z, dirv.X) * m_angularMotorDirection.Y;
tmp = -MathF.Atan2(dirv.Z, dirv.X) * m_angularMotorDirection.Y;
if(tmp < -4f)
tmp = -4f;
else if(tmp > 4f)
@@ -1069,11 +1062,11 @@ namespace OpenSim.Region.PhysicsModule.ubOde
else
torque.Y -= curLocalAngVel.Y * m_invtimestep;
if (Math.Abs(dirv.Y) > 0.01)
if (MathF.Abs(dirv.Y) > 0.01f)
{
if(mousemodebank)
{
tmp = -(float)Math.Atan2(dirv.Y, dirv.X) * m_angularMotorDirection.X;
tmp = -MathF.Atan2(dirv.Y, dirv.X) * m_angularMotorDirection.X;
if(tmp < -4f)
tmp = -4f;
else if(tmp > 4f)
@@ -1082,7 +1075,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
}
else
{
tmp = (float)Math.Atan2(dirv.Y, dirv.X) * m_angularMotorDirection.Z;
tmp = MathF.Atan2(dirv.Y, dirv.X) * m_angularMotorDirection.Z;
tmp *= invamts;
if(tmp < -4f)
tmp = -4f;
@@ -1147,14 +1140,14 @@ namespace OpenSim.Region.PhysicsModule.ubOde
float ftmp = m_angularDeflectionEfficiency / m_angularDeflectionTimescale;
if (Math.Abs(dirv.Z) > 0.01)
if (MathF.Abs(dirv.Z) > 0.01f)
{
torque.Y += - (float)Math.Atan2(dirv.Z, dirv.X) * ftmp;
torque.Y -= MathF.Atan2(dirv.Z, dirv.X) * ftmp;
}
if (Math.Abs(dirv.Y) > 0.01)
if (MathF.Abs(dirv.Y) > 0.01f)
{
torque.Z += (float)Math.Atan2(dirv.Y, dirv.X) * ftmp;
torque.Z += MathF.Atan2(dirv.Y, dirv.X) * ftmp;
}
}