make old Ode PInvoke follow ms coding rules

httptests
UbitUmarov 2018-01-14 01:40:49 +00:00
parent 88511bfab2
commit 3d87e37d99
7 changed files with 1023 additions and 1026 deletions

File diff suppressed because it is too large Load Diff

View File

@ -68,7 +68,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private Vector3 _position; private Vector3 _position;
private d.Vector3 _zeroPosition; private SafeNativeMethods.Vector3 _zeroPosition;
private bool _zeroFlag = false; private bool _zeroFlag = false;
private bool m_lastUpdateSent = false; private bool m_lastUpdateSent = false;
private Vector3 _velocity; private Vector3 _velocity;
@ -151,7 +151,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
internal IntPtr Shell { get; private set; } internal IntPtr Shell { get; private set; }
private IntPtr Amotor = IntPtr.Zero; private IntPtr Amotor = IntPtr.Zero;
private d.Mass ShellMass; private SafeNativeMethods.Mass ShellMass;
private int m_eventsubscription = 0; private int m_eventsubscription = 0;
private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate(); private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate();
@ -569,12 +569,12 @@ namespace OpenSim.Region.PhysicsModule.ODE
float yTiltComponent = -movementVector.Y * m_tiltMagnitudeWhenProjectedOnXYPlane; float yTiltComponent = -movementVector.Y * m_tiltMagnitudeWhenProjectedOnXYPlane;
//m_log.Debug("[ODE CHARACTER]: changing avatar tilt"); //m_log.Debug("[ODE CHARACTER]: changing avatar tilt");
d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, xTiltComponent); SafeNativeMethods.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 SafeNativeMethods.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); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, yTiltComponent);
d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, yTiltComponent); // same as lowstop SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, yTiltComponent); // same as lowstop
d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, 0f); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, 0f);
d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f); // same as lowstop SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f); // same as lowstop
} }
/// <summary> /// <summary>
@ -805,11 +805,11 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (m_pidControllerActive == false) if (m_pidControllerActive == false)
{ {
_zeroPosition = d.BodyGetPosition(Body); _zeroPosition = SafeNativeMethods.BodyGetPosition(Body);
} }
//PidStatus = true; //PidStatus = true;
d.Vector3 localpos = d.BodyGetPosition(Body); SafeNativeMethods.Vector3 localpos = SafeNativeMethods.BodyGetPosition(Body);
Vector3 localPos = new Vector3(localpos.X, localpos.Y, localpos.Z); Vector3 localPos = new Vector3(localpos.X, localpos.Y, localpos.Z);
if (!localPos.IsFinite()) if (!localPos.IsFinite())
@ -824,7 +824,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
} }
Vector3 vec = Vector3.Zero; Vector3 vec = Vector3.Zero;
d.Vector3 vel = d.BodyGetLinearVel(Body); SafeNativeMethods.Vector3 vel = SafeNativeMethods.BodyGetLinearVel(Body);
// m_log.DebugFormat( // m_log.DebugFormat(
// "[ODE CHARACTER]: Current velocity in Move() is <{0},{1},{2}>, target {3} for {4}", // "[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) if (!_zeroFlag)
{ {
_zeroFlag = true; _zeroFlag = true;
_zeroPosition = d.BodyGetPosition(Body); _zeroPosition = SafeNativeMethods.BodyGetPosition(Body);
} }
if (m_pidControllerActive) if (m_pidControllerActive)
@ -858,7 +858,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
// Avatar to Avatar collisions // Avatar to Avatar collisions
// Prim 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.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); vec.Y = (_target_velocity.Y - vel.Y) * (PID_D) + (_zeroPosition.Y - pos.Y)* (PID_P * 2);
if (flying) 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 // We're colliding with something and we're not flying but we're moving
// This means we're walking or running. // 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.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.X = ((_target_velocity.X - vel.X) / 1.2f) * PID_D;
vec.Y = ((_target_velocity.Y - vel.Y) / 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()) if (vec.IsFinite())
{ {
// Apply the total force acting on this avatar // 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) if (!_zeroFlag)
AlignAvatarTiltWithCurrentDirectionOfMovement(vec); AlignAvatarTiltWithCurrentDirectionOfMovement(vec);
@ -956,7 +956,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
return; 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) if (newVel.X >= 256 || newVel.X <= 256 || newVel.Y >= 256 || newVel.Y <= 256 || newVel.Z >= 256 || newVel.Z <= 256)
{ {
// m_log.DebugFormat( // m_log.DebugFormat(
@ -972,7 +972,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
else else
newVel.Z = Util.Clamp<float>(newVel.Z, -255f, 255f); 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) internal void UpdatePositionAndVelocity(List<OdeCharacter> defects)
{ {
// no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! // 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 try
{ {
newPos = d.BodyGetPosition(Body); newPos = SafeNativeMethods.BodyGetPosition(Body);
} }
catch (NullReferenceException) catch (NullReferenceException)
{ {
bad = true; bad = true;
defects.Add(this); 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! 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); 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 else
{ {
m_lastUpdateSent = false; m_lastUpdateSent = false;
d.Vector3 newVelocity; SafeNativeMethods.Vector3 newVelocity;
try try
{ {
newVelocity = d.BodyGetLinearVel(Body); newVelocity = SafeNativeMethods.BodyGetLinearVel(Body);
} }
catch (NullReferenceException) catch (NullReferenceException)
{ {
@ -1102,14 +1102,14 @@ namespace OpenSim.Region.PhysicsModule.ODE
} }
// lock (OdeScene.UniversalColliderSyncObject) // 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); SafeNativeMethods.GeomSetCategoryBits(Shell, (uint)m_collisionCategories);
d.GeomSetCollideBits(Shell, (uint)m_collisionFlags); SafeNativeMethods.GeomSetCollideBits(Shell, (uint)m_collisionFlags);
d.MassSetCapsuleTotal(out ShellMass, m_mass, 2, CAPSULE_RADIUS, CAPSULE_LENGTH); SafeNativeMethods.MassSetCapsuleTotal(out ShellMass, m_mass, 2, CAPSULE_RADIUS, CAPSULE_LENGTH);
Body = d.BodyCreate(_parent_scene.world); Body = SafeNativeMethods.BodyCreate(_parent_scene.world);
d.BodySetPosition(Body, npositionX, npositionY, npositionZ); SafeNativeMethods.BodySetPosition(Body, npositionX, npositionY, npositionZ);
_position.X = npositionX; _position.X = npositionX;
_position.Y = npositionY; _position.Y = npositionY;
@ -1117,45 +1117,45 @@ namespace OpenSim.Region.PhysicsModule.ODE
m_taintPosition = _position; m_taintPosition = _position;
d.BodySetMass(Body, ref ShellMass); SafeNativeMethods.BodySetMass(Body, ref ShellMass);
d.Matrix3 m_caprot; SafeNativeMethods.Matrix3 m_caprot;
// 90 Stand up on the cap of the capped cyllinder // 90 Stand up on the cap of the capped cyllinder
if (_parent_scene.IsAvCapsuleTilted) 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 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); SafeNativeMethods.GeomSetRotation(Shell, ref m_caprot);
d.BodySetRotation(Body, 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 // The purpose of the AMotor here is to keep the avatar's physical
// surrogate from rotating while moving // surrogate from rotating while moving
Amotor = d.JointCreateAMotor(_parent_scene.world, IntPtr.Zero); Amotor = SafeNativeMethods.JointCreateAMotor(_parent_scene.world, IntPtr.Zero);
d.JointAttach(Amotor, Body, IntPtr.Zero); SafeNativeMethods.JointAttach(Amotor, Body, IntPtr.Zero);
d.JointSetAMotorMode(Amotor, dAMotorEuler); SafeNativeMethods.JointSetAMotorMode(Amotor, dAMotorEuler);
d.JointSetAMotorNumAxes(Amotor, 3); SafeNativeMethods.JointSetAMotorNumAxes(Amotor, 3);
d.JointSetAMotorAxis(Amotor, 0, 0, 1, 0, 0); SafeNativeMethods.JointSetAMotorAxis(Amotor, 0, 0, 1, 0, 0);
d.JointSetAMotorAxis(Amotor, 1, 0, 0, 1, 0); SafeNativeMethods.JointSetAMotorAxis(Amotor, 1, 0, 0, 1, 0);
d.JointSetAMotorAxis(Amotor, 2, 0, 0, 0, 1); SafeNativeMethods.JointSetAMotorAxis(Amotor, 2, 0, 0, 0, 1);
d.JointSetAMotorAngle(Amotor, 0, 0); SafeNativeMethods.JointSetAMotorAngle(Amotor, 0, 0);
d.JointSetAMotorAngle(Amotor, 1, 0); SafeNativeMethods.JointSetAMotorAngle(Amotor, 1, 0);
d.JointSetAMotorAngle(Amotor, 2, 0); SafeNativeMethods.JointSetAMotorAngle(Amotor, 2, 0);
// These lowstops and high stops are effectively (no wiggle room) // These lowstops and high stops are effectively (no wiggle room)
if (_parent_scene.IsAvCapsuleTilted) if (_parent_scene.IsAvCapsuleTilted)
{ {
d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, -0.000000000001f); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.LowStop, -0.000000000001f);
d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0.000000000001f); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0.000000000001f);
d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, -0.000000000001f); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, -0.000000000001f);
d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.000000000001f); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.000000000001f);
d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0.000000000001f); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0.000000000001f);
d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.000000000001f); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.000000000001f);
} }
else else
{ {
@ -1167,18 +1167,18 @@ namespace OpenSim.Region.PhysicsModule.ODE
// to be comprehended in their entirety. // to be comprehended in their entirety.
#endregion #endregion
AlignAvatarTiltWithCurrentDirectionOfMovement(Vector3.Zero); AlignAvatarTiltWithCurrentDirectionOfMovement(Vector3.Zero);
d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, 0.08f); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.LowStop, 0.08f);
d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0f); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0f);
d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, 0.08f); SafeNativeMethods.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 SafeNativeMethods.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 SafeNativeMethods.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.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 // 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 // capped cyllinder will fall over
d.JointSetAMotorParam(Amotor, (int)dParam.FudgeFactor, 0f); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.FudgeFactor, 0f);
d.JointSetAMotorParam(Amotor, (int)dParam.FMax, tensor); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)dParam.FMax, tensor);
//d.Matrix3 bodyrotation = d.BodyGetRotation(Body); //d.Matrix3 bodyrotation = d.BodyGetRotation(Body);
//d.QfromR( //d.QfromR(
@ -1217,7 +1217,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (Amotor != IntPtr.Zero) if (Amotor != IntPtr.Zero)
{ {
// Kill the Amotor // Kill the Amotor
d.JointDestroy(Amotor); SafeNativeMethods.JointDestroy(Amotor);
Amotor = IntPtr.Zero; Amotor = IntPtr.Zero;
} }
@ -1227,14 +1227,14 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (Body != IntPtr.Zero) if (Body != IntPtr.Zero)
{ {
//kill the body //kill the body
d.BodyDestroy(Body); SafeNativeMethods.BodyDestroy(Body);
Body = IntPtr.Zero; Body = IntPtr.Zero;
} }
if (Shell != IntPtr.Zero) if (Shell != IntPtr.Zero)
{ {
// lock (OdeScene.UniversalColliderSyncObject) // lock (OdeScene.UniversalColliderSyncObject)
d.GeomDestroy(Shell); SafeNativeMethods.GeomDestroy(Shell);
_parent_scene.geom_name_map.Remove(Shell); _parent_scene.geom_name_map.Remove(Shell);
_parent_scene.actor_name_map.Remove(Shell); _parent_scene.actor_name_map.Remove(Shell);
@ -1325,7 +1325,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
{ {
if (Body != IntPtr.Zero) 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; _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 // 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 // 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. // 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; m_taintForce = Vector3.Zero;

View File

@ -93,7 +93,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
private float m_linearMotorDecayTimescale = 0; private float m_linearMotorDecayTimescale = 0;
private float m_linearMotorTimescale = 0; private float m_linearMotorTimescale = 0;
private Vector3 m_lastLinearVelocityVector = Vector3.Zero; private Vector3 m_lastLinearVelocityVector = Vector3.Zero;
private d.Vector3 m_lastPositionVector = new d.Vector3(); private SafeNativeMethods.Vector3 m_lastPositionVector = new SafeNativeMethods.Vector3();
// private bool m_LinearMotorSetLastFrame = false; // private bool m_LinearMotorSetLastFrame = false;
// private Vector3 m_linearMotorOffset = Vector3.Zero; // private Vector3 m_linearMotorOffset = Vector3.Zero;
@ -611,7 +611,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
{ {
m_lastLinearVelocityVector = Vector3.Zero; m_lastLinearVelocityVector = Vector3.Zero;
m_lastAngularVelocity = Vector3.Zero; m_lastAngularVelocity = Vector3.Zero;
m_lastPositionVector = d.BodyGetPosition(Body); m_lastPositionVector = SafeNativeMethods.BodyGetPosition(Body);
} }
internal void Step(float pTimestep, OdeScene pParentScene) internal void Step(float pTimestep, OdeScene pParentScene)
@ -631,8 +631,8 @@ namespace OpenSim.Region.PhysicsModule.ODE
{ {
if (!m_linearMotorDirection.ApproxEquals(Vector3.Zero, 0.01f)) // requested m_linearMotorDirection is significant if (!m_linearMotorDirection.ApproxEquals(Vector3.Zero, 0.01f)) // requested m_linearMotorDirection is significant
{ {
if (!d.BodyIsEnabled(Body)) if (!SafeNativeMethods.BodyIsEnabled(Body))
d.BodyEnable(Body); SafeNativeMethods.BodyEnable(Body);
// add drive to body // add drive to body
Vector3 addAmount = m_linearMotorDirection/(m_linearMotorTimescale/pTimestep); Vector3 addAmount = m_linearMotorDirection/(m_linearMotorTimescale/pTimestep);
@ -662,7 +662,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
// convert requested object velocity to world-referenced vector // convert requested object velocity to world-referenced vector
m_dir = m_lastLinearVelocityVector; m_dir = m_lastLinearVelocityVector;
d.Quaternion rot = d.BodyGetQuaternion(Body); SafeNativeMethods.Quaternion rot = SafeNativeMethods.BodyGetQuaternion(Body);
Quaternion rotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W); // rotq = rotation of object Quaternion rotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W); // rotq = rotation of object
m_dir *= rotq; // apply obj rotation to velocity vector m_dir *= rotq; // apply obj rotation to velocity vector
@ -673,15 +673,15 @@ namespace OpenSim.Region.PhysicsModule.ODE
Vector3 grav = Vector3.Zero; Vector3 grav = Vector3.Zero;
// There is some gravity, make a gravity force vector // There is some gravity, make a gravity force vector
// that is applied after object velocity. // that is applied after object velocity.
d.Mass objMass; SafeNativeMethods.Mass objMass;
d.BodyGetMass(Body, out objMass); SafeNativeMethods.BodyGetMass(Body, out objMass);
// m_VehicleBuoyancy: -1=2g; 0=1g; 1=0g; // m_VehicleBuoyancy: -1=2g; 0=1g; 1=0g;
grav.Z = _pParentScene.gravityz * objMass.mass * (1f - m_VehicleBuoyancy); grav.Z = _pParentScene.gravityz * objMass.mass * (1f - m_VehicleBuoyancy);
// Preserve the current Z velocity // Preserve the current Z velocity
d.Vector3 vel_now = d.BodyGetLinearVel(Body); SafeNativeMethods.Vector3 vel_now = SafeNativeMethods.BodyGetLinearVel(Body);
m_dir.Z = vel_now.Z; // Preserve the accumulated falling velocity m_dir.Z = vel_now.Z; // Preserve the accumulated falling velocity
d.Vector3 pos = d.BodyGetPosition(Body); SafeNativeMethods.Vector3 pos = SafeNativeMethods.BodyGetPosition(Body);
// Vector3 accel = new Vector3(-(m_dir.X - m_lastLinearVelocityVector.X / 0.1f), -(m_dir.Y - m_lastLinearVelocityVector.Y / 0.1f), m_dir.Z - m_lastLinearVelocityVector.Z / 0.1f); // Vector3 accel = new Vector3(-(m_dir.X - m_lastLinearVelocityVector.X / 0.1f), -(m_dir.Y - m_lastLinearVelocityVector.Y / 0.1f), m_dir.Z - m_lastLinearVelocityVector.Z / 0.1f);
Vector3 posChange = new Vector3(); Vector3 posChange = new Vector3();
posChange.X = pos.X - m_lastPositionVector.X; posChange.X = pos.X - m_lastPositionVector.X;
@ -693,33 +693,33 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (pos.X >= (m_BlockingEndPoint.X - (float)1)) if (pos.X >= (m_BlockingEndPoint.X - (float)1))
{ {
pos.X -= posChange.X + 1; pos.X -= posChange.X + 1;
d.BodySetPosition(Body, pos.X, pos.Y, pos.Z); SafeNativeMethods.BodySetPosition(Body, pos.X, pos.Y, pos.Z);
} }
if (pos.Y >= (m_BlockingEndPoint.Y - (float)1)) if (pos.Y >= (m_BlockingEndPoint.Y - (float)1))
{ {
pos.Y -= posChange.Y + 1; pos.Y -= posChange.Y + 1;
d.BodySetPosition(Body, pos.X, pos.Y, pos.Z); SafeNativeMethods.BodySetPosition(Body, pos.X, pos.Y, pos.Z);
} }
if (pos.Z >= (m_BlockingEndPoint.Z - (float)1)) if (pos.Z >= (m_BlockingEndPoint.Z - (float)1))
{ {
pos.Z -= posChange.Z + 1; pos.Z -= posChange.Z + 1;
d.BodySetPosition(Body, pos.X, pos.Y, pos.Z); SafeNativeMethods.BodySetPosition(Body, pos.X, pos.Y, pos.Z);
} }
if (pos.X <= 0) if (pos.X <= 0)
{ {
pos.X += posChange.X + 1; pos.X += posChange.X + 1;
d.BodySetPosition(Body, pos.X, pos.Y, pos.Z); SafeNativeMethods.BodySetPosition(Body, pos.X, pos.Y, pos.Z);
} }
if (pos.Y <= 0) if (pos.Y <= 0)
{ {
pos.Y += posChange.Y + 1; pos.Y += posChange.Y + 1;
d.BodySetPosition(Body, pos.X, pos.Y, pos.Z); SafeNativeMethods.BodySetPosition(Body, pos.X, pos.Y, pos.Z);
} }
} }
if (pos.Z < _pParentScene.GetTerrainHeightAtXY(pos.X, pos.Y)) if (pos.Z < _pParentScene.GetTerrainHeightAtXY(pos.X, pos.Y))
{ {
pos.Z = _pParentScene.GetTerrainHeightAtXY(pos.X, pos.Y) + 2; pos.Z = _pParentScene.GetTerrainHeightAtXY(pos.X, pos.Y) + 2;
d.BodySetPosition(Body, pos.X, pos.Y, pos.Z); SafeNativeMethods.BodySetPosition(Body, pos.X, pos.Y, pos.Z);
} }
// Check if hovering // Check if hovering
@ -748,7 +748,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
{ {
if ((pos.Z - m_VhoverTargetHeight) > .2 || (pos.Z - m_VhoverTargetHeight) < -.2) if ((pos.Z - m_VhoverTargetHeight) > .2 || (pos.Z - m_VhoverTargetHeight) < -.2)
{ {
d.BodySetPosition(Body, pos.X, pos.Y, m_VhoverTargetHeight); SafeNativeMethods.BodySetPosition(Body, pos.X, pos.Y, m_VhoverTargetHeight);
} }
} }
else else
@ -815,12 +815,12 @@ namespace OpenSim.Region.PhysicsModule.ODE
m_dir.Z = 0; m_dir.Z = 0;
} }
m_lastPositionVector = d.BodyGetPosition(Body); m_lastPositionVector = SafeNativeMethods.BodyGetPosition(Body);
// Apply velocity // Apply velocity
d.BodySetLinearVel(Body, m_dir.X, m_dir.Y, m_dir.Z); SafeNativeMethods.BodySetLinearVel(Body, m_dir.X, m_dir.Y, m_dir.Z);
// apply gravity force // apply gravity force
d.BodyAddForce(Body, grav.X, grav.Y, grav.Z); SafeNativeMethods.BodyAddForce(Body, grav.X, grav.Y, grav.Z);
// apply friction // apply friction
@ -841,7 +841,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
*/ */
// Get what the body is doing, this includes 'external' influences // Get what the body is doing, this includes 'external' influences
d.Vector3 angularVelocity = d.BodyGetAngularVel(Body); SafeNativeMethods.Vector3 angularVelocity = SafeNativeMethods.BodyGetAngularVel(Body);
// Vector3 angularVelocity = Vector3.Zero; // Vector3 angularVelocity = Vector3.Zero;
if (m_angularMotorApply > 0) if (m_angularMotorApply > 0)
@ -874,7 +874,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
{ {
float VAservo = 0.2f / (m_verticalAttractionTimescale * pTimestep); float VAservo = 0.2f / (m_verticalAttractionTimescale * pTimestep);
// get present body rotation // get present body rotation
d.Quaternion rot = d.BodyGetQuaternion(Body); SafeNativeMethods.Quaternion rot = SafeNativeMethods.BodyGetQuaternion(Body);
Quaternion rotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W); Quaternion rotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W);
// make a vector pointing up // make a vector pointing up
Vector3 verterr = Vector3.Zero; Vector3 verterr = Vector3.Zero;
@ -923,7 +923,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (!m_lastAngularVelocity.ApproxEquals(Vector3.Zero, 0.01f)) if (!m_lastAngularVelocity.ApproxEquals(Vector3.Zero, 0.01f))
{ {
if (!d.BodyIsEnabled (Body)) d.BodyEnable (Body); if (!SafeNativeMethods.BodyIsEnabled (Body)) SafeNativeMethods.BodyEnable (Body);
} }
else else
{ {
@ -935,14 +935,14 @@ namespace OpenSim.Region.PhysicsModule.ODE
m_lastAngularVelocity -= m_lastAngularVelocity * decayamount; m_lastAngularVelocity -= m_lastAngularVelocity * decayamount;
// Apply to the body // Apply to the body
d.BodySetAngularVel (Body, m_lastAngularVelocity.X, m_lastAngularVelocity.Y, m_lastAngularVelocity.Z); SafeNativeMethods.BodySetAngularVel (Body, m_lastAngularVelocity.X, m_lastAngularVelocity.Y, m_lastAngularVelocity.Z);
} //end MoveAngular } //end MoveAngular
internal void LimitRotation(float timestep) internal void LimitRotation(float timestep)
{ {
d.Quaternion rot = d.BodyGetQuaternion(Body); SafeNativeMethods.Quaternion rot = SafeNativeMethods.BodyGetQuaternion(Body);
Quaternion rotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W); // rotq = rotation of object Quaternion rotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W); // rotq = rotation of object
d.Quaternion m_rot = new d.Quaternion(); SafeNativeMethods.Quaternion m_rot = new SafeNativeMethods.Quaternion();
bool changed = false; bool changed = false;
m_rot.X = rotq.X; m_rot.X = rotq.X;
m_rot.Y = rotq.Y; m_rot.Y = rotq.Y;
@ -975,7 +975,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
changed = true; changed = true;
} }
if (changed) if (changed)
d.BodySetQuaternion(Body, ref m_rot); SafeNativeMethods.BodySetQuaternion(Body, ref m_rot);
} }
} }
} }

