mirror of
https://github.com/opensim/opensim.git
synced 2026-08-08 18:25:33 +08:00
make old Ode PInvoke follow ms coding rules
This commit is contained in:
@@ -68,7 +68,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private Vector3 _position;
|
||||
private d.Vector3 _zeroPosition;
|
||||
private SafeNativeMethods.Vector3 _zeroPosition;
|
||||
private bool _zeroFlag = false;
|
||||
private bool m_lastUpdateSent = false;
|
||||
private Vector3 _velocity;
|
||||
@@ -151,7 +151,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
|
||||
internal IntPtr Shell { get; private set; }
|
||||
|
||||
private IntPtr Amotor = IntPtr.Zero;
|
||||
private d.Mass ShellMass;
|
||||
private SafeNativeMethods.Mass ShellMass;
|
||||
|
||||
private int m_eventsubscription = 0;
|
||||
private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate();
|
||||
@@ -569,12 +569,12 @@ namespace OpenSim.Region.PhysicsModule.ODE
|
||||
float yTiltComponent = -movementVector.Y * m_tiltMagnitudeWhenProjectedOnXYPlane;
|
||||
|
||||
//m_log.Debug("[ODE CHARACTER]: changing avatar tilt");
|
||||
d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, xTiltComponent);
|
||||
d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, xTiltComponent); // must be same as lowstop, else a different, spurious tilt is introduced
|
||||
d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, yTiltComponent);
|
||||
d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, yTiltComponent); // same as lowstop
|
||||
d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, 0f);
|
||||
d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f); // same as lowstop
|
||||
SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.LowStop, xTiltComponent);
|
||||
SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.HiStop, xTiltComponent); // must be same as lowstop, else a different, spurious tilt is introduced
|
||||
SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, yTiltComponent);
|
||||
SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, yTiltComponent); // same as lowstop
|
||||
SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, 0f);
|
||||
SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f); // same as lowstop
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -805,11 +805,11 @@ namespace OpenSim.Region.PhysicsModule.ODE
|
||||
|
||||
if (m_pidControllerActive == false)
|
||||
{
|
||||
_zeroPosition = d.BodyGetPosition(Body);
|
||||
_zeroPosition = SafeNativeMethods.BodyGetPosition(Body);
|
||||
}
|
||||
//PidStatus = true;
|
||||
|
||||
d.Vector3 localpos = d.BodyGetPosition(Body);
|
||||
SafeNativeMethods.Vector3 localpos = SafeNativeMethods.BodyGetPosition(Body);
|
||||
Vector3 localPos = new Vector3(localpos.X, localpos.Y, localpos.Z);
|
||||
|
||||
if (!localPos.IsFinite())
|
||||
@@ -824,7 +824,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
|
||||
}
|
||||
|
||||
Vector3 vec = Vector3.Zero;
|
||||
d.Vector3 vel = d.BodyGetLinearVel(Body);
|
||||
SafeNativeMethods.Vector3 vel = SafeNativeMethods.BodyGetLinearVel(Body);
|
||||
|
||||
// m_log.DebugFormat(
|
||||
// "[ODE CHARACTER]: Current velocity in Move() is <{0},{1},{2}>, target {3} for {4}",
|
||||
@@ -848,7 +848,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
|
||||
if (!_zeroFlag)
|
||||
{
|
||||
_zeroFlag = true;
|
||||
_zeroPosition = d.BodyGetPosition(Body);
|
||||
_zeroPosition = SafeNativeMethods.BodyGetPosition(Body);
|
||||
}
|
||||
|
||||
if (m_pidControllerActive)
|
||||
@@ -858,7 +858,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
|
||||
// Avatar to Avatar collisions
|
||||
// Prim to avatar collisions
|
||||
|
||||
d.Vector3 pos = d.BodyGetPosition(Body);
|
||||
SafeNativeMethods.Vector3 pos = SafeNativeMethods.BodyGetPosition(Body);
|
||||
vec.X = (_target_velocity.X - vel.X) * (PID_D) + (_zeroPosition.X - pos.X) * (PID_P * 2);
|
||||
vec.Y = (_target_velocity.Y - vel.Y) * (PID_D) + (_zeroPosition.Y - pos.Y)* (PID_P * 2);
|
||||
if (flying)
|
||||
@@ -906,7 +906,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
|
||||
{
|
||||
// We're colliding with something and we're not flying but we're moving
|
||||
// This means we're walking or running.
|
||||
d.Vector3 pos = d.BodyGetPosition(Body);
|
||||
SafeNativeMethods.Vector3 pos = SafeNativeMethods.BodyGetPosition(Body);
|
||||
vec.Z = (_target_velocity.Z - vel.Z) * PID_D + (_zeroPosition.Z - pos.Z) * PID_P;
|
||||
vec.X = ((_target_velocity.X - vel.X) / 1.2f) * PID_D;
|
||||
vec.Y = ((_target_velocity.Y - vel.Y) / 1.2f) * PID_D;
|
||||
@@ -940,7 +940,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
|
||||
if (vec.IsFinite())
|
||||
{
|
||||
// Apply the total force acting on this avatar
|
||||
d.BodyAddForce(Body, vec.X, vec.Y, vec.Z);
|
||||
SafeNativeMethods.BodyAddForce(Body, vec.X, vec.Y, vec.Z);
|
||||
|
||||
if (!_zeroFlag)
|
||||
AlignAvatarTiltWithCurrentDirectionOfMovement(vec);
|
||||
@@ -956,7 +956,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
|
||||
return;
|
||||
}
|
||||
|
||||
d.Vector3 newVel = d.BodyGetLinearVel(Body);
|
||||
SafeNativeMethods.Vector3 newVel = SafeNativeMethods.BodyGetLinearVel(Body);
|
||||
if (newVel.X >= 256 || newVel.X <= 256 || newVel.Y >= 256 || newVel.Y <= 256 || newVel.Z >= 256 || newVel.Z <= 256)
|
||||
{
|
||||
// m_log.DebugFormat(
|
||||
@@ -972,7 +972,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
|
||||
else
|
||||
newVel.Z = Util.Clamp<float>(newVel.Z, -255f, 255f);
|
||||
|
||||
d.BodySetLinearVel(Body, newVel.X, newVel.Y, newVel.Z);
|
||||
SafeNativeMethods.BodySetLinearVel(Body, newVel.X, newVel.Y, newVel.Z);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -985,16 +985,16 @@ namespace OpenSim.Region.PhysicsModule.ODE
|
||||
internal void UpdatePositionAndVelocity(List<OdeCharacter> defects)
|
||||
{
|
||||
// no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit!
|
||||
d.Vector3 newPos;
|
||||
SafeNativeMethods.Vector3 newPos;
|
||||
try
|
||||
{
|
||||
newPos = d.BodyGetPosition(Body);
|
||||
newPos = SafeNativeMethods.BodyGetPosition(Body);
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
bad = true;
|
||||
defects.Add(this);
|
||||
newPos = new d.Vector3(_position.X, _position.Y, _position.Z);
|
||||
newPos = new SafeNativeMethods.Vector3(_position.X, _position.Y, _position.Z);
|
||||
base.RaiseOutOfBounds(_position); // Tells ScenePresence that there's a problem!
|
||||
m_log.WarnFormat("[ODE CHARACTER]: Avatar Null reference for Avatar {0}, physical actor {1}", Name, m_uuid);
|
||||
|
||||
@@ -1031,11 +1031,11 @@ namespace OpenSim.Region.PhysicsModule.ODE
|
||||
else
|
||||
{
|
||||
m_lastUpdateSent = false;
|
||||
d.Vector3 newVelocity;
|
||||
SafeNativeMethods.Vector3 newVelocity;
|
||||
|
||||
try
|
||||
{
|
||||
newVelocity = d.BodyGetLinearVel(Body);
|
||||
newVelocity = SafeNativeMethods.BodyGetLinearVel(Body);
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
@@ -1102,14 +1102,14 @@ namespace OpenSim.Region.PhysicsModule.ODE
|
||||
}
|
||||
|
||||
// lock (OdeScene.UniversalColliderSyncObject)
|
||||
Shell = d.CreateCapsule(_parent_scene.space, CAPSULE_RADIUS, CAPSULE_LENGTH);
|
||||
Shell = SafeNativeMethods.CreateCapsule(_parent_scene.space, CAPSULE_RADIUS, CAPSULE_LENGTH);
|
||||
|
||||
d.GeomSetCategoryBits(Shell, (uint)m_collisionCategories);
|
||||
d.GeomSetCollideBits(Shell, (uint)m_collisionFlags);
|
||||
SafeNativeMethods.GeomSetCategoryBits(Shell, (uint)m_collisionCategories);
|
||||
SafeNativeMethods.GeomSetCollideBits(Shell, (uint)m_collisionFlags);
|
||||
|
||||
d.MassSetCapsuleTotal(out ShellMass, m_mass, 2, CAPSULE_RADIUS, CAPSULE_LENGTH);
|
||||
Body = d.BodyCreate(_parent_scene.world);
|
||||
d.BodySetPosition(Body, npositionX, npositionY, npositionZ);
|
||||
SafeNativeMethods.MassSetCapsuleTotal(out ShellMass, m_mass, 2, CAPSULE_RADIUS, CAPSULE_LENGTH);
|
||||
Body = SafeNativeMethods.BodyCreate(_parent_scene.world);
|
||||
SafeNativeMethods.BodySetPosition(Body, npositionX, npositionY, npositionZ);
|
||||
|
||||
_position.X = npositionX;
|
||||
_position.Y = npositionY;
|
||||
@@ -1117,45 +1117,45 @@ namespace OpenSim.Region.PhysicsModule.ODE
|
||||
|
||||
m_taintPosition = _position;
|
||||
|
||||
d.BodySetMass(Body, ref ShellMass);
|
||||
d.Matrix3 m_caprot;
|
||||
SafeNativeMethods.BodySetMass(Body, ref ShellMass);
|
||||
SafeNativeMethods.Matrix3 m_caprot;
|
||||
// 90 Stand up on the cap of the capped cyllinder
|
||||
if (_parent_scene.IsAvCapsuleTilted)
|
||||
{
|
||||
d.RFromAxisAndAngle(out m_caprot, 1, 0, 1, (float)(Math.PI / 2));
|
||||
SafeNativeMethods.RFromAxisAndAngle(out m_caprot, 1, 0, 1, (float)(Math.PI / 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
d.RFromAxisAndAngle(out m_caprot, 0, 0, 1, (float)(Math.PI / 2));
|
||||
SafeNativeMethods.RFromAxisAndAngle(out m_caprot, 0, 0, 1, (float)(Math.PI / 2));
|
||||
}
|
||||
|
||||
d.GeomSetRotation(Shell, ref m_caprot);
|
||||
d.BodySetRotation(Body, ref m_caprot);
|
||||
SafeNativeMethods.GeomSetRotation(Shell, ref m_caprot);
|
||||
SafeNativeMethods.BodySetRotation(Body, ref m_caprot);
|
||||
|
||||
d.GeomSetBody(Shell, Body);
|
||||
SafeNativeMethods.GeomSetBody(Shell, Body);
|
||||
|
||||
// The purpose of the AMotor here is to keep the avatar's physical
|
||||
// surrogate from rotating while moving
|
||||
Amotor = d.JointCreateAMotor(_parent_scene.world, IntPtr.Zero);
|
||||
d.JointAttach(Amotor, Body, IntPtr.Zero);
|
||||
d.JointSetAMotorMode(Amotor, dAMotorEuler);
|
||||
d.JointSetAMotorNumAxes(Amotor, 3);
|
||||
d.JointSetAMotorAxis(Amotor, 0, 0, 1, 0, 0);
|
||||
d.JointSetAMotorAxis(Amotor, 1, 0, 0, 1, 0);
|
||||
d.JointSetAMotorAxis(Amotor, 2, 0, 0, 0, 1);
|
||||
d.JointSetAMotorAngle(Amotor, 0, 0);
|
||||
d.JointSetAMotorAngle(Amotor, 1, 0);
|
||||
d.JointSetAMotorAngle(Amotor, 2, 0);
|
||||
Amotor = SafeNativeMethods.JointCreateAMotor(_parent_scene.world, IntPtr.Zero);
|
||||
SafeNativeMethods.JointAttach(Amotor, Body, IntPtr.Zero);
|
||||
SafeNativeMethods.JointSetAMotorMode(Amotor, dAMotorEuler);
|
||||
SafeNativeMethods.JointSetAMotorNumAxes(Amotor, 3);
|
||||
SafeNativeMethods.JointSetAMotorAxis(Amotor, 0, 0, 1, 0, 0);
|
||||
SafeNativeMethods.JointSetAMotorAxis(Amotor, 1, 0, 0, 1, 0);
|
||||
SafeNativeMethods.JointSetAMotorAxis(Amotor, 2, 0, 0, 0, 1);
|
||||
SafeNativeMethods.JointSetAMotorAngle(Amotor, 0, 0);
|
||||
SafeNativeMethods.JointSetAMotorAngle(Amotor, 1, 0);
|
||||
SafeNativeMethods.JointSetAMotorAngle(Amotor, 2, 0);
|
||||
|
||||
// These lowstops and high stops are effectively (no wiggle room)
|
||||
if (_parent_scene.IsAvCapsuleTilted)
|
||||
{
|
||||
d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, -0.000000000001f);
|
||||
d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0.000000000001f);
|
||||
d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, -0.000000000001f);
|
||||
d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.000000000001f);
|
||||
d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0.000000000001f);
|
||||
d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.000000000001f);
|
||||
SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.LowStop, -0.000000000001f);
|
||||
SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0.000000000001f);
|
||||
SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, -0.000000000001f);
|
||||
SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.000000000001f);
|
||||
SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0.000000000001f);
|
||||
SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.000000000001f);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1167,18 +1167,18 @@ namespace OpenSim.Region.PhysicsModule.ODE
|
||||
// to be comprehended in their entirety.
|
||||
#endregion
|
||||
AlignAvatarTiltWithCurrentDirectionOfMovement(Vector3.Zero);
|
||||
d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, 0.08f);
|
||||
d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0f);
|
||||
d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, 0.08f);
|
||||
d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.08f); // must be same as lowstop, else a different, spurious tilt is introduced
|
||||
d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f); // same as lowstop
|
||||
d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.08f); // same as lowstop
|
||||
SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.LowStop, 0.08f);
|
||||
SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0f);
|
||||
SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, 0.08f);
|
||||
SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.08f); // must be same as lowstop, else a different, spurious tilt is introduced
|
||||
SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f); // same as lowstop
|
||||
SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.08f); // same as lowstop
|
||||
}
|
||||
|
||||
// Fudge factor is 1f by default, we're setting it to 0. We don't want it to Fudge or the
|
||||
// capped cyllinder will fall over
|
||||
d.JointSetAMotorParam(Amotor, (int)dParam.FudgeFactor, 0f);
|
||||
d.JointSetAMotorParam(Amotor, (int)dParam.FMax, tensor);
|
||||
SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.FudgeFactor, 0f);
|
||||
SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.FMax, tensor);
|
||||
|
||||
//d.Matrix3 bodyrotation = d.BodyGetRotation(Body);
|
||||
//d.QfromR(
|
||||
@@ -1217,7 +1217,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
|
||||
if (Amotor != IntPtr.Zero)
|
||||
{
|
||||
// Kill the Amotor
|
||||
d.JointDestroy(Amotor);
|
||||
SafeNativeMethods.JointDestroy(Amotor);
|
||||
Amotor = IntPtr.Zero;
|
||||
}
|
||||
|
||||
@@ -1227,14 +1227,14 @@ namespace OpenSim.Region.PhysicsModule.ODE
|
||||
if (Body != IntPtr.Zero)
|
||||
{
|
||||
//kill the body
|
||||
d.BodyDestroy(Body);
|
||||
SafeNativeMethods.BodyDestroy(Body);
|
||||
Body = IntPtr.Zero;
|
||||
}
|
||||
|
||||
if (Shell != IntPtr.Zero)
|
||||
{
|
||||
// lock (OdeScene.UniversalColliderSyncObject)
|
||||
d.GeomDestroy(Shell);
|
||||
SafeNativeMethods.GeomDestroy(Shell);
|
||||
|
||||
_parent_scene.geom_name_map.Remove(Shell);
|
||||
_parent_scene.actor_name_map.Remove(Shell);
|
||||
@@ -1325,7 +1325,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
|
||||
{
|
||||
if (Body != IntPtr.Zero)
|
||||
{
|
||||
d.BodySetPosition(Body, m_taintPosition.X, m_taintPosition.Y, m_taintPosition.Z);
|
||||
SafeNativeMethods.BodySetPosition(Body, m_taintPosition.X, m_taintPosition.Y, m_taintPosition.Z);
|
||||
_position = m_taintPosition;
|
||||
}
|
||||
}
|
||||
@@ -1337,7 +1337,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
|
||||
// FIXME: This is not a good solution since it's subject to a race condition if a force is another
|
||||
// thread sets a new force while we're in this loop (since it could be obliterated by
|
||||
// m_taintForce = Vector3.Zero. Need to lock ProcessTaints() when we set a new tainted force.
|
||||
d.BodyAddForce(Body, m_taintForce.X, m_taintForce.Y, m_taintForce.Z);
|
||||
SafeNativeMethods.BodyAddForce(Body, m_taintForce.X, m_taintForce.Y, m_taintForce.Z);
|
||||
}
|
||||
|
||||
m_taintForce = Vector3.Zero;
|
||||
|
||||
Reference in New Issue
Block a user