View File

@ -63,7 +63,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
// Initializing ODE only when a scene is created allows alternative ODE plugins to co-habit (according to // Initializing ODE only when a scene is created allows alternative ODE plugins to co-habit (according to
// http://opensimulator.org/mantis/view.php?id=2750). // http://opensimulator.org/mantis/view.php?id=2750).
d.InitODE(); SafeNativeMethods.InitODE();
m_scene = new OdeScene(scene, m_config, Name, Version); m_scene = new OdeScene(scene, m_config, Name, Version);
} }

View File

@ -212,7 +212,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
public IntPtr Body = IntPtr.Zero; public IntPtr Body = IntPtr.Zero;
private Vector3 _target_velocity; private Vector3 _target_velocity;
private d.Mass pMass; private SafeNativeMethods.Mass pMass;
private int m_eventsubscription; private int m_eventsubscription;
private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate(); private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate();
@ -356,13 +356,13 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (m_assetFailed) if (m_assetFailed)
{ {
d.GeomSetCategoryBits(prim_geom, 0); SafeNativeMethods.GeomSetCategoryBits(prim_geom, 0);
d.GeomSetCollideBits(prim_geom, (uint)BadMeshAssetCollideBits); SafeNativeMethods.GeomSetCollideBits(prim_geom, (uint)BadMeshAssetCollideBits);
} }
else else
{ {
d.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories); SafeNativeMethods.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories);
d.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags); SafeNativeMethods.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags);
} }
_parent_scene.geom_name_map[prim_geom] = Name; _parent_scene.geom_name_map[prim_geom] = Name;
@ -386,7 +386,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
{ {
if (IsPhysical && Body != IntPtr.Zero) if (IsPhysical && Body != IntPtr.Zero)
{ {
d.BodyEnable(Body); SafeNativeMethods.BodyEnable(Body);
if (m_vehicle.Type != Vehicle.TYPE_NONE) if (m_vehicle.Type != Vehicle.TYPE_NONE)
m_vehicle.Enable(Body, _parent_scene); m_vehicle.Enable(Body, _parent_scene);
} }
@ -401,7 +401,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (IsPhysical && Body != IntPtr.Zero) if (IsPhysical && Body != IntPtr.Zero)
{ {
d.BodyDisable(Body); SafeNativeMethods.BodyDisable(Body);
} }
} }
@ -415,22 +415,22 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (!childPrim) if (!childPrim)
{ {
// Sets the geom to a body // Sets the geom to a body
Body = d.BodyCreate(_parent_scene.world); Body = SafeNativeMethods.BodyCreate(_parent_scene.world);
setMass(); setMass();
d.BodySetPosition(Body, _position.X, _position.Y, _position.Z); SafeNativeMethods.BodySetPosition(Body, _position.X, _position.Y, _position.Z);
d.Quaternion myrot = new d.Quaternion(); SafeNativeMethods.Quaternion myrot = new SafeNativeMethods.Quaternion();
myrot.X = _orientation.X; myrot.X = _orientation.X;
myrot.Y = _orientation.Y; myrot.Y = _orientation.Y;
myrot.Z = _orientation.Z; myrot.Z = _orientation.Z;
myrot.W = _orientation.W; myrot.W = _orientation.W;
d.BodySetQuaternion(Body, ref myrot); SafeNativeMethods.BodySetQuaternion(Body, ref myrot);
d.GeomSetBody(prim_geom, Body); SafeNativeMethods.GeomSetBody(prim_geom, Body);
if (m_assetFailed) if (m_assetFailed)
{ {
d.GeomSetCategoryBits(prim_geom, 0); SafeNativeMethods.GeomSetCategoryBits(prim_geom, 0);
d.GeomSetCollideBits(prim_geom, (uint)BadMeshAssetCollideBits); SafeNativeMethods.GeomSetCollideBits(prim_geom, (uint)BadMeshAssetCollideBits);
} }
else else
{ {
@ -438,14 +438,14 @@ namespace OpenSim.Region.PhysicsModule.ODE
m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind); m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
} }
d.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories); SafeNativeMethods.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories);
d.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags); SafeNativeMethods.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags);
d.BodySetAutoDisableFlag(Body, true); SafeNativeMethods.BodySetAutoDisableFlag(Body, true);
d.BodySetAutoDisableSteps(Body, body_autodisable_frames); SafeNativeMethods.BodySetAutoDisableSteps(Body, body_autodisable_frames);
// disconnect from world gravity so we can apply buoyancy // disconnect from world gravity so we can apply buoyancy
d.BodySetGravityMode (Body, false); SafeNativeMethods.BodySetGravityMode (Body, false);
m_interpenetrationcount = 0; m_interpenetrationcount = 0;
m_collisionscore = 0; m_collisionscore = 0;
@ -787,8 +787,8 @@ namespace OpenSim.Region.PhysicsModule.ODE
//m_log.Info("[PHYSICS]: New Mass: " + newmass.ToString()); //m_log.Info("[PHYSICS]: New Mass: " + newmass.ToString());
d.MassSetBoxTotal(out pMass, newmass, _size.X, _size.Y, _size.Z); SafeNativeMethods.MassSetBoxTotal(out pMass, newmass, _size.X, _size.Y, _size.Z);
d.BodySetMass(Body, ref pMass); SafeNativeMethods.BodySetMass(Body, ref pMass);
} }
} }
@ -796,7 +796,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
{ {
if (Body != (IntPtr)0) if (Body != (IntPtr)0)
{ {
d.BodySetAngularVel(Body, x, y, z); SafeNativeMethods.BodySetAngularVel(Body, x, y, z);
} }
} }
@ -818,16 +818,16 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (m_assetFailed) if (m_assetFailed)
{ {
d.GeomSetCategoryBits(prim_geom, 0); SafeNativeMethods.GeomSetCategoryBits(prim_geom, 0);
d.GeomSetCollideBits(prim_geom, 0); SafeNativeMethods.GeomSetCollideBits(prim_geom, 0);
} }
else else
{ {
d.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories); SafeNativeMethods.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories);
d.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags); SafeNativeMethods.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags);
} }
d.BodyDestroy(Body); SafeNativeMethods.BodyDestroy(Body);
lock (childrenPrim) lock (childrenPrim)
{ {
if (childrenPrim.Count > 0) if (childrenPrim.Count > 0)
@ -851,14 +851,14 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (m_assetFailed) if (m_assetFailed)
{ {
d.GeomSetCategoryBits(prim_geom, 0); SafeNativeMethods.GeomSetCategoryBits(prim_geom, 0);
d.GeomSetCollideBits(prim_geom, 0); SafeNativeMethods.GeomSetCollideBits(prim_geom, 0);
} }
else else
{ {
d.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories); SafeNativeMethods.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories);
d.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags); SafeNativeMethods.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags);
} }
Body = IntPtr.Zero; Body = IntPtr.Zero;
@ -915,10 +915,10 @@ namespace OpenSim.Region.PhysicsModule.ODE
} }
else else
{ {
_triMeshData = d.GeomTriMeshDataCreate(); _triMeshData = SafeNativeMethods.GeomTriMeshDataCreate();
d.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride); SafeNativeMethods.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride);
d.GeomTriMeshDataPreprocess(_triMeshData); SafeNativeMethods.GeomTriMeshDataPreprocess(_triMeshData);
m_MeshToTriMeshMap[mesh] = _triMeshData; m_MeshToTriMeshMap[mesh] = _triMeshData;
} }
} }
@ -926,7 +926,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
// _parent_scene.waitForSpaceUnlock(m_targetSpace); // _parent_scene.waitForSpaceUnlock(m_targetSpace);
try try
{ {
SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, null, null, null)); SetGeom(SafeNativeMethods.CreateTriMesh(m_targetSpace, _triMeshData, null, null, null));
} }
catch (AccessViolationException) catch (AccessViolationException)
{ {
@ -1032,7 +1032,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
{ {
if (Amotor != IntPtr.Zero) if (Amotor != IntPtr.Zero)
{ {
d.JointDestroy(Amotor); SafeNativeMethods.JointDestroy(Amotor);
Amotor = IntPtr.Zero; Amotor = IntPtr.Zero;
} }
} }
@ -1107,7 +1107,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
if (Body == IntPtr.Zero) if (Body == IntPtr.Zero)
{ {
Body = d.BodyCreate(_parent_scene.world); Body = SafeNativeMethods.BodyCreate(_parent_scene.world);
setMass(); setMass();
} }
@ -1123,21 +1123,21 @@ Console.WriteLine("ZProcessTaints for " + Name);
foreach (OdePrim prm in childrenPrim) foreach (OdePrim prm in childrenPrim)
{ {
d.Mass m2; SafeNativeMethods.Mass m2;
d.MassSetZero(out m2); SafeNativeMethods.MassSetZero(out m2);
d.MassSetBoxTotal(out m2, prm.CalculateMass(), prm._size.X, prm._size.Y, prm._size.Z); SafeNativeMethods.MassSetBoxTotal(out m2, prm.CalculateMass(), prm._size.X, prm._size.Y, prm._size.Z);
d.Quaternion quat = new d.Quaternion(); SafeNativeMethods.Quaternion quat = new SafeNativeMethods.Quaternion();
quat.W = prm._orientation.W; quat.W = prm._orientation.W;
quat.X = prm._orientation.X; quat.X = prm._orientation.X;
quat.Y = prm._orientation.Y; quat.Y = prm._orientation.Y;
quat.Z = prm._orientation.Z; quat.Z = prm._orientation.Z;
d.Matrix3 mat = new d.Matrix3(); SafeNativeMethods.Matrix3 mat = new SafeNativeMethods.Matrix3();
d.RfromQ(out mat, ref quat); SafeNativeMethods.RfromQ(out mat, ref quat);
d.MassRotate(ref m2, ref mat); SafeNativeMethods.MassRotate(ref m2, ref mat);
d.MassTranslate(ref m2, Position.X - prm.Position.X, Position.Y - prm.Position.Y, Position.Z - prm.Position.Z); SafeNativeMethods.MassTranslate(ref m2, Position.X - prm.Position.X, Position.Y - prm.Position.Y, Position.Z - prm.Position.Z);
d.MassAdd(ref pMass, ref m2); SafeNativeMethods.MassAdd(ref pMass, ref m2);
} }
foreach (OdePrim prm in childrenPrim) foreach (OdePrim prm in childrenPrim)
@ -1148,36 +1148,36 @@ Console.WriteLine("ZProcessTaints for " + Name);
//Console.WriteLine(" GeomSetCategoryBits 1: " + prm.prim_geom + " - " + (int)prm.m_collisionCategories + " for " + Name); //Console.WriteLine(" GeomSetCategoryBits 1: " + prm.prim_geom + " - " + (int)prm.m_collisionCategories + " for " + Name);
if (prm.m_assetFailed) if (prm.m_assetFailed)
{ {
d.GeomSetCategoryBits(prm.prim_geom, 0); SafeNativeMethods.GeomSetCategoryBits(prm.prim_geom, 0);
d.GeomSetCollideBits(prm.prim_geom, (uint)prm.BadMeshAssetCollideBits); SafeNativeMethods.GeomSetCollideBits(prm.prim_geom, (uint)prm.BadMeshAssetCollideBits);
} }
else else
{ {
d.GeomSetCategoryBits(prm.prim_geom, (uint)prm.m_collisionCategories); SafeNativeMethods.GeomSetCategoryBits(prm.prim_geom, (uint)prm.m_collisionCategories);
d.GeomSetCollideBits(prm.prim_geom, (uint)prm.m_collisionFlags); SafeNativeMethods.GeomSetCollideBits(prm.prim_geom, (uint)prm.m_collisionFlags);
} }
d.Quaternion quat = new d.Quaternion(); SafeNativeMethods.Quaternion quat = new SafeNativeMethods.Quaternion();
quat.W = prm._orientation.W; quat.W = prm._orientation.W;
quat.X = prm._orientation.X; quat.X = prm._orientation.X;
quat.Y = prm._orientation.Y; quat.Y = prm._orientation.Y;
quat.Z = prm._orientation.Z; quat.Z = prm._orientation.Z;
d.Matrix3 mat = new d.Matrix3(); SafeNativeMethods.Matrix3 mat = new SafeNativeMethods.Matrix3();
d.RfromQ(out mat, ref quat); SafeNativeMethods.RfromQ(out mat, ref quat);
if (Body != IntPtr.Zero) if (Body != IntPtr.Zero)
{ {
d.GeomSetBody(prm.prim_geom, Body); SafeNativeMethods.GeomSetBody(prm.prim_geom, Body);
prm.childPrim = true; prm.childPrim = true;
d.GeomSetOffsetWorldPosition(prm.prim_geom, prm.Position.X , prm.Position.Y, prm.Position.Z); SafeNativeMethods.GeomSetOffsetWorldPosition(prm.prim_geom, prm.Position.X , prm.Position.Y, prm.Position.Z);
//d.GeomSetOffsetPosition(prim.prim_geom, //d.GeomSetOffsetPosition(prim.prim_geom,
// (Position.X - prm.Position.X) - pMass.c.X, // (Position.X - prm.Position.X) - pMass.c.X,
// (Position.Y - prm.Position.Y) - pMass.c.Y, // (Position.Y - prm.Position.Y) - pMass.c.Y,
// (Position.Z - prm.Position.Z) - pMass.c.Z); // (Position.Z - prm.Position.Z) - pMass.c.Z);
d.GeomSetOffsetWorldRotation(prm.prim_geom, ref mat); SafeNativeMethods.GeomSetOffsetWorldRotation(prm.prim_geom, ref mat);
//d.GeomSetOffsetRotation(prm.prim_geom, ref mat); //d.GeomSetOffsetRotation(prm.prim_geom, ref mat);
d.MassTranslate(ref pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z); SafeNativeMethods.MassTranslate(ref pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
d.BodySetMass(Body, ref pMass); SafeNativeMethods.BodySetMass(Body, ref pMass);
} }
else else
{ {
@ -1197,37 +1197,37 @@ Console.WriteLine("ZProcessTaints for " + Name);
if (m_assetFailed) if (m_assetFailed)
{ {
d.GeomSetCategoryBits(prim_geom, 0); SafeNativeMethods.GeomSetCategoryBits(prim_geom, 0);
d.GeomSetCollideBits(prim_geom, (uint)BadMeshAssetCollideBits); SafeNativeMethods.GeomSetCollideBits(prim_geom, (uint)BadMeshAssetCollideBits);
} }
else else
{ {
//Console.WriteLine("GeomSetCategoryBits 2: " + prim_geom + " - " + (int)m_collisionCategories + " for " + Name); //Console.WriteLine("GeomSetCategoryBits 2: " + prim_geom + " - " + (int)m_collisionCategories + " for " + Name);
d.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories); SafeNativeMethods.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories);
//Console.WriteLine(" Post GeomSetCategoryBits 2"); //Console.WriteLine(" Post GeomSetCategoryBits 2");
d.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags); SafeNativeMethods.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags);
} }
d.Quaternion quat2 = new d.Quaternion(); SafeNativeMethods.Quaternion quat2 = new SafeNativeMethods.Quaternion();
quat2.W = _orientation.W; quat2.W = _orientation.W;
quat2.X = _orientation.X; quat2.X = _orientation.X;
quat2.Y = _orientation.Y; quat2.Y = _orientation.Y;
quat2.Z = _orientation.Z; quat2.Z = _orientation.Z;
d.Matrix3 mat2 = new d.Matrix3(); SafeNativeMethods.Matrix3 mat2 = new SafeNativeMethods.Matrix3();
d.RfromQ(out mat2, ref quat2); SafeNativeMethods.RfromQ(out mat2, ref quat2);
d.GeomSetBody(prim_geom, Body); SafeNativeMethods.GeomSetBody(prim_geom, Body);
d.GeomSetOffsetWorldPosition(prim_geom, Position.X - pMass.c.X, Position.Y - pMass.c.Y, Position.Z - pMass.c.Z); SafeNativeMethods.GeomSetOffsetWorldPosition(prim_geom, Position.X - pMass.c.X, Position.Y - pMass.c.Y, Position.Z - pMass.c.Z);
//d.GeomSetOffsetPosition(prim.prim_geom, //d.GeomSetOffsetPosition(prim.prim_geom,
// (Position.X - prm.Position.X) - pMass.c.X, // (Position.X - prm.Position.X) - pMass.c.X,
// (Position.Y - prm.Position.Y) - pMass.c.Y, // (Position.Y - prm.Position.Y) - pMass.c.Y,
// (Position.Z - prm.Position.Z) - pMass.c.Z); // (Position.Z - prm.Position.Z) - pMass.c.Z);
//d.GeomSetOffsetRotation(prim_geom, ref mat2); //d.GeomSetOffsetRotation(prim_geom, ref mat2);
d.MassTranslate(ref pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z); SafeNativeMethods.MassTranslate(ref pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
d.BodySetMass(Body, ref pMass); SafeNativeMethods.BodySetMass(Body, ref pMass);
d.BodySetAutoDisableFlag(Body, true); SafeNativeMethods.BodySetAutoDisableFlag(Body, true);
d.BodySetAutoDisableSteps(Body, body_autodisable_frames); SafeNativeMethods.BodySetAutoDisableSteps(Body, body_autodisable_frames);
m_interpenetrationcount = 0; m_interpenetrationcount = 0;
m_collisionscore = 0; m_collisionscore = 0;
@ -1240,7 +1240,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
createAMotor(m_angularlock); createAMotor(m_angularlock);
} }
d.BodySetPosition(Body, Position.X, Position.Y, Position.Z); SafeNativeMethods.BodySetPosition(Body, Position.X, Position.Y, Position.Z);
if (m_vehicle.Type != Vehicle.TYPE_NONE) if (m_vehicle.Type != Vehicle.TYPE_NONE)
m_vehicle.Enable(Body, _parent_scene); m_vehicle.Enable(Body, _parent_scene);
@ -1370,13 +1370,13 @@ Console.WriteLine("ZProcessTaints for " + Name);
if (m_assetFailed) if (m_assetFailed)
{ {
d.GeomSetCategoryBits(prim_geom, 0); SafeNativeMethods.GeomSetCategoryBits(prim_geom, 0);
d.GeomSetCollideBits(prim_geom, 0); SafeNativeMethods.GeomSetCollideBits(prim_geom, 0);
} }
else else
{ {
d.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories); SafeNativeMethods.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories);
d.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags); SafeNativeMethods.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags);
} }
if (IsPhysical) if (IsPhysical)
@ -1400,21 +1400,21 @@ Console.WriteLine("ZProcessTaints for " + Name);
if (m_assetFailed) if (m_assetFailed)
{ {
d.GeomSetCategoryBits(prim_geom, 0); SafeNativeMethods.GeomSetCategoryBits(prim_geom, 0);
d.GeomSetCollideBits(prim_geom, (uint)BadMeshAssetCollideBits); SafeNativeMethods.GeomSetCollideBits(prim_geom, (uint)BadMeshAssetCollideBits);
} }
else else
{ {
d.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories); SafeNativeMethods.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories);
d.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags); SafeNativeMethods.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags);
} }
if (IsPhysical) if (IsPhysical)
{ {
if (Body != IntPtr.Zero) if (Body != IntPtr.Zero)
{ {
d.BodySetLinearVel(Body, 0f, 0f, 0f); SafeNativeMethods.BodySetLinearVel(Body, 0f, 0f, 0f);
d.BodySetForce(Body, 0, 0, 0); SafeNativeMethods.BodySetForce(Body, 0, 0, 0);
enableBodySoft(); enableBodySoft();
} }
} }
@ -1463,7 +1463,7 @@ Console.WriteLine("CreateGeom:");
try try
{ {
//Console.WriteLine(" CreateGeom 1"); //Console.WriteLine(" CreateGeom 1");
SetGeom(d.CreateSphere(m_targetSpace, _size.X / 2)); SetGeom(SafeNativeMethods.CreateSphere(m_targetSpace, _size.X / 2));
m_expectedCollisionContacts = 3; m_expectedCollisionContacts = 3;
} }
catch (AccessViolationException) catch (AccessViolationException)
@ -1478,7 +1478,7 @@ Console.WriteLine("CreateGeom:");
try try
{ {
//Console.WriteLine(" CreateGeom 2"); //Console.WriteLine(" CreateGeom 2");
SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z)); SetGeom(SafeNativeMethods.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
m_expectedCollisionContacts = 4; m_expectedCollisionContacts = 4;
} }
catch (AccessViolationException) catch (AccessViolationException)
@ -1494,7 +1494,7 @@ Console.WriteLine("CreateGeom:");
try try
{ {
//Console.WriteLine(" CreateGeom 3"); //Console.WriteLine(" CreateGeom 3");
SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z)); SetGeom(SafeNativeMethods.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
m_expectedCollisionContacts = 4; m_expectedCollisionContacts = 4;
} }
catch (AccessViolationException) catch (AccessViolationException)
@ -1510,7 +1510,7 @@ Console.WriteLine("CreateGeom:");
try try
{ {
//Console.WriteLine(" CreateGeom 4"); //Console.WriteLine(" CreateGeom 4");
SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z)); SetGeom(SafeNativeMethods.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
m_expectedCollisionContacts = 4; m_expectedCollisionContacts = 4;
} }
catch (AccessViolationException) catch (AccessViolationException)
@ -1536,7 +1536,7 @@ Console.WriteLine("CreateGeom:");
{ {
_parent_scene.geom_name_map.Remove(prim_geom); _parent_scene.geom_name_map.Remove(prim_geom);
_parent_scene.actor_name_map.Remove(prim_geom); _parent_scene.actor_name_map.Remove(prim_geom);
d.GeomDestroy(prim_geom); SafeNativeMethods.GeomDestroy(prim_geom);
m_expectedCollisionContacts = 0; m_expectedCollisionContacts = 0;
prim_geom = IntPtr.Zero; prim_geom = IntPtr.Zero;
} }
@ -1593,13 +1593,13 @@ Console.WriteLine("changeadd 1");
#endif #endif
CreateGeom(m_targetSpace, mesh); CreateGeom(m_targetSpace, mesh);
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); SafeNativeMethods.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
d.Quaternion myrot = new d.Quaternion(); SafeNativeMethods.Quaternion myrot = new SafeNativeMethods.Quaternion();
myrot.X = _orientation.X; myrot.X = _orientation.X;
myrot.Y = _orientation.Y; myrot.Y = _orientation.Y;
myrot.Z = _orientation.Z; myrot.Z = _orientation.Z;
myrot.W = _orientation.W; myrot.W = _orientation.W;
d.GeomSetQuaternion(prim_geom, ref myrot); SafeNativeMethods.GeomSetQuaternion(prim_geom, ref myrot);
if (IsPhysical && Body == IntPtr.Zero) if (IsPhysical && Body == IntPtr.Zero)
enableBody(); enableBody();
@ -1627,14 +1627,14 @@ Console.WriteLine("changeadd 1");
{ {
if (m_linkJoint != IntPtr.Zero) if (m_linkJoint != IntPtr.Zero)
{ {
d.JointDestroy(m_linkJoint); SafeNativeMethods.JointDestroy(m_linkJoint);
m_linkJoint = IntPtr.Zero; m_linkJoint = IntPtr.Zero;
} }
} }
if (Body != IntPtr.Zero) if (Body != IntPtr.Zero)
{ {
d.BodySetPosition(Body, _position.X, _position.Y, _position.Z); SafeNativeMethods.BodySetPosition(Body, _position.X, _position.Y, _position.Z);
if (_parent != null) if (_parent != null)
{ {
@ -1643,12 +1643,12 @@ Console.WriteLine("changeadd 1");
{ {
// KF: Fixed Joints were removed? Anyway - this Console.WriteLine does not show up, so routine is not used?? // KF: Fixed Joints were removed? Anyway - this Console.WriteLine does not show up, so routine is not used??
Console.WriteLine(" JointCreateFixed"); Console.WriteLine(" JointCreateFixed");
m_linkJoint = d.JointCreateFixed(_parent_scene.world, _linkJointGroup); m_linkJoint = SafeNativeMethods.JointCreateFixed(_parent_scene.world, _linkJointGroup);
d.JointAttach(m_linkJoint, Body, odParent.Body); SafeNativeMethods.JointAttach(m_linkJoint, Body, odParent.Body);
d.JointSetFixed(m_linkJoint); SafeNativeMethods.JointSetFixed(m_linkJoint);
} }
} }
d.BodyEnable(Body); SafeNativeMethods.BodyEnable(Body);
if (m_vehicle.Type != Vehicle.TYPE_NONE) if (m_vehicle.Type != Vehicle.TYPE_NONE)
{ {
m_vehicle.Enable(Body, _parent_scene); m_vehicle.Enable(Body, _parent_scene);
@ -1674,10 +1674,10 @@ Console.WriteLine(" JointCreateFixed");
// _parent_scene.waitForSpaceUnlock(m_targetSpace); // _parent_scene.waitForSpaceUnlock(m_targetSpace);
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); SafeNativeMethods.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
// _parent_scene.waitForSpaceUnlock(m_targetSpace); // _parent_scene.waitForSpaceUnlock(m_targetSpace);
d.SpaceAdd(m_targetSpace, prim_geom); SafeNativeMethods.SpaceAdd(m_targetSpace, prim_geom);
changeSelectedStatus(); changeSelectedStatus();
@ -1704,7 +1704,7 @@ Console.WriteLine(" JointCreateFixed");
else else
{ {
//Console.WriteLine("Move " + Name); //Console.WriteLine("Move " + Name);
if (!d.BodyIsEnabled (Body)) d.BodyEnable (Body); // KF add 161009 if (!SafeNativeMethods.BodyIsEnabled (Body)) SafeNativeMethods.BodyEnable (Body); // KF add 161009
float m_mass = CalculateMass(); float m_mass = CalculateMass();
@ -1746,9 +1746,9 @@ Console.WriteLine(" JointCreateFixed");
//PidStatus = true; //PidStatus = true;
// PhysicsVector vec = new PhysicsVector(); // PhysicsVector vec = new PhysicsVector();
d.Vector3 vel = d.BodyGetLinearVel(Body); SafeNativeMethods.Vector3 vel = SafeNativeMethods.BodyGetLinearVel(Body);
d.Vector3 pos = d.BodyGetPosition(Body); SafeNativeMethods.Vector3 pos = SafeNativeMethods.BodyGetPosition(Body);
_target_velocity = _target_velocity =
new Vector3( new Vector3(
(m_PIDTarget.X - pos.X) * ((PID_G - m_PIDTau) * timestep), (m_PIDTarget.X - pos.X) * ((PID_G - m_PIDTau) * timestep),
@ -1770,9 +1770,9 @@ Console.WriteLine(" JointCreateFixed");
//fx = (_target_velocity.X - vel.X) * (PID_D) + (_zeroPosition.X - pos.X) * (PID_P * 2); //fx = (_target_velocity.X - vel.X) * (PID_D) + (_zeroPosition.X - pos.X) * (PID_P * 2);
//fy = (_target_velocity.Y - vel.Y) * (PID_D) + (_zeroPosition.Y - pos.Y) * (PID_P * 2); //fy = (_target_velocity.Y - vel.Y) * (PID_D) + (_zeroPosition.Y - pos.Y) * (PID_P * 2);
//fz = fz + (_target_velocity.Z - vel.Z) * (PID_D) + (_zeroPosition.Z - pos.Z) * PID_P; //fz = fz + (_target_velocity.Z - vel.Z) * (PID_D) + (_zeroPosition.Z - pos.Z) * PID_P;
d.BodySetPosition(Body, m_PIDTarget.X, m_PIDTarget.Y, m_PIDTarget.Z); SafeNativeMethods.BodySetPosition(Body, m_PIDTarget.X, m_PIDTarget.Y, m_PIDTarget.Z);
d.BodySetLinearVel(Body, 0, 0, 0); SafeNativeMethods.BodySetLinearVel(Body, 0, 0, 0);
d.BodyAddForce(Body, 0, 0, fz); SafeNativeMethods.BodyAddForce(Body, 0, 0, fz);
return; return;
} }
else else
@ -1813,8 +1813,8 @@ Console.WriteLine(" JointCreateFixed");
} }
// Where are we, and where are we headed? // Where are we, and where are we headed?
d.Vector3 pos = d.BodyGetPosition(Body); SafeNativeMethods.Vector3 pos = SafeNativeMethods.BodyGetPosition(Body);
d.Vector3 vel = d.BodyGetLinearVel(Body); SafeNativeMethods.Vector3 vel = SafeNativeMethods.BodyGetLinearVel(Body);
// Non-Vehicles have a limited set of Hover options. // Non-Vehicles have a limited set of Hover options.
// determine what our target height really is based on HoverType // determine what our target height really is based on HoverType
@ -1856,9 +1856,9 @@ Console.WriteLine(" JointCreateFixed");
// Avatar to Avatar collisions // Avatar to Avatar collisions
// Prim to avatar collisions // Prim to avatar collisions
d.BodySetPosition(Body, pos.X, pos.Y, m_targetHoverHeight); SafeNativeMethods.BodySetPosition(Body, pos.X, pos.Y, m_targetHoverHeight);
d.BodySetLinearVel(Body, vel.X, vel.Y, 0); SafeNativeMethods.BodySetLinearVel(Body, vel.X, vel.Y, 0);
d.BodyAddForce(Body, 0, 0, fz); SafeNativeMethods.BodyAddForce(Body, 0, 0, fz);
return; return;
} }
else else
@ -1884,13 +1884,13 @@ Console.WriteLine(" JointCreateFixed");
//m_taintdisable = true; //m_taintdisable = true;
//base.RaiseOutOfBounds(Position); //base.RaiseOutOfBounds(Position);
//d.BodySetLinearVel(Body, fx, fy, 0f); //d.BodySetLinearVel(Body, fx, fy, 0f);
if (!d.BodyIsEnabled(Body)) if (!SafeNativeMethods.BodyIsEnabled(Body))
{ {
// A physical body at rest on a surface will auto-disable after a while, // A physical body at rest on a surface will auto-disable after a while,
// this appears to re-enable it incase the surface it is upon vanishes, // this appears to re-enable it incase the surface it is upon vanishes,
// and the body should fall again. // and the body should fall again.
d.BodySetLinearVel(Body, 0f, 0f, 0f); SafeNativeMethods.BodySetLinearVel(Body, 0f, 0f, 0f);
d.BodySetForce(Body, 0, 0, 0); SafeNativeMethods.BodySetForce(Body, 0, 0, 0);
enableBodySoft(); enableBodySoft();
} }
@ -1906,7 +1906,7 @@ Console.WriteLine(" JointCreateFixed");
fy = nmax; fy = nmax;
if (fy < nmin) if (fy < nmin)
fy = nmin; fy = nmin;
d.BodyAddForce(Body, fx, fy, fz); SafeNativeMethods.BodyAddForce(Body, fx, fy, fz);
//Console.WriteLine("AddForce " + fx + "," + fy + "," + fz); //Console.WriteLine("AddForce " + fx + "," + fy + "," + fz);
} }
} }
@ -1922,7 +1922,7 @@ Console.WriteLine(" JointCreateFixed");
private void rotate() private void rotate()
{ {
d.Quaternion myrot = new d.Quaternion(); SafeNativeMethods.Quaternion myrot = new SafeNativeMethods.Quaternion();
myrot.X = _orientation.X; myrot.X = _orientation.X;
myrot.Y = _orientation.Y; myrot.Y = _orientation.Y;
myrot.Z = _orientation.Z; myrot.Z = _orientation.Z;
@ -1930,7 +1930,7 @@ Console.WriteLine(" JointCreateFixed");
if (Body != IntPtr.Zero) if (Body != IntPtr.Zero)
{ {
// KF: If this is a root prim do BodySet // KF: If this is a root prim do BodySet
d.BodySetQuaternion(Body, ref myrot); SafeNativeMethods.BodySetQuaternion(Body, ref myrot);
if (IsPhysical) if (IsPhysical)
{ {
// create or remove locks // create or remove locks
@ -1940,7 +1940,7 @@ Console.WriteLine(" JointCreateFixed");
else else
{ {
// daughter prim, do Geom set // daughter prim, do Geom set
d.GeomSetQuaternion(prim_geom, ref myrot); SafeNativeMethods.GeomSetQuaternion(prim_geom, ref myrot);
} }
resetCollisionAccounting(); resetCollisionAccounting();
@ -1962,7 +1962,7 @@ Console.WriteLine(" JointCreateFixed");
m_disabled = true; m_disabled = true;
if (Body != IntPtr.Zero) if (Body != IntPtr.Zero)
{ {
d.BodyDisable(Body); SafeNativeMethods.BodyDisable(Body);
Body = IntPtr.Zero; Body = IntPtr.Zero;
} }
@ -2051,10 +2051,10 @@ Console.WriteLine(" JointCreateFixed");
} }
} }
if (d.SpaceQuery(m_targetSpace, prim_geom)) if (SafeNativeMethods.SpaceQuery(m_targetSpace, prim_geom))
{ {
// _parent_scene.waitForSpaceUnlock(m_targetSpace); // _parent_scene.waitForSpaceUnlock(m_targetSpace);
d.SpaceRemove(m_targetSpace, prim_geom); SafeNativeMethods.SpaceRemove(m_targetSpace, prim_geom);
} }
RemoveGeom(); RemoveGeom();
@ -2084,13 +2084,13 @@ Console.WriteLine(" JointCreateFixed");
} }
CreateGeom(m_targetSpace, mesh); CreateGeom(m_targetSpace, mesh);
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); SafeNativeMethods.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
d.Quaternion myrot = new d.Quaternion(); SafeNativeMethods.Quaternion myrot = new SafeNativeMethods.Quaternion();
myrot.X = _orientation.X; myrot.X = _orientation.X;
myrot.Y = _orientation.Y; myrot.Y = _orientation.Y;
myrot.Z = _orientation.Z; myrot.Z = _orientation.Z;
myrot.W = _orientation.W; myrot.W = _orientation.W;
d.GeomSetQuaternion(prim_geom, ref myrot); SafeNativeMethods.GeomSetQuaternion(prim_geom, ref myrot);
//d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z); //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
if (IsPhysical && Body == IntPtr.Zero && !childPrim) if (IsPhysical && Body == IntPtr.Zero && !childPrim)
@ -2098,7 +2098,7 @@ Console.WriteLine(" JointCreateFixed");
// Re creates body on size. // Re creates body on size.
// EnableBody also does setMass() // EnableBody also does setMass()
enableBody(); enableBody();
d.BodyEnable(Body); SafeNativeMethods.BodyEnable(Body);
} }
changeSelectedStatus(); changeSelectedStatus();
@ -2133,10 +2133,10 @@ Console.WriteLine(" JointCreateFixed");
} }
if (m_assetFailed) if (m_assetFailed)
d.GeomSetCollideBits(prim_geom, (uint)BadMeshAssetCollideBits); SafeNativeMethods.GeomSetCollideBits(prim_geom, (uint)BadMeshAssetCollideBits);
else else
d.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags); SafeNativeMethods.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags);
} }
/// <summary> /// <summary>
/// Change prim in response to a shape taint. /// Change prim in response to a shape taint.
@ -2190,14 +2190,14 @@ Console.WriteLine(" JointCreateFixed");
} }
CreateGeom(m_targetSpace, mesh); CreateGeom(m_targetSpace, mesh);
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); SafeNativeMethods.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
d.Quaternion myrot = new d.Quaternion(); SafeNativeMethods.Quaternion myrot = new SafeNativeMethods.Quaternion();
//myrot.W = _orientation.w; //myrot.W = _orientation.w;
myrot.W = _orientation.W; myrot.W = _orientation.W;
myrot.X = _orientation.X; myrot.X = _orientation.X;
myrot.Y = _orientation.Y; myrot.Y = _orientation.Y;
myrot.Z = _orientation.Z; myrot.Z = _orientation.Z;
d.GeomSetQuaternion(prim_geom, ref myrot); SafeNativeMethods.GeomSetQuaternion(prim_geom, ref myrot);
//d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z); //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
if (IsPhysical && Body == IntPtr.Zero) if (IsPhysical && Body == IntPtr.Zero)
@ -2207,7 +2207,7 @@ Console.WriteLine(" JointCreateFixed");
enableBody(); enableBody();
if (Body != IntPtr.Zero) if (Body != IntPtr.Zero)
{ {
d.BodyEnable(Body); SafeNativeMethods.BodyEnable(Body);
} }
} }
@ -2264,8 +2264,8 @@ Console.WriteLine(" JointCreateFixed");
m_taintforce = false; m_taintforce = false;
return; return;
} }
d.BodyEnable(Body); SafeNativeMethods.BodyEnable(Body);
d.BodyAddForce(Body, iforce.X, iforce.Y, iforce.Z); SafeNativeMethods.BodyAddForce(Body, iforce.X, iforce.Y, iforce.Z);
} }
m_forcelist.Clear(); m_forcelist.Clear();
} }
@ -2286,7 +2286,7 @@ Console.WriteLine(" JointCreateFixed");
{ {
if (IsPhysical && Body != IntPtr.Zero) if (IsPhysical && Body != IntPtr.Zero)
{ {
d.BodySetTorque(Body, m_taintTorque.X, m_taintTorque.Y, m_taintTorque.Z); SafeNativeMethods.BodySetTorque(Body, m_taintTorque.X, m_taintTorque.Y, m_taintTorque.Z);
} }
} }
@ -2310,8 +2310,8 @@ Console.WriteLine(" JointCreateFixed");
{ {
iforce = iforce + (m_angularforcelist[i] * 100); iforce = iforce + (m_angularforcelist[i] * 100);
} }
d.BodyEnable(Body); SafeNativeMethods.BodyEnable(Body);
d.BodyAddTorque(Body, iforce.X, iforce.Y, iforce.Z); SafeNativeMethods.BodyAddTorque(Body, iforce.X, iforce.Y, iforce.Z);
} }
m_angularforcelist.Clear(); m_angularforcelist.Clear();
@ -2339,7 +2339,7 @@ Console.WriteLine(" JointCreateFixed");
{ {
if (Body != IntPtr.Zero) if (Body != IntPtr.Zero)
{ {
d.BodySetLinearVel(Body, m_taintVelocity.X, m_taintVelocity.Y, m_taintVelocity.Z); SafeNativeMethods.BodySetLinearVel(Body, m_taintVelocity.X, m_taintVelocity.Y, m_taintVelocity.Z);
} }
} }
@ -2665,7 +2665,7 @@ Console.WriteLine(" JointCreateFixed");
} }
*/ */
d.AllocateODEDataForThread(0U); SafeNativeMethods.AllocateODEDataForThread(0U);
_position.X = Util.Clip(_position.X, 0.5f, _parent_scene.WorldExtents.X - 0.5f); _position.X = Util.Clip(_position.X, 0.5f, _parent_scene.WorldExtents.X - 0.5f);
_position.Y = Util.Clip(_position.Y, 0.5f, _parent_scene.WorldExtents.Y - 0.5f); _position.Y = Util.Clip(_position.Y, 0.5f, _parent_scene.WorldExtents.Y - 0.5f);
@ -2680,8 +2680,8 @@ Console.WriteLine(" JointCreateFixed");
if (Body != IntPtr.Zero) if (Body != IntPtr.Zero)
{ {
d.BodySetLinearVel(Body, 0, 0, 0); // stop it SafeNativeMethods.BodySetLinearVel(Body, 0, 0, 0); // stop it
d.BodySetPosition(Body, _position.X, _position.Y, _position.Z); SafeNativeMethods.BodySetPosition(Body, _position.X, _position.Y, _position.Z);
} }
if(m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE) if(m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
@ -2728,11 +2728,11 @@ Console.WriteLine(" JointCreateFixed");
float m_minvelocity = 0; float m_minvelocity = 0;
if (Body != IntPtr.Zero) // FIXME -> or if it is a joint if (Body != IntPtr.Zero) // FIXME -> or if it is a joint
{ {
d.Vector3 vec = d.BodyGetPosition(Body); SafeNativeMethods.Vector3 vec = SafeNativeMethods.BodyGetPosition(Body);
d.Quaternion ori = d.BodyGetQuaternion(Body); SafeNativeMethods.Quaternion ori = SafeNativeMethods.BodyGetQuaternion(Body);
d.Vector3 vel = d.BodyGetLinearVel(Body); SafeNativeMethods.Vector3 vel = SafeNativeMethods.BodyGetLinearVel(Body);
d.Vector3 rotvel = d.BodyGetAngularVel(Body); SafeNativeMethods.Vector3 rotvel = SafeNativeMethods.BodyGetAngularVel(Body);
d.Vector3 torque = d.BodyGetTorque(Body); SafeNativeMethods.Vector3 torque = SafeNativeMethods.BodyGetTorque(Body);
_torque = new Vector3(torque.X, torque.Y, torque.Z); _torque = new Vector3(torque.X, torque.Y, torque.Z);
Vector3 l_position = Vector3.Zero; Vector3 l_position = Vector3.Zero;
Quaternion l_orientation = Quaternion.Identity; Quaternion l_orientation = Quaternion.Identity;
@ -2812,11 +2812,11 @@ Console.WriteLine(" JointCreateFixed");
else else
Util.Clamp(l_position.Y, _parent_scene.WorldExtents.Y + 0.1f, _parent_scene.WorldExtents.Y + 2f); Util.Clamp(l_position.Y, _parent_scene.WorldExtents.Y + 0.1f, _parent_scene.WorldExtents.Y + 2f);
d.BodySetPosition(Body, l_position.X, l_position.Y, l_position.Z); SafeNativeMethods.BodySetPosition(Body, l_position.X, l_position.Y, l_position.Z);
// stop it // stop it
d.BodySetAngularVel(Body, 0, 0, 0); SafeNativeMethods.BodySetAngularVel(Body, 0, 0, 0);
d.BodySetLinearVel(Body, 0, 0, 0); SafeNativeMethods.BodySetLinearVel(Body, 0, 0, 0);
disableBodySoft(); disableBodySoft();
_position = l_position; _position = l_position;
@ -3009,7 +3009,7 @@ Console.WriteLine(" JointCreateFixed");
if (Amotor != IntPtr.Zero) if (Amotor != IntPtr.Zero)
{ {
d.JointDestroy(Amotor); SafeNativeMethods.JointDestroy(Amotor);
Amotor = IntPtr.Zero; Amotor = IntPtr.Zero;
} }
@ -3039,19 +3039,19 @@ Console.WriteLine(" JointCreateFixed");
if(axisnum == 0) if(axisnum == 0)
return; return;
// stop it // stop it
d.BodySetTorque(Body, 0, 0, 0); SafeNativeMethods.BodySetTorque(Body, 0, 0, 0);
d.BodySetAngularVel(Body, 0, 0, 0); SafeNativeMethods.BodySetAngularVel(Body, 0, 0, 0);
Amotor = d.JointCreateAMotor(_parent_scene.world, IntPtr.Zero); Amotor = SafeNativeMethods.JointCreateAMotor(_parent_scene.world, IntPtr.Zero);
d.JointAttach(Amotor, Body, IntPtr.Zero); SafeNativeMethods.JointAttach(Amotor, Body, IntPtr.Zero);
d.JointSetAMotorMode(Amotor, 0); SafeNativeMethods.JointSetAMotorMode(Amotor, 0);
d.JointSetAMotorNumAxes(Amotor, axisnum); SafeNativeMethods.JointSetAMotorNumAxes(Amotor, axisnum);
// get current orientation to lock // get current orientation to lock
d.Quaternion dcur = d.BodyGetQuaternion(Body); SafeNativeMethods.Quaternion dcur = SafeNativeMethods.BodyGetQuaternion(Body);
Quaternion curr; // crap convertion between identical things Quaternion curr; // crap convertion between identical things
curr.X = dcur.X; curr.X = dcur.X;
curr.Y = dcur.Y; curr.Y = dcur.Y;
@ -3064,17 +3064,17 @@ Console.WriteLine(" JointCreateFixed");
if (axisX) if (axisX)
{ {
ax = (new Vector3(1, 0, 0)) * curr; // rotate world X to current local X ax = (new Vector3(1, 0, 0)) * curr; // rotate world X to current local X
d.JointSetAMotorAxis(Amotor, 0, 0, ax.X, ax.Y, ax.Z); SafeNativeMethods.JointSetAMotorAxis(Amotor, 0, 0, ax.X, ax.Y, ax.Z);
d.JointSetAMotorAngle(Amotor, 0, 0); SafeNativeMethods.JointSetAMotorAngle(Amotor, 0, 0);
d.JointSetAMotorParam(Amotor, (int)d.JointParam.LoStop, 0f); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)SafeNativeMethods.JointParam.LoStop, 0f);
d.JointSetAMotorParam(Amotor, (int)d.JointParam.HiStop, 0f); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)SafeNativeMethods.JointParam.HiStop, 0f);
d.JointSetAMotorParam(Amotor, (int)d.JointParam.Vel, 0); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)SafeNativeMethods.JointParam.Vel, 0);
d.JointSetAMotorParam(Amotor, (int)d.JointParam.FudgeFactor, 0.0001f); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)SafeNativeMethods.JointParam.FudgeFactor, 0.0001f);
d.JointSetAMotorParam(Amotor, (int)d.JointParam.Bounce, 0f); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)SafeNativeMethods.JointParam.Bounce, 0f);
d.JointSetAMotorParam(Amotor, (int)d.JointParam.CFM, 0f); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)SafeNativeMethods.JointParam.CFM, 0f);
d.JointSetAMotorParam(Amotor, (int)d.JointParam.FMax, 5e8f); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)SafeNativeMethods.JointParam.FMax, 5e8f);
d.JointSetAMotorParam(Amotor, (int)d.JointParam.StopCFM, 0f); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)SafeNativeMethods.JointParam.StopCFM, 0f);
d.JointSetAMotorParam(Amotor, (int)d.JointParam.StopERP, 0.8f); SafeNativeMethods.JointSetAMotorParam(Amotor, (int)SafeNativeMethods.JointParam.StopERP, 0.8f);
i++; i++;
j = 256; // move to next axis set j = 256; // move to next axis set
} }
@ -3082,17 +3082,17 @@ Console.WriteLine(" JointCreateFixed");
if (axisY) if (axisY)
{ {
ax = (new Vector3(0, 1, 0)) * curr; ax = (new Vector3(0, 1, 0)) * curr;
d.JointSetAMotorAxis(Amotor, i, 0, ax.X, ax.Y, ax.Z); SafeNativeMethods.JointSetAMotorAxis(Amotor, i, 0, ax.X, ax.Y, ax.Z);
d.JointSetAMotorAngle(Amotor, i, 0); SafeNativeMethods.JointSetAMotorAngle(Amotor, i, 0);
d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.LoStop, 0f); SafeNativeMethods.JointSetAMotorParam(Amotor, j + (int)SafeNativeMethods.JointParam.LoStop, 0f);
d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.HiStop, 0f); SafeNativeMethods.JointSetAMotorParam(Amotor, j + (int)SafeNativeMethods.JointParam.HiStop, 0f);
d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.Vel, 0); SafeNativeMethods.JointSetAMotorParam(Amotor, j + (int)SafeNativeMethods.JointParam.Vel, 0);
d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FudgeFactor, 0.0001f); SafeNativeMethods.JointSetAMotorParam(Amotor, j + (int)SafeNativeMethods.JointParam.FudgeFactor, 0.0001f);
d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.Bounce, 0f); SafeNativeMethods.JointSetAMotorParam(Amotor, j + (int)SafeNativeMethods.JointParam.Bounce, 0f);
d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.CFM, 0f); SafeNativeMethods.JointSetAMotorParam(Amotor, j + (int)SafeNativeMethods.JointParam.CFM, 0f);
d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FMax, 5e8f); SafeNativeMethods.JointSetAMotorParam(Amotor, j + (int)SafeNativeMethods.JointParam.FMax, 5e8f);
d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.StopCFM, 0f); SafeNativeMethods.JointSetAMotorParam(Amotor, j + (int)SafeNativeMethods.JointParam.StopCFM, 0f);
d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.StopERP, 0.8f); SafeNativeMethods.JointSetAMotorParam(Amotor, j + (int)SafeNativeMethods.JointParam.StopERP, 0.8f);
i++; i++;
j += 256; j += 256;
} }
@ -3100,17 +3100,17 @@ Console.WriteLine(" JointCreateFixed");
if (axisZ) if (axisZ)
{ {
ax = (new Vector3(0, 0, 1)) * curr; ax = (new Vector3(0, 0, 1)) * curr;
d.JointSetAMotorAxis(Amotor, i, 0, ax.X, ax.Y, ax.Z); SafeNativeMethods.JointSetAMotorAxis(Amotor, i, 0, ax.X, ax.Y, ax.Z);
d.JointSetAMotorAngle(Amotor, i, 0); SafeNativeMethods.JointSetAMotorAngle(Amotor, i, 0);
d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.LoStop, 0f); SafeNativeMethods.JointSetAMotorParam(Amotor, j + (int)SafeNativeMethods.JointParam.LoStop, 0f);
d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.HiStop, 0f); SafeNativeMethods.JointSetAMotorParam(Amotor, j + (int)SafeNativeMethods.JointParam.HiStop, 0f);
d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.Vel, 0); SafeNativeMethods.JointSetAMotorParam(Amotor, j + (int)SafeNativeMethods.JointParam.Vel, 0);
d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FudgeFactor, 0.0001f); SafeNativeMethods.JointSetAMotorParam(Amotor, j + (int)SafeNativeMethods.JointParam.FudgeFactor, 0.0001f);
d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.Bounce, 0f); SafeNativeMethods.JointSetAMotorParam(Amotor, j + (int)SafeNativeMethods.JointParam.Bounce, 0f);
d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.CFM, 0f); SafeNativeMethods.JointSetAMotorParam(Amotor, j + (int)SafeNativeMethods.JointParam.CFM, 0f);
d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FMax, 5e8f); SafeNativeMethods.JointSetAMotorParam(Amotor, j + (int)SafeNativeMethods.JointParam.FMax, 5e8f);
d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.StopCFM, 0f); SafeNativeMethods.JointSetAMotorParam(Amotor, j + (int)SafeNativeMethods.JointParam.StopCFM, 0f);
d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.StopERP, 0.8f); SafeNativeMethods.JointSetAMotorParam(Amotor, j + (int)SafeNativeMethods.JointParam.StopERP, 0.8f);
} }
} }

View File

@ -61,12 +61,12 @@ namespace OpenSim.Region.PhysicsModule.ODE
/// <summary> /// <summary>
/// ODE contact array to be filled by the collision testing /// ODE contact array to be filled by the collision testing
/// </summary> /// </summary>
d.ContactGeom[] contacts = new d.ContactGeom[5]; SafeNativeMethods.ContactGeom[] contacts = new SafeNativeMethods.ContactGeom[5];
/// <summary> /// <summary>
/// ODE near callback delegate /// ODE near callback delegate
/// </summary> /// </summary>
private d.NearCallback nearCallback; private SafeNativeMethods.NearCallback nearCallback;
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private List<ContactResult> m_contactResults = new List<ContactResult>(); private List<ContactResult> m_contactResults = new List<ContactResult>();
@ -179,14 +179,14 @@ namespace OpenSim.Region.PhysicsModule.ODE
len = 100f; len = 100f;
// Create the ray // Create the ray
IntPtr ray = d.CreateRay(m_scene.space, len); IntPtr ray = SafeNativeMethods.CreateRay(m_scene.space, len);
d.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z); SafeNativeMethods.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z);
// Collide test // Collide test
d.SpaceCollide2(m_scene.space, ray, IntPtr.Zero, nearCallback); SafeNativeMethods.SpaceCollide2(m_scene.space, ray, IntPtr.Zero, nearCallback);
// Remove Ray // Remove Ray
d.GeomDestroy(ray); SafeNativeMethods.GeomDestroy(ray);
// Define default results // Define default results
bool hitYN = false; bool hitYN = false;
@ -230,14 +230,14 @@ namespace OpenSim.Region.PhysicsModule.ODE
len = 100f; len = 100f;
// Create the ray // Create the ray
IntPtr ray = d.CreateRay(m_scene.space, len); IntPtr ray = SafeNativeMethods.CreateRay(m_scene.space, len);
d.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z); SafeNativeMethods.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z);
// Collide test // Collide test
d.SpaceCollide2(m_scene.space, ray, IntPtr.Zero, nearCallback); SafeNativeMethods.SpaceCollide2(m_scene.space, ray, IntPtr.Zero, nearCallback);
// Remove Ray // Remove Ray
d.GeomDestroy(ray); SafeNativeMethods.GeomDestroy(ray);
// Find closest contact and object. // Find closest contact and object.
lock (m_contactResults) lock (m_contactResults)
@ -258,7 +258,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
// return; // return;
// Raytest against AABBs of spaces first, then dig into the spaces it hits for actual geoms. // Raytest against AABBs of spaces first, then dig into the spaces it hits for actual geoms.
if (d.GeomIsSpace(g1) || d.GeomIsSpace(g2)) if (SafeNativeMethods.GeomIsSpace(g1) || SafeNativeMethods.GeomIsSpace(g2))
{ {
if (g1 == IntPtr.Zero || g2 == IntPtr.Zero) if (g1 == IntPtr.Zero || g2 == IntPtr.Zero)
return; return;
@ -269,7 +269,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
// contact points in the space // contact points in the space
try try
{ {
d.SpaceCollide2(g1, g2, IntPtr.Zero, nearCallback); SafeNativeMethods.SpaceCollide2(g1, g2, IntPtr.Zero, nearCallback);
} }
catch (AccessViolationException) catch (AccessViolationException)
{ {
@ -296,7 +296,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
lock (contacts) lock (contacts)
{ {
count = d.Collide(g1, g2, contacts.GetLength(0), contacts, d.ContactGeom.unmanagedSizeOf); count = SafeNativeMethods.Collide(g1, g2, contacts.GetLength(0), contacts, SafeNativeMethods.ContactGeom.unmanagedSizeOf);
} }
} }
catch (SEHException) catch (SEHException)

View File

@ -336,9 +336,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
private bool m_filterCollisions = true; private bool m_filterCollisions = true;
private d.NearCallback nearCallback; private SafeNativeMethods.NearCallback nearCallback;
public d.TriCallback triCallback;
public d.TriArrayCallback triArrayCallback;
/// <summary> /// <summary>
/// Avatars in the physics scene. /// Avatars in the physics scene.
@ -368,7 +366,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
/// <summary> /// <summary>
/// Keep record of contacts in the physics loop so that we can remove duplicates. /// Keep record of contacts in the physics loop so that we can remove duplicates.
/// </summary> /// </summary>
private readonly List<d.ContactGeom> _perloopContact = new List<d.ContactGeom>(); private readonly List<SafeNativeMethods.ContactGeom> _perloopContact = new List<SafeNativeMethods.ContactGeom>();
/// <summary> /// <summary>
/// A dictionary of actors that should receive collision events. /// A dictionary of actors that should receive collision events.
@ -409,7 +407,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
private bool m_NINJA_physics_joints_enabled = false; private bool m_NINJA_physics_joints_enabled = false;
//private Dictionary<String, IntPtr> jointpart_name_map = new Dictionary<String,IntPtr>(); //private Dictionary<String, IntPtr> jointpart_name_map = new Dictionary<String,IntPtr>();
private readonly Dictionary<String, List<PhysicsJoint>> joints_connecting_actor = new Dictionary<String, List<PhysicsJoint>>(); private readonly Dictionary<String, List<PhysicsJoint>> joints_connecting_actor = new Dictionary<String, List<PhysicsJoint>>();
private d.ContactGeom[] contacts; private SafeNativeMethods.ContactGeom[] contacts;
/// <summary> /// <summary>
/// Lock only briefly. accessed by external code (to request new joints) and by OdeScene.Simulate() to move those joints into pending/active /// Lock only briefly. accessed by external code (to request new joints) and by OdeScene.Simulate() to move those joints into pending/active
@ -437,12 +435,12 @@ namespace OpenSim.Region.PhysicsModule.ODE
private readonly DoubleDictionary<Vector3, IntPtr, IntPtr> RegionTerrain = new DoubleDictionary<Vector3, IntPtr, IntPtr>(); private readonly DoubleDictionary<Vector3, IntPtr, IntPtr> RegionTerrain = new DoubleDictionary<Vector3, IntPtr, IntPtr>();
private readonly Dictionary<IntPtr,float[]> TerrainHeightFieldHeights = new Dictionary<IntPtr, float[]>(); private readonly Dictionary<IntPtr,float[]> TerrainHeightFieldHeights = new Dictionary<IntPtr, float[]>();
private d.Contact contact; private SafeNativeMethods.Contact contact;
private d.Contact TerrainContact; private SafeNativeMethods.Contact TerrainContact;
private d.Contact AvatarMovementprimContact; private SafeNativeMethods.Contact AvatarMovementprimContact;
private d.Contact AvatarMovementTerrainContact; private SafeNativeMethods.Contact AvatarMovementTerrainContact;
private d.Contact WaterContact; private SafeNativeMethods.Contact WaterContact;
private d.Contact[,] m_materialContacts; private SafeNativeMethods.Contact[,] m_materialContacts;
private int m_physicsiterations = 10; private int m_physicsiterations = 10;
private const float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag private const float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag
@ -480,8 +478,8 @@ namespace OpenSim.Region.PhysicsModule.ODE
private bool avplanted = false; private bool avplanted = false;
private bool av_av_collisions_off = false; private bool av_av_collisions_off = false;
public d.Vector3 xyz = new d.Vector3(128.1640f, 128.3079f, 25.7600f); internal SafeNativeMethods.Vector3 xyz = new SafeNativeMethods.Vector3(128.1640f, 128.3079f, 25.7600f);
public d.Vector3 hpr = new d.Vector3(125.5000f, -17.0000f, 0.0000f); internal SafeNativeMethods.Vector3 hpr = new SafeNativeMethods.Vector3(125.5000f, -17.0000f, 0.0000f);
private volatile int m_global_contactcount = 0; private volatile int m_global_contactcount = 0;
@ -544,12 +542,11 @@ namespace OpenSim.Region.PhysicsModule.ODE
m_rayCastManager = new ODERayCastRequestManager(this); m_rayCastManager = new ODERayCastRequestManager(this);
// Create the world and the first space // Create the world and the first space
world = d.WorldCreate(); world = SafeNativeMethods.WorldCreate();
space = d.HashSpaceCreate(IntPtr.Zero); space = SafeNativeMethods.HashSpaceCreate(IntPtr.Zero);
contactgroup = SafeNativeMethods.JointGroupCreate(0);
contactgroup = d.JointGroupCreate(0); SafeNativeMethods.WorldSetAutoDisableFlag(world, false);
d.WorldSetAutoDisableFlag(world, false);
} }
// Initialize from configs // Initialize from configs
@ -651,7 +648,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
} }
} }
contacts = new d.ContactGeom[contactsPerCollision]; contacts = new SafeNativeMethods.ContactGeom[contactsPerCollision];
spacesPerMeterX = 1.0f / metersInSpace; spacesPerMeterX = 1.0f / metersInSpace;
spacesPerMeterY = 1.0f / metersInSpace; spacesPerMeterY = 1.0f / metersInSpace;
@ -680,7 +677,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
// Centeral contact friction and bounce // Centeral contact friction and bounce
// ckrinke 11/10/08 Enabling soft_erp but not soft_cfm until I figure out why // ckrinke 11/10/08 Enabling soft_erp but not soft_cfm until I figure out why
// an avatar falls through in Z but not in X or Y when walking on a prim. // an avatar falls through in Z but not in X or Y when walking on a prim.
contact.surface.mode |= d.ContactFlags.SoftERP; contact.surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
contact.surface.mu = nmAvatarObjectContactFriction; contact.surface.mu = nmAvatarObjectContactFriction;
contact.surface.bounce = nmAvatarObjectContactBounce; contact.surface.bounce = nmAvatarObjectContactBounce;
contact.surface.soft_cfm = 0.010f; contact.surface.soft_cfm = 0.010f;
@ -689,12 +686,12 @@ namespace OpenSim.Region.PhysicsModule.ODE
// Terrain contact friction and Bounce // Terrain contact friction and Bounce
// This is the *non* moving version. Use this when an avatar // This is the *non* moving version. Use this when an avatar
// isn't moving to keep it in place better // isn't moving to keep it in place better
TerrainContact.surface.mode |= d.ContactFlags.SoftERP; TerrainContact.surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
TerrainContact.surface.mu = nmTerrainContactFriction; TerrainContact.surface.mu = nmTerrainContactFriction;
TerrainContact.surface.bounce = nmTerrainContactBounce; TerrainContact.surface.bounce = nmTerrainContactBounce;
TerrainContact.surface.soft_erp = nmTerrainContactERP; TerrainContact.surface.soft_erp = nmTerrainContactERP;
WaterContact.surface.mode |= (d.ContactFlags.SoftERP | d.ContactFlags.SoftCFM); WaterContact.surface.mode |= (SafeNativeMethods.ContactFlags.SoftERP | SafeNativeMethods.ContactFlags.SoftCFM);
WaterContact.surface.mu = 0f; // No friction WaterContact.surface.mu = 0f; // No friction
WaterContact.surface.bounce = 0.0f; // No bounce WaterContact.surface.bounce = 0.0f; // No bounce
WaterContact.surface.soft_cfm = 0.010f; WaterContact.surface.soft_cfm = 0.010f;
@ -709,7 +706,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
// Terrain contact friction bounce and various error correcting calculations // Terrain contact friction bounce and various error correcting calculations
// Use this when an avatar is in contact with the terrain and moving. // Use this when an avatar is in contact with the terrain and moving.
AvatarMovementTerrainContact.surface.mode |= d.ContactFlags.SoftERP; AvatarMovementTerrainContact.surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
AvatarMovementTerrainContact.surface.mu = mTerrainContactFriction; AvatarMovementTerrainContact.surface.mu = mTerrainContactFriction;
AvatarMovementTerrainContact.surface.bounce = mTerrainContactBounce; AvatarMovementTerrainContact.surface.bounce = mTerrainContactBounce;
AvatarMovementTerrainContact.surface.soft_erp = mTerrainContactERP; AvatarMovementTerrainContact.surface.soft_erp = mTerrainContactERP;
@ -731,38 +728,38 @@ namespace OpenSim.Region.PhysicsModule.ODE
Rubber = 6 Rubber = 6
*/ */
m_materialContacts = new d.Contact[7,2]; m_materialContacts = new SafeNativeMethods.Contact[7,2];
m_materialContacts[(int)Material.Stone, 0] = new d.Contact(); m_materialContacts[(int)Material.Stone, 0] = new SafeNativeMethods.Contact();
m_materialContacts[(int)Material.Stone, 0].surface.mode |= d.ContactFlags.SoftERP; m_materialContacts[(int)Material.Stone, 0].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
m_materialContacts[(int)Material.Stone, 0].surface.mu = nmAvatarObjectContactFriction; m_materialContacts[(int)Material.Stone, 0].surface.mu = nmAvatarObjectContactFriction;
m_materialContacts[(int)Material.Stone, 0].surface.bounce = nmAvatarObjectContactBounce; m_materialContacts[(int)Material.Stone, 0].surface.bounce = nmAvatarObjectContactBounce;
m_materialContacts[(int)Material.Stone, 0].surface.soft_cfm = 0.010f; m_materialContacts[(int)Material.Stone, 0].surface.soft_cfm = 0.010f;
m_materialContacts[(int)Material.Stone, 0].surface.soft_erp = 0.010f; m_materialContacts[(int)Material.Stone, 0].surface.soft_erp = 0.010f;
m_materialContacts[(int)Material.Stone, 1] = new d.Contact(); m_materialContacts[(int)Material.Stone, 1] = new SafeNativeMethods.Contact();
m_materialContacts[(int)Material.Stone, 1].surface.mode |= d.ContactFlags.SoftERP; m_materialContacts[(int)Material.Stone, 1].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
m_materialContacts[(int)Material.Stone, 1].surface.mu = mAvatarObjectContactFriction; m_materialContacts[(int)Material.Stone, 1].surface.mu = mAvatarObjectContactFriction;
m_materialContacts[(int)Material.Stone, 1].surface.bounce = mAvatarObjectContactBounce; m_materialContacts[(int)Material.Stone, 1].surface.bounce = mAvatarObjectContactBounce;
m_materialContacts[(int)Material.Stone, 1].surface.soft_cfm = 0.010f; m_materialContacts[(int)Material.Stone, 1].surface.soft_cfm = 0.010f;
m_materialContacts[(int)Material.Stone, 1].surface.soft_erp = 0.010f; m_materialContacts[(int)Material.Stone, 1].surface.soft_erp = 0.010f;
m_materialContacts[(int)Material.Metal, 0] = new d.Contact(); m_materialContacts[(int)Material.Metal, 0] = new SafeNativeMethods.Contact();
m_materialContacts[(int)Material.Metal, 0].surface.mode |= d.ContactFlags.SoftERP; m_materialContacts[(int)Material.Metal, 0].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
m_materialContacts[(int)Material.Metal, 0].surface.mu = nmAvatarObjectContactFriction; m_materialContacts[(int)Material.Metal, 0].surface.mu = nmAvatarObjectContactFriction;
m_materialContacts[(int)Material.Metal, 0].surface.bounce = nmAvatarObjectContactBounce; m_materialContacts[(int)Material.Metal, 0].surface.bounce = nmAvatarObjectContactBounce;
m_materialContacts[(int)Material.Metal, 0].surface.soft_cfm = 0.010f; m_materialContacts[(int)Material.Metal, 0].surface.soft_cfm = 0.010f;
m_materialContacts[(int)Material.Metal, 0].surface.soft_erp = 0.010f; m_materialContacts[(int)Material.Metal, 0].surface.soft_erp = 0.010f;
m_materialContacts[(int)Material.Metal, 1] = new d.Contact(); m_materialContacts[(int)Material.Metal, 1] = new SafeNativeMethods.Contact();
m_materialContacts[(int)Material.Metal, 1].surface.mode |= d.ContactFlags.SoftERP; m_materialContacts[(int)Material.Metal, 1].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
m_materialContacts[(int)Material.Metal, 1].surface.mu = mAvatarObjectContactFriction; m_materialContacts[(int)Material.Metal, 1].surface.mu = mAvatarObjectContactFriction;
m_materialContacts[(int)Material.Metal, 1].surface.bounce = mAvatarObjectContactBounce; m_materialContacts[(int)Material.Metal, 1].surface.bounce = mAvatarObjectContactBounce;
m_materialContacts[(int)Material.Metal, 1].surface.soft_cfm = 0.010f; m_materialContacts[(int)Material.Metal, 1].surface.soft_cfm = 0.010f;
m_materialContacts[(int)Material.Metal, 1].surface.soft_erp = 0.010f; m_materialContacts[(int)Material.Metal, 1].surface.soft_erp = 0.010f;
m_materialContacts[(int)Material.Glass, 0] = new d.Contact(); m_materialContacts[(int)Material.Glass, 0] = new SafeNativeMethods.Contact();
m_materialContacts[(int)Material.Glass, 0].surface.mode |= d.ContactFlags.SoftERP; m_materialContacts[(int)Material.Glass, 0].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
m_materialContacts[(int)Material.Glass, 0].surface.mu = 1f; m_materialContacts[(int)Material.Glass, 0].surface.mu = 1f;
m_materialContacts[(int)Material.Glass, 0].surface.bounce = 0.5f; m_materialContacts[(int)Material.Glass, 0].surface.bounce = 0.5f;
m_materialContacts[(int)Material.Glass, 0].surface.soft_cfm = 0.010f; m_materialContacts[(int)Material.Glass, 0].surface.soft_cfm = 0.010f;
@ -775,83 +772,83 @@ namespace OpenSim.Region.PhysicsModule.ODE
private float mAvatarObjectContactFriction = 75f; private float mAvatarObjectContactFriction = 75f;
private float mAvatarObjectContactBounce = 0.1f; private float mAvatarObjectContactBounce = 0.1f;
*/ */
m_materialContacts[(int)Material.Glass, 1] = new d.Contact(); m_materialContacts[(int)Material.Glass, 1] = new SafeNativeMethods.Contact();
m_materialContacts[(int)Material.Glass, 1].surface.mode |= d.ContactFlags.SoftERP; m_materialContacts[(int)Material.Glass, 1].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
m_materialContacts[(int)Material.Glass, 1].surface.mu = 1f; m_materialContacts[(int)Material.Glass, 1].surface.mu = 1f;
m_materialContacts[(int)Material.Glass, 1].surface.bounce = 0.5f; m_materialContacts[(int)Material.Glass, 1].surface.bounce = 0.5f;
m_materialContacts[(int)Material.Glass, 1].surface.soft_cfm = 0.010f; m_materialContacts[(int)Material.Glass, 1].surface.soft_cfm = 0.010f;
m_materialContacts[(int)Material.Glass, 1].surface.soft_erp = 0.010f; m_materialContacts[(int)Material.Glass, 1].surface.soft_erp = 0.010f;
m_materialContacts[(int)Material.Wood, 0] = new d.Contact(); m_materialContacts[(int)Material.Wood, 0] = new SafeNativeMethods.Contact();
m_materialContacts[(int)Material.Wood, 0].surface.mode |= d.ContactFlags.SoftERP; m_materialContacts[(int)Material.Wood, 0].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
m_materialContacts[(int)Material.Wood, 0].surface.mu = nmAvatarObjectContactFriction; m_materialContacts[(int)Material.Wood, 0].surface.mu = nmAvatarObjectContactFriction;
m_materialContacts[(int)Material.Wood, 0].surface.bounce = nmAvatarObjectContactBounce; m_materialContacts[(int)Material.Wood, 0].surface.bounce = nmAvatarObjectContactBounce;
m_materialContacts[(int)Material.Wood, 0].surface.soft_cfm = 0.010f; m_materialContacts[(int)Material.Wood, 0].surface.soft_cfm = 0.010f;
m_materialContacts[(int)Material.Wood, 0].surface.soft_erp = 0.010f; m_materialContacts[(int)Material.Wood, 0].surface.soft_erp = 0.010f;
m_materialContacts[(int)Material.Wood, 1] = new d.Contact(); m_materialContacts[(int)Material.Wood, 1] = new SafeNativeMethods.Contact();
m_materialContacts[(int)Material.Wood, 1].surface.mode |= d.ContactFlags.SoftERP; m_materialContacts[(int)Material.Wood, 1].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
m_materialContacts[(int)Material.Wood, 1].surface.mu = mAvatarObjectContactFriction; m_materialContacts[(int)Material.Wood, 1].surface.mu = mAvatarObjectContactFriction;
m_materialContacts[(int)Material.Wood, 1].surface.bounce = mAvatarObjectContactBounce; m_materialContacts[(int)Material.Wood, 1].surface.bounce = mAvatarObjectContactBounce;
m_materialContacts[(int)Material.Wood, 1].surface.soft_cfm = 0.010f; m_materialContacts[(int)Material.Wood, 1].surface.soft_cfm = 0.010f;
m_materialContacts[(int)Material.Wood, 1].surface.soft_erp = 0.010f; m_materialContacts[(int)Material.Wood, 1].surface.soft_erp = 0.010f;
m_materialContacts[(int)Material.Flesh, 0] = new d.Contact(); m_materialContacts[(int)Material.Flesh, 0] = new SafeNativeMethods.Contact();
m_materialContacts[(int)Material.Flesh, 0].surface.mode |= d.ContactFlags.SoftERP; m_materialContacts[(int)Material.Flesh, 0].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
m_materialContacts[(int)Material.Flesh, 0].surface.mu = nmAvatarObjectContactFriction; m_materialContacts[(int)Material.Flesh, 0].surface.mu = nmAvatarObjectContactFriction;
m_materialContacts[(int)Material.Flesh, 0].surface.bounce = nmAvatarObjectContactBounce; m_materialContacts[(int)Material.Flesh, 0].surface.bounce = nmAvatarObjectContactBounce;
m_materialContacts[(int)Material.Flesh, 0].surface.soft_cfm = 0.010f; m_materialContacts[(int)Material.Flesh, 0].surface.soft_cfm = 0.010f;
m_materialContacts[(int)Material.Flesh, 0].surface.soft_erp = 0.010f; m_materialContacts[(int)Material.Flesh, 0].surface.soft_erp = 0.010f;
m_materialContacts[(int)Material.Flesh, 1] = new d.Contact(); m_materialContacts[(int)Material.Flesh, 1] = new SafeNativeMethods.Contact();
m_materialContacts[(int)Material.Flesh, 1].surface.mode |= d.ContactFlags.SoftERP; m_materialContacts[(int)Material.Flesh, 1].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
m_materialContacts[(int)Material.Flesh, 1].surface.mu = mAvatarObjectContactFriction; m_materialContacts[(int)Material.Flesh, 1].surface.mu = mAvatarObjectContactFriction;
m_materialContacts[(int)Material.Flesh, 1].surface.bounce = mAvatarObjectContactBounce; m_materialContacts[(int)Material.Flesh, 1].surface.bounce = mAvatarObjectContactBounce;
m_materialContacts[(int)Material.Flesh, 1].surface.soft_cfm = 0.010f; m_materialContacts[(int)Material.Flesh, 1].surface.soft_cfm = 0.010f;
m_materialContacts[(int)Material.Flesh, 1].surface.soft_erp = 0.010f; m_materialContacts[(int)Material.Flesh, 1].surface.soft_erp = 0.010f;
m_materialContacts[(int)Material.Plastic, 0] = new d.Contact(); m_materialContacts[(int)Material.Plastic, 0] = new SafeNativeMethods.Contact();
m_materialContacts[(int)Material.Plastic, 0].surface.mode |= d.ContactFlags.SoftERP; m_materialContacts[(int)Material.Plastic, 0].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
m_materialContacts[(int)Material.Plastic, 0].surface.mu = nmAvatarObjectContactFriction; m_materialContacts[(int)Material.Plastic, 0].surface.mu = nmAvatarObjectContactFriction;
m_materialContacts[(int)Material.Plastic, 0].surface.bounce = nmAvatarObjectContactBounce; m_materialContacts[(int)Material.Plastic, 0].surface.bounce = nmAvatarObjectContactBounce;
m_materialContacts[(int)Material.Plastic, 0].surface.soft_cfm = 0.010f; m_materialContacts[(int)Material.Plastic, 0].surface.soft_cfm = 0.010f;
m_materialContacts[(int)Material.Plastic, 0].surface.soft_erp = 0.010f; m_materialContacts[(int)Material.Plastic, 0].surface.soft_erp = 0.010f;
m_materialContacts[(int)Material.Plastic, 1] = new d.Contact(); m_materialContacts[(int)Material.Plastic, 1] = new SafeNativeMethods.Contact();
m_materialContacts[(int)Material.Plastic, 1].surface.mode |= d.ContactFlags.SoftERP; m_materialContacts[(int)Material.Plastic, 1].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
m_materialContacts[(int)Material.Plastic, 1].surface.mu = mAvatarObjectContactFriction; m_materialContacts[(int)Material.Plastic, 1].surface.mu = mAvatarObjectContactFriction;
m_materialContacts[(int)Material.Plastic, 1].surface.bounce = mAvatarObjectContactBounce; m_materialContacts[(int)Material.Plastic, 1].surface.bounce = mAvatarObjectContactBounce;
m_materialContacts[(int)Material.Plastic, 1].surface.soft_cfm = 0.010f; m_materialContacts[(int)Material.Plastic, 1].surface.soft_cfm = 0.010f;
m_materialContacts[(int)Material.Plastic, 1].surface.soft_erp = 0.010f; m_materialContacts[(int)Material.Plastic, 1].surface.soft_erp = 0.010f;
m_materialContacts[(int)Material.Rubber, 0] = new d.Contact(); m_materialContacts[(int)Material.Rubber, 0] = new SafeNativeMethods.Contact();
m_materialContacts[(int)Material.Rubber, 0].surface.mode |= d.ContactFlags.SoftERP; m_materialContacts[(int)Material.Rubber, 0].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
m_materialContacts[(int)Material.Rubber, 0].surface.mu = nmAvatarObjectContactFriction; m_materialContacts[(int)Material.Rubber, 0].surface.mu = nmAvatarObjectContactFriction;
m_materialContacts[(int)Material.Rubber, 0].surface.bounce = nmAvatarObjectContactBounce; m_materialContacts[(int)Material.Rubber, 0].surface.bounce = nmAvatarObjectContactBounce;
m_materialContacts[(int)Material.Rubber, 0].surface.soft_cfm = 0.010f; m_materialContacts[(int)Material.Rubber, 0].surface.soft_cfm = 0.010f;
m_materialContacts[(int)Material.Rubber, 0].surface.soft_erp = 0.010f; m_materialContacts[(int)Material.Rubber, 0].surface.soft_erp = 0.010f;
m_materialContacts[(int)Material.Rubber, 1] = new d.Contact(); m_materialContacts[(int)Material.Rubber, 1] = new SafeNativeMethods.Contact();
m_materialContacts[(int)Material.Rubber, 1].surface.mode |= d.ContactFlags.SoftERP; m_materialContacts[(int)Material.Rubber, 1].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
m_materialContacts[(int)Material.Rubber, 1].surface.mu = mAvatarObjectContactFriction; m_materialContacts[(int)Material.Rubber, 1].surface.mu = mAvatarObjectContactFriction;
m_materialContacts[(int)Material.Rubber, 1].surface.bounce = mAvatarObjectContactBounce; m_materialContacts[(int)Material.Rubber, 1].surface.bounce = mAvatarObjectContactBounce;
m_materialContacts[(int)Material.Rubber, 1].surface.soft_cfm = 0.010f; m_materialContacts[(int)Material.Rubber, 1].surface.soft_cfm = 0.010f;
m_materialContacts[(int)Material.Rubber, 1].surface.soft_erp = 0.010f; m_materialContacts[(int)Material.Rubber, 1].surface.soft_erp = 0.010f;
d.HashSpaceSetLevels(space, HashspaceLow, HashspaceHigh); SafeNativeMethods.HashSpaceSetLevels(space, HashspaceLow, HashspaceHigh);
// Set the gravity,, don't disable things automatically (we set it explicitly on some things) // Set the gravity,, don't disable things automatically (we set it explicitly on some things)
d.WorldSetGravity(world, gravityx, gravityy, gravityz); SafeNativeMethods.WorldSetGravity(world, gravityx, gravityy, gravityz);
d.WorldSetContactSurfaceLayer(world, contactsurfacelayer); SafeNativeMethods.WorldSetContactSurfaceLayer(world, contactsurfacelayer);
d.WorldSetLinearDamping(world, 256f); SafeNativeMethods.WorldSetLinearDamping(world, 256f);
d.WorldSetAngularDamping(world, 256f); SafeNativeMethods.WorldSetAngularDamping(world, 256f);
d.WorldSetAngularDampingThreshold(world, 256f); SafeNativeMethods.WorldSetAngularDampingThreshold(world, 256f);
d.WorldSetLinearDampingThreshold(world, 256f); SafeNativeMethods.WorldSetLinearDampingThreshold(world, 256f);
d.WorldSetMaxAngularSpeed(world, 256f); SafeNativeMethods.WorldSetMaxAngularSpeed(world, 256f);
d.WorldSetQuickStepNumIterations(world, m_physicsiterations); SafeNativeMethods.WorldSetQuickStepNumIterations(world, m_physicsiterations);
//d.WorldSetContactMaxCorrectingVel(world, 1000.0f); //d.WorldSetContactMaxCorrectingVel(world, 1000.0f);
for (int i = 0; i < staticPrimspace.GetLength(0); i++) for (int i = 0; i < staticPrimspace.GetLength(0); i++)
@ -877,7 +874,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
/// <param name='contactsArray'></param> /// <param name='contactsArray'></param>
/// <param name='contactGeomSize'></param> /// <param name='contactGeomSize'></param>
private int CollideGeoms( private int CollideGeoms(
IntPtr geom1, IntPtr geom2, int maxContacts, d.ContactGeom[] contactsArray, int contactGeomSize) IntPtr geom1, IntPtr geom2, int maxContacts, SafeNativeMethods.ContactGeom[] contactsArray, int contactGeomSize)
{ {
int count; int count;
@ -887,7 +884,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (CollectStats) if (CollectStats)
m_nativeCollisionStartTick = Util.EnvironmentTickCount(); m_nativeCollisionStartTick = Util.EnvironmentTickCount();
count = d.Collide(geom1, geom2, maxContacts, contactsArray, contactGeomSize); count = SafeNativeMethods.Collide(geom1, geom2, maxContacts, contactsArray, contactGeomSize);
} }
// We do this outside the lock so that any waiting threads aren't held up, though the effect is probably // We do this outside the lock so that any waiting threads aren't held up, though the effect is probably
@ -913,7 +910,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
m_nativeCollisionStartTick = Util.EnvironmentTickCount(); m_nativeCollisionStartTick = Util.EnvironmentTickCount();
} }
d.SpaceCollide2(space1, space2, data, nearCallback); SafeNativeMethods.SpaceCollide2(space1, space2, data, nearCallback);
if (CollectStats && m_inCollisionTiming) if (CollectStats && m_inCollisionTiming)
{ {
@ -944,7 +941,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
// Test if we're colliding a geom with a space. // Test if we're colliding a geom with a space.
// If so we have to drill down into the space recursively // If so we have to drill down into the space recursively
if (d.GeomIsSpace(g1) || d.GeomIsSpace(g2)) if (SafeNativeMethods.GeomIsSpace(g1) || SafeNativeMethods.GeomIsSpace(g2))
{ {
if (g1 == IntPtr.Zero || g2 == IntPtr.Zero) if (g1 == IntPtr.Zero || g2 == IntPtr.Zero)
return; return;
@ -973,8 +970,8 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (g1 == IntPtr.Zero || g2 == IntPtr.Zero) if (g1 == IntPtr.Zero || g2 == IntPtr.Zero)
return; return;
IntPtr b1 = d.GeomGetBody(g1); IntPtr b1 = SafeNativeMethods.GeomGetBody(g1);
IntPtr b2 = d.GeomGetBody(g2); IntPtr b2 = SafeNativeMethods.GeomGetBody(g2);
// d.GeomClassID id = d.GeomGetClass(g1); // d.GeomClassID id = d.GeomGetClass(g1);
@ -1001,10 +998,10 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (g1 == g2) if (g1 == g2)
return; // Can't collide with yourself return; // Can't collide with yourself
if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact)) if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && SafeNativeMethods.AreConnectedExcluding(b1, b2, SafeNativeMethods.JointType.Contact))
return; return;
count = CollideGeoms(g1, g2, contacts.Length, contacts, d.ContactGeom.unmanagedSizeOf); count = CollideGeoms(g1, g2, contacts.Length, contacts, SafeNativeMethods.ContactGeom.unmanagedSizeOf);
// All code after this is only relevant if we have any collisions // All code after this is only relevant if we have any collisions
if (count <= 0) if (count <= 0)
@ -1052,7 +1049,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
d.ContactGeom curContact = contacts[i]; SafeNativeMethods.ContactGeom curContact = contacts[i];
if (curContact.depth > maxDepthContact.PenetrationDepth) if (curContact.depth > maxDepthContact.PenetrationDepth)
{ {
@ -1129,7 +1126,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
curContact.depth = 0.00000003f; curContact.depth = 0.00000003f;
p2.Velocity = p2.Velocity + new Vector3(0f, 0f, 0.5f); p2.Velocity = p2.Velocity + new Vector3(0f, 0f, 0.5f);
curContact.pos = curContact.pos =
new d.Vector3(curContact.pos.X + (p1.Size.X/2), new SafeNativeMethods.Vector3(curContact.pos.X + (p1.Size.X/2),
curContact.pos.Y + (p1.Size.Y/2), curContact.pos.Y + (p1.Size.Y/2),
curContact.pos.Z + (p1.Size.Z/2)); curContact.pos.Z + (p1.Size.Z/2));
character.SetPidStatus(true); character.SetPidStatus(true);
@ -1146,7 +1143,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
curContact.depth = 0.00000003f; curContact.depth = 0.00000003f;
p1.Velocity = p1.Velocity + new Vector3(0f, 0f, 0.5f); p1.Velocity = p1.Velocity + new Vector3(0f, 0f, 0.5f);
curContact.pos = curContact.pos =
new d.Vector3(curContact.pos.X + (p1.Size.X/2), new SafeNativeMethods.Vector3(curContact.pos.X + (p1.Size.X/2),
curContact.pos.Y + (p1.Size.Y/2), curContact.pos.Y + (p1.Size.Y/2),
curContact.pos.Z + (p1.Size.Z/2)); curContact.pos.Z + (p1.Size.Z/2));
character.SetPidStatus(true); character.SetPidStatus(true);
@ -1198,7 +1195,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (m_global_contactcount < maxContactsbeforedeath) if (m_global_contactcount < maxContactsbeforedeath)
{ {
joint = d.JointCreateContact(world, contactgroup, ref AvatarMovementTerrainContact); joint = SafeNativeMethods.JointCreateContact(world, contactgroup, ref AvatarMovementTerrainContact);
m_global_contactcount++; m_global_contactcount++;
} }
} }
@ -1212,7 +1209,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (m_global_contactcount < maxContactsbeforedeath) if (m_global_contactcount < maxContactsbeforedeath)
{ {
joint = d.JointCreateContact(world, contactgroup, ref TerrainContact); joint = SafeNativeMethods.JointCreateContact(world, contactgroup, ref TerrainContact);
m_global_contactcount++; m_global_contactcount++;
} }
} }
@ -1247,7 +1244,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (m_global_contactcount < maxContactsbeforedeath) if (m_global_contactcount < maxContactsbeforedeath)
{ {
joint = d.JointCreateContact(world, contactgroup, ref m_materialContacts[material, movintYN]); joint = SafeNativeMethods.JointCreateContact(world, contactgroup, ref m_materialContacts[material, movintYN]);
m_global_contactcount++; m_global_contactcount++;
} }
} }
@ -1273,7 +1270,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (m_global_contactcount < maxContactsbeforedeath) if (m_global_contactcount < maxContactsbeforedeath)
{ {
joint = d.JointCreateContact(world, contactgroup, ref m_materialContacts[material, movintYN]); joint = SafeNativeMethods.JointCreateContact(world, contactgroup, ref m_materialContacts[material, movintYN]);
m_global_contactcount++; m_global_contactcount++;
} }
} }
@ -1307,7 +1304,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (m_global_contactcount < maxContactsbeforedeath) if (m_global_contactcount < maxContactsbeforedeath)
{ {
joint = d.JointCreateContact(world, contactgroup, ref WaterContact); joint = SafeNativeMethods.JointCreateContact(world, contactgroup, ref WaterContact);
m_global_contactcount++; m_global_contactcount++;
} }
//m_log.Info("[PHYSICS]: Prim Water Contact" + contact.depth); //m_log.Info("[PHYSICS]: Prim Water Contact" + contact.depth);
@ -1324,7 +1321,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (m_global_contactcount < maxContactsbeforedeath) if (m_global_contactcount < maxContactsbeforedeath)
{ {
joint = d.JointCreateContact(world, contactgroup, ref AvatarMovementprimContact); joint = SafeNativeMethods.JointCreateContact(world, contactgroup, ref AvatarMovementprimContact);
m_global_contactcount++; m_global_contactcount++;
} }
} }
@ -1335,7 +1332,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (m_global_contactcount < maxContactsbeforedeath) if (m_global_contactcount < maxContactsbeforedeath)
{ {
joint = d.JointCreateContact(world, contactgroup, ref contact); joint = SafeNativeMethods.JointCreateContact(world, contactgroup, ref contact);
m_global_contactcount++; m_global_contactcount++;
} }
} }
@ -1356,7 +1353,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (m_global_contactcount < maxContactsbeforedeath) if (m_global_contactcount < maxContactsbeforedeath)
{ {
joint = d.JointCreateContact(world, contactgroup, ref m_materialContacts[material, 0]); joint = SafeNativeMethods.JointCreateContact(world, contactgroup, ref m_materialContacts[material, 0]);
m_global_contactcount++; m_global_contactcount++;
} }
} }
@ -1364,7 +1361,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (m_global_contactcount < maxContactsbeforedeath && joint != IntPtr.Zero) // stack collide! if (m_global_contactcount < maxContactsbeforedeath && joint != IntPtr.Zero) // stack collide!
{ {
d.JointAttach(joint, b1, b2); SafeNativeMethods.JointAttach(joint, b1, b2);
m_global_contactcount++; m_global_contactcount++;
} }
} }
@ -1384,7 +1381,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
} }
} }
private bool checkDupe(d.ContactGeom contactGeom, int atype) private bool checkDupe(SafeNativeMethods.ContactGeom contactGeom, int atype)
{ {
if (!m_filterCollisions) if (!m_filterCollisions)
return false; return false;
@ -1393,7 +1390,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
ActorTypes at = (ActorTypes)atype; ActorTypes at = (ActorTypes)atype;
foreach (d.ContactGeom contact in _perloopContact) foreach (SafeNativeMethods.ContactGeom contact in _perloopContact)
{ {
//if ((contact.g1 == contactGeom.g1 && contact.g2 == contactGeom.g2)) //if ((contact.g1 == contactGeom.g1 && contact.g2 == contactGeom.g2))
//{ //{
@ -1580,7 +1577,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
List<OdePrim> removeprims = null; List<OdePrim> removeprims = null;
foreach (OdePrim chr in _activeprims) foreach (OdePrim chr in _activeprims)
{ {
if (chr.Body != IntPtr.Zero && d.BodyIsEnabled(chr.Body) && (!chr.m_disabled)) if (chr.Body != IntPtr.Zero && SafeNativeMethods.BodyIsEnabled(chr.Body) && (!chr.m_disabled))
{ {
try try
{ {
@ -1706,7 +1703,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying) public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying)
{ {
d.AllocateODEDataForThread(0); SafeNativeMethods.AllocateODEDataForThread(0);
OdeCharacter newAv OdeCharacter newAv
= new OdeCharacter( = new OdeCharacter(
@ -1729,7 +1726,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
lock (OdeLock) lock (OdeLock)
{ {
d.AllocateODEDataForThread(0); SafeNativeMethods.AllocateODEDataForThread(0);
((OdeCharacter) actor).Destroy(); ((OdeCharacter) actor).Destroy();
} }
@ -1786,7 +1783,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
OdePrim newPrim; OdePrim newPrim;
lock (OdeLock) lock (OdeLock)
{ {
d.AllocateODEDataForThread(0); SafeNativeMethods.AllocateODEDataForThread(0);
newPrim = new OdePrim(name, this, pos, siz, rot, pbs, isphysical); newPrim = new OdePrim(name, this, pos, siz, rot, pbs, isphysical);
lock (_prims) lock (_prims)
@ -1950,7 +1947,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
DoJointDeactivated(joint); DoJointDeactivated(joint);
if (joint.jointID != IntPtr.Zero) if (joint.jointID != IntPtr.Zero)
{ {
d.JointDestroy(joint.jointID); SafeNativeMethods.JointDestroy(joint.jointID);
joint.jointID = IntPtr.Zero; joint.jointID = IntPtr.Zero;
//DoJointErrorMessage(joint, "successfully destroyed joint " + jointName); //DoJointErrorMessage(joint, "successfully destroyed joint " + jointName);
} }
@ -2115,7 +2112,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
public override Vector3 GetJointAnchor(PhysicsJoint joint) public override Vector3 GetJointAnchor(PhysicsJoint joint)
{ {
Debug.Assert(joint.IsInPhysicsEngine); Debug.Assert(joint.IsInPhysicsEngine);
d.Vector3 pos = new d.Vector3(); SafeNativeMethods.Vector3 pos = new SafeNativeMethods.Vector3();
if (!(joint is OdePhysicsJoint)) if (!(joint is OdePhysicsJoint))
{ {
@ -2127,10 +2124,10 @@ namespace OpenSim.Region.PhysicsModule.ODE
switch (odeJoint.Type) switch (odeJoint.Type)
{ {
case PhysicsJointType.Ball: case PhysicsJointType.Ball:
d.JointGetBallAnchor(odeJoint.jointID, out pos); SafeNativeMethods.JointGetBallAnchor(odeJoint.jointID, out pos);
break; break;
case PhysicsJointType.Hinge: case PhysicsJointType.Hinge:
d.JointGetHingeAnchor(odeJoint.jointID, out pos); SafeNativeMethods.JointGetHingeAnchor(odeJoint.jointID, out pos);
break; break;
} }
} }
@ -2151,7 +2148,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
public override Vector3 GetJointAxis(PhysicsJoint joint) public override Vector3 GetJointAxis(PhysicsJoint joint)
{ {
Debug.Assert(joint.IsInPhysicsEngine); Debug.Assert(joint.IsInPhysicsEngine);
d.Vector3 axis = new d.Vector3(); SafeNativeMethods.Vector3 axis = new SafeNativeMethods.Vector3();
if (!(joint is OdePhysicsJoint)) if (!(joint is OdePhysicsJoint))
{ {
@ -2166,7 +2163,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
DoJointErrorMessage(joint, "warning - axis requested for ball joint: " + joint.ObjectNameInScene); DoJointErrorMessage(joint, "warning - axis requested for ball joint: " + joint.ObjectNameInScene);
break; break;
case PhysicsJointType.Hinge: case PhysicsJointType.Hinge:
d.JointGetHingeAxis(odeJoint.jointID, out axis); SafeNativeMethods.JointGetHingeAxis(odeJoint.jointID, out axis);
break; break;
} }
} }
@ -2299,12 +2296,12 @@ namespace OpenSim.Region.PhysicsModule.ODE
//{ //{
//int adfadf = 0; //int adfadf = 0;
//} //}
if (d.SpaceQuery(currentspace, geom) && currentspace != IntPtr.Zero) if (SafeNativeMethods.SpaceQuery(currentspace, geom) && currentspace != IntPtr.Zero)
{ {
if (d.GeomIsSpace(currentspace)) if (SafeNativeMethods.GeomIsSpace(currentspace))
{ {
// waitForSpaceUnlock(currentspace); // waitForSpaceUnlock(currentspace);
d.SpaceRemove(currentspace, geom); SafeNativeMethods.SpaceRemove(currentspace, geom);
} }
else else
{ {
@ -2314,13 +2311,13 @@ namespace OpenSim.Region.PhysicsModule.ODE
} }
else else
{ {
IntPtr sGeomIsIn = d.GeomGetSpace(geom); IntPtr sGeomIsIn = SafeNativeMethods.GeomGetSpace(geom);
if (sGeomIsIn != IntPtr.Zero) if (sGeomIsIn != IntPtr.Zero)
{ {
if (d.GeomIsSpace(currentspace)) if (SafeNativeMethods.GeomIsSpace(currentspace))
{ {
// waitForSpaceUnlock(sGeomIsIn); // waitForSpaceUnlock(sGeomIsIn);
d.SpaceRemove(sGeomIsIn, geom); SafeNativeMethods.SpaceRemove(sGeomIsIn, geom);
} }
else else
{ {
@ -2331,13 +2328,13 @@ namespace OpenSim.Region.PhysicsModule.ODE
} }
//If there are no more geometries in the sub-space, we don't need it in the main space anymore //If there are no more geometries in the sub-space, we don't need it in the main space anymore
if (d.SpaceGetNumGeoms(currentspace) == 0) if (SafeNativeMethods.SpaceGetNumGeoms(currentspace) == 0)
{ {
if (currentspace != IntPtr.Zero) if (currentspace != IntPtr.Zero)
{ {
if (d.GeomIsSpace(currentspace)) if (SafeNativeMethods.GeomIsSpace(currentspace))
{ {
d.SpaceRemove(space, currentspace); SafeNativeMethods.SpaceRemove(space, currentspace);
// free up memory used by the space. // free up memory used by the space.
resetSpaceArrayItemToZero(currentspace); resetSpaceArrayItemToZero(currentspace);
@ -2355,12 +2352,12 @@ namespace OpenSim.Region.PhysicsModule.ODE
// this is a physical object that got disabled. ;.; // this is a physical object that got disabled. ;.;
if (currentspace != IntPtr.Zero && geom != IntPtr.Zero) if (currentspace != IntPtr.Zero && geom != IntPtr.Zero)
{ {
if (d.SpaceQuery(currentspace, geom)) if (SafeNativeMethods.SpaceQuery(currentspace, geom))
{ {
if (d.GeomIsSpace(currentspace)) if (SafeNativeMethods.GeomIsSpace(currentspace))
{ {
// waitForSpaceUnlock(currentspace); // waitForSpaceUnlock(currentspace);
d.SpaceRemove(currentspace, geom); SafeNativeMethods.SpaceRemove(currentspace, geom);
} }
else else
{ {
@ -2370,13 +2367,13 @@ namespace OpenSim.Region.PhysicsModule.ODE
} }
else else
{ {
IntPtr sGeomIsIn = d.GeomGetSpace(geom); IntPtr sGeomIsIn = SafeNativeMethods.GeomGetSpace(geom);
if (sGeomIsIn != IntPtr.Zero) if (sGeomIsIn != IntPtr.Zero)
{ {
if (d.GeomIsSpace(sGeomIsIn)) if (SafeNativeMethods.GeomIsSpace(sGeomIsIn))
{ {
// waitForSpaceUnlock(sGeomIsIn); // waitForSpaceUnlock(sGeomIsIn);
d.SpaceRemove(sGeomIsIn, geom); SafeNativeMethods.SpaceRemove(sGeomIsIn, geom);
} }
else else
{ {
@ -2397,7 +2394,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
if (newspace == IntPtr.Zero) if (newspace == IntPtr.Zero)
{ {
newspace = createprimspace(iprimspaceArrItem[0], iprimspaceArrItem[1]); newspace = createprimspace(iprimspaceArrItem[0], iprimspaceArrItem[1]);
d.HashSpaceSetLevels(newspace, HashspaceLow, HashspaceHigh); SafeNativeMethods.HashSpaceSetLevels(newspace, HashspaceLow, HashspaceHigh);
} }
return newspace; return newspace;
@ -2412,11 +2409,11 @@ namespace OpenSim.Region.PhysicsModule.ODE
internal IntPtr createprimspace(int iprimspaceArrItemX, int iprimspaceArrItemY) internal IntPtr createprimspace(int iprimspaceArrItemX, int iprimspaceArrItemY)
{ {
// creating a new space for prim and inserting it into main space. // creating a new space for prim and inserting it into main space.
staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY] = d.HashSpaceCreate(IntPtr.Zero); staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY] = SafeNativeMethods.HashSpaceCreate(IntPtr.Zero);
d.GeomSetCategoryBits(staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY], (int)CollisionCategories.Space); SafeNativeMethods.GeomSetCategoryBits(staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY], (int)CollisionCategories.Space);
// waitForSpaceUnlock(space); // waitForSpaceUnlock(space);
d.SpaceSetSublevel(space, 1); SafeNativeMethods.SpaceSetSublevel(space, 1);
d.SpaceAdd(space, staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]); SafeNativeMethods.SpaceAdd(space, staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]);
return staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]; return staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY];
} }
@ -2636,7 +2633,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
m_log.InfoFormat("[Ode] start processing pending actor operations"); m_log.InfoFormat("[Ode] start processing pending actor operations");
int tstart = Util.EnvironmentTickCount(); int tstart = Util.EnvironmentTickCount();
d.AllocateODEDataForThread(0); SafeNativeMethods.AllocateODEDataForThread(0);
lock (_taintedPrims) lock (_taintedPrims)
{ {
@ -2719,7 +2716,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
lock (OdeLock) lock (OdeLock)
{ {
d.AllocateODEDataForThread(~0U); SafeNativeMethods.AllocateODEDataForThread(~0U);
while (step_time > HalfOdeStep) while (step_time > HalfOdeStep)
{ {
@ -2871,12 +2868,12 @@ namespace OpenSim.Region.PhysicsModule.ODE
} }
lock(SimulationLock) lock(SimulationLock)
d.WorldQuickStep(world, ODE_STEPSIZE); SafeNativeMethods.WorldQuickStep(world, ODE_STEPSIZE);
if (CollectStats) if (CollectStats)
m_stats[ODENativeStepFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick); m_stats[ODENativeStepFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick);
d.JointGroupEmpty(contactgroup); SafeNativeMethods.JointGroupEmpty(contactgroup);
} }
catch (Exception e) catch (Exception e)
{ {
@ -2924,7 +2921,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
foreach (OdePrim prim in _activeprims) foreach (OdePrim prim in _activeprims)
{ {
if (prim.IsPhysical && (d.BodyIsEnabled(prim.Body) || !prim._zeroFlag)) if (prim.IsPhysical && (SafeNativeMethods.BodyIsEnabled(prim.Body) || !prim._zeroFlag))
{ {
prim.UpdatePositionAndVelocity(); prim.UpdatePositionAndVelocity();
@ -2954,7 +2951,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
fwriter.Close(); fwriter.Close();
} }
d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix); SafeNativeMethods.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix);
} }
latertickcount = Util.EnvironmentTickCountSubtract(tickCountFrameRun); latertickcount = Util.EnvironmentTickCountSubtract(tickCountFrameRun);
@ -3069,11 +3066,11 @@ namespace OpenSim.Region.PhysicsModule.ODE
{ {
IntPtr odeJoint; IntPtr odeJoint;
//DoJointErrorMessage(joint, "ODE creating ball joint "); //DoJointErrorMessage(joint, "ODE creating ball joint ");
odeJoint = d.JointCreateBall(world, IntPtr.Zero); odeJoint = SafeNativeMethods.JointCreateBall(world, IntPtr.Zero);
//DoJointErrorMessage(joint, "ODE attaching ball joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]); //DoJointErrorMessage(joint, "ODE attaching ball joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]);
d.JointAttach(odeJoint, jointBodies[0], jointBodies[1]); SafeNativeMethods.JointAttach(odeJoint, jointBodies[0], jointBodies[1]);
//DoJointErrorMessage(joint, "ODE setting ball anchor: " + odeJoint + " to vec:" + joint.Position); //DoJointErrorMessage(joint, "ODE setting ball anchor: " + odeJoint + " to vec:" + joint.Position);
d.JointSetBallAnchor(odeJoint, SafeNativeMethods.JointSetBallAnchor(odeJoint,
joint.Position.X, joint.Position.X,
joint.Position.Y, joint.Position.Y,
joint.Position.Z); joint.Position.Z);
@ -3097,11 +3094,11 @@ namespace OpenSim.Region.PhysicsModule.ODE
{ {
IntPtr odeJoint; IntPtr odeJoint;
//DoJointErrorMessage(joint, "ODE creating hinge joint "); //DoJointErrorMessage(joint, "ODE creating hinge joint ");
odeJoint = d.JointCreateHinge(world, IntPtr.Zero); odeJoint = SafeNativeMethods.JointCreateHinge(world, IntPtr.Zero);
//DoJointErrorMessage(joint, "ODE attaching hinge joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]); //DoJointErrorMessage(joint, "ODE attaching hinge joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]);
d.JointAttach(odeJoint, jointBodies[0], jointBodies[1]); SafeNativeMethods.JointAttach(odeJoint, jointBodies[0], jointBodies[1]);
//DoJointErrorMessage(joint, "ODE setting hinge anchor: " + odeJoint + " to vec:" + joint.Position); //DoJointErrorMessage(joint, "ODE setting hinge anchor: " + odeJoint + " to vec:" + joint.Position);
d.JointSetHingeAnchor(odeJoint, SafeNativeMethods.JointSetHingeAnchor(odeJoint,
joint.Position.X, joint.Position.X,
joint.Position.Y, joint.Position.Y,
joint.Position.Z); joint.Position.Z);
@ -3137,7 +3134,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
Vector3 jointAxis = Vector3.Transform(Vector3.UnitX, proxyFrame); Vector3 jointAxis = Vector3.Transform(Vector3.UnitX, proxyFrame);
//m_log.Debug("PHY: making axis: hinge joint axis is " + jointAxis); //m_log.Debug("PHY: making axis: hinge joint axis is " + jointAxis);
//DoJointErrorMessage(joint, "ODE setting hinge axis: " + odeJoint + " to vec:" + jointAxis); //DoJointErrorMessage(joint, "ODE setting hinge axis: " + odeJoint + " to vec:" + jointAxis);
d.JointSetHingeAxis(odeJoint, SafeNativeMethods.JointSetHingeAxis(odeJoint,
jointAxis.X, jointAxis.X,
jointAxis.Y, jointAxis.Y,
jointAxis.Z); jointAxis.Z);
@ -3299,7 +3296,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
lock (OdeLock) lock (OdeLock)
{ {
d.AllocateODEDataForThread(~0U); SafeNativeMethods.AllocateODEDataForThread(~0U);
IntPtr GroundGeom = IntPtr.Zero; IntPtr GroundGeom = IntPtr.Zero;
if (RegionTerrain.TryGetValue(pOffset, out GroundGeom)) if (RegionTerrain.TryGetValue(pOffset, out GroundGeom))
@ -3311,29 +3308,29 @@ namespace OpenSim.Region.PhysicsModule.ODE
{ {
TerrainHeightFieldHeights.Remove(GroundGeom); TerrainHeightFieldHeights.Remove(GroundGeom);
} }
d.SpaceRemove(space, GroundGeom); SafeNativeMethods.SpaceRemove(space, GroundGeom);
d.GeomDestroy(GroundGeom); SafeNativeMethods.GeomDestroy(GroundGeom);
} }
} }
IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); IntPtr HeightmapData = SafeNativeMethods.GeomHeightfieldDataCreate();
d.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmap, 0, SafeNativeMethods.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmap, 0,
heightmapWidth, heightmapHeight, heightmapWidth, heightmapHeight,
(int)heightmapWidthSamples, (int)heightmapWidthSamples,
(int)heightmapHeightSamples, (int)heightmapHeightSamples,
scale, offset, thickness, wrap); scale, offset, thickness, wrap);
d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1); SafeNativeMethods.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1);
GroundGeom = d.CreateHeightfield(space, HeightmapData, 1); GroundGeom = SafeNativeMethods.CreateHeightfield(space, HeightmapData, 1);
if (GroundGeom != IntPtr.Zero) if (GroundGeom != IntPtr.Zero)
{ {
d.GeomSetCategoryBits(GroundGeom, (int)(CollisionCategories.Land)); SafeNativeMethods.GeomSetCategoryBits(GroundGeom, (int)(CollisionCategories.Land));
d.GeomSetCollideBits(GroundGeom, (int)(CollisionCategories.Space)); SafeNativeMethods.GeomSetCollideBits(GroundGeom, (int)(CollisionCategories.Space));
} }
geom_name_map[GroundGeom] = "Terrain"; geom_name_map[GroundGeom] = "Terrain";
d.Matrix3 R = new d.Matrix3(); SafeNativeMethods.Matrix3 R = new SafeNativeMethods.Matrix3();
Quaternion q1 = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), 1.5707f); Quaternion q1 = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), 1.5707f);
Quaternion q2 = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), 1.5707f); Quaternion q2 = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), 1.5707f);
@ -3343,9 +3340,9 @@ namespace OpenSim.Region.PhysicsModule.ODE
float angle; float angle;
q1.GetAxisAngle(out v3, out angle); q1.GetAxisAngle(out v3, out angle);
d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle); SafeNativeMethods.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle);
d.GeomSetRotation(GroundGeom, ref R); SafeNativeMethods.GeomSetRotation(GroundGeom, ref R);
d.GeomSetPosition(GroundGeom, pOffset.X + regionsizeX * 0.5f, pOffset.Y + regionsizeY * 0.5f, 0.0f); SafeNativeMethods.GeomSetPosition(GroundGeom, pOffset.X + regionsizeX * 0.5f, pOffset.Y + regionsizeY * 0.5f, 0.0f);
IntPtr testGround = IntPtr.Zero; IntPtr testGround = IntPtr.Zero;
if (RegionTerrain.TryGetValue(pOffset, out testGround)) if (RegionTerrain.TryGetValue(pOffset, out testGround))
{ {
@ -3384,7 +3381,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
_worldInitialized = false; _worldInitialized = false;
d.AllocateODEDataForThread(~0U); SafeNativeMethods.AllocateODEDataForThread(~0U);
if (m_rayCastManager != null) if (m_rayCastManager != null)
{ {
@ -3412,13 +3409,13 @@ namespace OpenSim.Region.PhysicsModule.ODE
{ {
if (TerrainHeightFieldHeights.ContainsKey(GroundGeom)) if (TerrainHeightFieldHeights.ContainsKey(GroundGeom))
TerrainHeightFieldHeights.Remove(GroundGeom); TerrainHeightFieldHeights.Remove(GroundGeom);
d.GeomDestroy(GroundGeom); SafeNativeMethods.GeomDestroy(GroundGeom);
} }
} }
try try
{ {
d.WorldDestroy(world); SafeNativeMethods.WorldDestroy(world);
world = IntPtr.Zero; world = IntPtr.Zero;
} }
catch (AccessViolationException e) catch (AccessViolationException e)