From efd90b56b761219af6425b1c7a2cdd3b6ffb4de2 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Thu, 27 Dec 2007 21:41:48 +0000 Subject: * Optimized usings * shortened references * Removed redundant 'this' * Normalized EOF --- .../Physics/BasicPhysicsPlugin/AssemblyInfo.cs | 2 +- .../BasicPhysicsPlugin/BasicPhysicsPlugin.cs | 42 ++- .../Region/Physics/BulletXPlugin/AssemblyInfo.cs | 2 +- .../Region/Physics/BulletXPlugin/BulletXPlugin.cs | 206 ++++++++----- .../BulletXPlugin/TriangleIndexVertexArray.cs | 69 ++++- OpenSim/Region/Physics/Manager/AssemblyInfo.cs | 2 +- OpenSim/Region/Physics/Manager/IMesher.cs | 9 +- OpenSim/Region/Physics/Manager/PhysicsActor.cs | 101 ++++--- .../Region/Physics/Manager/PhysicsPluginManager.cs | 8 +- OpenSim/Region/Physics/Manager/PhysicsScene.cs | 15 +- OpenSim/Region/Physics/Manager/PhysicsVector.cs | 15 +- OpenSim/Region/Physics/Manager/ZeroMesher.cs | 9 +- OpenSim/Region/Physics/Meshing/Extruder.cs | 21 +- OpenSim/Region/Physics/Meshing/HelperTypes.cs | 10 +- OpenSim/Region/Physics/Meshing/Mesh.cs | 42 ++- OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 74 +++-- OpenSim/Region/Physics/Meshing/SimpleHull.cs | 120 ++++---- OpenSim/Region/Physics/Meshing/Simplex.cs | 49 ++- OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs | 2 +- OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 114 ++++--- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 175 +++++------ OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 336 +++++++++++---------- OpenSim/Region/Physics/POSPlugin/AssemblyInfo.cs | 2 +- OpenSim/Region/Physics/POSPlugin/POSPlugin.cs | 84 ++++-- OpenSim/Region/Physics/PhysXPlugin/AssemblyInfo.cs | 2 +- OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs | 124 ++++---- 26 files changed, 862 insertions(+), 773 deletions(-) (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/AssemblyInfo.cs index 919910c..b76fbbf 100644 --- a/OpenSim/Region/Physics/BasicPhysicsPlugin/AssemblyInfo.cs +++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/AssemblyInfo.cs @@ -55,4 +55,4 @@ using System.Runtime.InteropServices; // You can specify all values by your own or you can build default build and revision // numbers with the '*' character (the default): -[assembly : AssemblyVersion("1.0.*")] +[assembly : AssemblyVersion("1.0.*")] \ No newline at end of file diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs index 5ac651f..636cf1a 100644 --- a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs +++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs @@ -106,18 +106,19 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation) { - return this.AddPrimShape(primName, pbs, position, size, rotation, false); + return AddPrimShape(primName, pbs, position, size, rotation, false); } - public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, + public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation, bool isPhysical) { return null; } + public override void AddPhysicsActorTaint(PhysicsActor prim) { - } + public override float Simulate(float timeStep) { float fps = 0; @@ -125,8 +126,8 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin { BasicActor actor = _actors[i]; - actor.Position.X += actor.Velocity.X * timeStep; - actor.Position.Y += actor.Velocity.Y * timeStep; + actor.Position.X += actor.Velocity.X*timeStep; + actor.Position.Y += actor.Velocity.Y*timeStep; if (actor.Position.Y < 0) { @@ -146,18 +147,18 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin actor.Position.X = 255.9F; } - float height = _heightMap[(int) actor.Position.Y * 256 + (int) actor.Position.X] + 1.0f; + float height = _heightMap[(int) actor.Position.Y*256 + (int) actor.Position.X] + 1.0f; if (actor.Flying) { - if (actor.Position.Z + (actor.Velocity.Z * timeStep) < - _heightMap[(int) actor.Position.Y * 256 + (int) actor.Position.X] + 2) + if (actor.Position.Z + (actor.Velocity.Z*timeStep) < + _heightMap[(int) actor.Position.Y*256 + (int) actor.Position.X] + 2) { actor.Position.Z = height; actor.Velocity.Z = 0; } else { - actor.Position.Z += actor.Velocity.Z * timeStep; + actor.Position.Z += actor.Velocity.Z*timeStep; } } else @@ -204,31 +205,37 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin _position = new PhysicsVector(); _acceleration = new PhysicsVector(); } + public override int PhysicsActorType { - get { return (int)ActorTypes.Agent; } + get { return (int) ActorTypes.Agent; } set { return; } } + public override PhysicsVector RotationalVelocity { get { return m_rotationalVelocity; } set { m_rotationalVelocity = value; } } + public override bool SetAlwaysRun { get { return false; } set { return; } } + public override bool IsPhysical { get { return false; } set { return; } } + public override bool ThrottleUpdates { get { return false; } set { return; } } + public override bool Flying { get { return flying; } @@ -240,16 +247,19 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin get { return iscolliding; } set { iscolliding = value; } } + public override bool CollidingGround { get { return false; } set { return; } } + public override bool CollidingObj { get { return false; } set { return; } } + public override PhysicsVector Position { get { return _position; } @@ -264,27 +274,29 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin public override PrimitiveBaseShape Shape { - set - { - return; - } + set { return; } } + public override float Mass { get { return 0f; } } + public override PhysicsVector Force { get { return PhysicsVector.Zero; } } + public override PhysicsVector CenterOfMass { get { return PhysicsVector.Zero; } } + public override PhysicsVector GeometricCenter { get { return PhysicsVector.Zero; } } + public override PhysicsVector Velocity { get { return _velocity; } @@ -321,4 +333,4 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin { } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/BulletXPlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/BulletXPlugin/AssemblyInfo.cs index 06d4fe3..6b7ce82 100644 --- a/OpenSim/Region/Physics/BulletXPlugin/AssemblyInfo.cs +++ b/OpenSim/Region/Physics/BulletXPlugin/AssemblyInfo.cs @@ -55,4 +55,4 @@ using System.Runtime.InteropServices; // You can specify all values by your own or you can build default build and revision // numbers with the '*' character (the default): -[assembly : AssemblyVersion("1.0.0.0")] +[assembly : AssemblyVersion("1.0.0.0")] \ No newline at end of file diff --git a/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs b/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs index 5602301..a88299e 100644 --- a/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs +++ b/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs @@ -70,12 +70,11 @@ using XnaDevRu.BulletX; using XnaDevRu.BulletX.Dynamics; using AxiomQuaternion = Axiom.Math.Quaternion; using BoxShape=XnaDevRu.BulletX.BoxShape; -#endregion +#endregion namespace OpenSim.Region.Physics.BulletXPlugin { - /// /// BulletXConversions are called now BulletXMaths /// This Class converts objects and types for BulletX and give some operations @@ -263,25 +262,25 @@ namespace OpenSim.Region.Physics.BulletXPlugin // Class to detect and debug collisions // Mainly used for debugging purposes - class CollisionDispatcherLocal : CollisionDispatcher + internal class CollisionDispatcherLocal : CollisionDispatcher { - - BulletXScene relatedScene; + private BulletXScene relatedScene; public CollisionDispatcherLocal(BulletXScene s) : base() { - relatedScene=s; + relatedScene = s; } public override bool NeedsCollision(CollisionObject bodyA, CollisionObject bodyB) { RigidBody rb; - BulletXCharacter bxcA=null; + BulletXCharacter bxcA = null; BulletXPrim bxpA = null; Type t = bodyA.GetType(); - if (t==typeof(RigidBody)) { - rb = (RigidBody)bodyA; + if (t == typeof (RigidBody)) + { + rb = (RigidBody) bodyA; relatedScene._characters.TryGetValue(rb, out bxcA); relatedScene._prims.TryGetValue(rb, out bxpA); } @@ -296,9 +295,9 @@ namespace OpenSim.Region.Physics.BulletXPlugin BulletXCharacter bxcB = null; BulletXPrim bxpB = null; t = bodyB.GetType(); - if (t == typeof(RigidBody)) + if (t == typeof (RigidBody)) { - rb = (RigidBody)bodyB; + rb = (RigidBody) bodyB; relatedScene._characters.TryGetValue(rb, out bxcB); relatedScene._prims.TryGetValue(rb, out bxpB); } @@ -310,15 +309,16 @@ namespace OpenSim.Region.Physics.BulletXPlugin else nameB = "null"; - bool needsCollision=base.NeedsCollision(bodyA, bodyB); + bool needsCollision = base.NeedsCollision(bodyA, bodyB); - MainLog.Instance.Debug("BulletX", "A collision was detected between {0} and {1} --> {2}", nameA, nameB, needsCollision); + MainLog.Instance.Debug("BulletX", "A collision was detected between {0} and {1} --> {2}", nameA, nameB, + needsCollision); return needsCollision; } } - + /// /// PhysicsScene Class for BulletX /// @@ -439,7 +439,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin ((BulletXCharacter) actor).RigidBody.ActivationState = ActivationState.DisableSimulation; AddForgottenRigidBody(((BulletXCharacter) actor).RigidBody); } - _characters.Remove(((BulletXCharacter)actor).RigidBody); + _characters.Remove(((BulletXCharacter) actor).RigidBody); } GC.Collect(); } @@ -448,8 +448,9 @@ namespace OpenSim.Region.Physics.BulletXPlugin public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, AxiomQuaternion rotation) { - return this.AddPrimShape(primName, pbs, position, size, rotation, false); + return AddPrimShape(primName, pbs, position, size, rotation, false); } + public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, AxiomQuaternion rotation, bool isPhysical) { @@ -514,7 +515,6 @@ namespace OpenSim.Region.Physics.BulletXPlugin public override void AddPhysicsActorTaint(PhysicsActor prim) { - } public override float Simulate(float timeStep) @@ -526,10 +526,10 @@ namespace OpenSim.Region.Physics.BulletXPlugin RemoveForgottenRigidBodies(); //End of remove MoveAllObjects(timeStep); - - - fps = (timeStep * simulationSubSteps); - + + + fps = (timeStep*simulationSubSteps); + ddWorld.StepSimulation(timeStep, simulationSubSteps, timeStep); //Extra Heightmap Validation: BulletX's HeightFieldTerrain somestimes doesn't work so fine. ValidateHeightForAll(); @@ -768,7 +768,13 @@ namespace OpenSim.Region.Physics.BulletXPlugin public override PhysicsVector Size { get { return _size; } - set { lock (BulletXScene.BulletXLock) { _size = value; } } + set + { + lock (BulletXScene.BulletXLock) + { + _size = value; + } + } } public override PhysicsVector Force @@ -788,10 +794,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin public override PrimitiveBaseShape Shape { - set - { - return; - } + set { return; } } public override bool SetAlwaysRun @@ -818,9 +821,9 @@ namespace OpenSim.Region.Physics.BulletXPlugin } } - public override float Mass - { - get { return ActorMass; } + public override float Mass + { + get { return ActorMass; } } public virtual float ActorMass @@ -841,7 +844,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin public Vector3 RigidBodyPosition { - get { return this.rigidBody.CenterOfMassPosition; } + get { return rigidBody.CenterOfMassPosition; } } public override bool IsPhysical @@ -855,6 +858,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin get { return flying; } set { flying = value; } } + public override bool ThrottleUpdates { get { return false; } @@ -889,19 +893,12 @@ namespace OpenSim.Region.Physics.BulletXPlugin public override bool Kinematic { - get - { - return false; - } - set - { - - } + get { return false; } + set { } } public override void AddForce(PhysicsVector force) { - } public override void SetMomentum(PhysicsVector momentum) @@ -917,31 +914,37 @@ namespace OpenSim.Region.Physics.BulletXPlugin } #region Methods for updating values of RigidBody - internal protected void Translate() + + protected internal void Translate() { - Translate(this._position); + Translate(_position); } - internal protected void Translate(PhysicsVector _newPos) + + protected internal void Translate(PhysicsVector _newPos) { Vector3 _translation; _translation = BulletXMaths.PhysicsVectorToXnaVector3(_newPos) - rigidBody.CenterOfMassPosition; rigidBody.Translate(_translation); } - internal protected void Speed() + + protected internal void Speed() { - Speed(this._velocity); + Speed(_velocity); } - internal protected void Speed(PhysicsVector _newSpeed) + + protected internal void Speed(PhysicsVector _newSpeed) { Vector3 _speed; _speed = BulletXMaths.PhysicsVectorToXnaVector3(_newSpeed); rigidBody.LinearVelocity = _speed; } - internal protected void ReOrient() + + protected internal void ReOrient() { - ReOrient(this._orientation); + ReOrient(_orientation); } - internal protected void ReOrient(AxiomQuaternion _newOrient) + + protected internal void ReOrient(AxiomQuaternion _newOrient) { Quaternion _newOrientation; _newOrientation = BulletXMaths.AxiomQuaternionToXnaQuaternion(_newOrient); @@ -949,17 +952,21 @@ namespace OpenSim.Region.Physics.BulletXPlugin BulletXMaths.SetRotation(ref _comTransform, _newOrientation); rigidBody.CenterOfMassTransform = _comTransform; } - internal protected void ReSize() + + protected internal void ReSize() { - ReSize(this._size); + ReSize(_size); } - internal protected virtual void ReSize(PhysicsVector _newSize) + + protected internal virtual void ReSize(PhysicsVector _newSize) { } + public virtual void ScheduleTerseUpdate() { base.RequestPhysicsterseUpdate(); } + #endregion } @@ -972,11 +979,13 @@ namespace OpenSim.Region.Physics.BulletXPlugin : this("", parent_scene, pos) { } + public BulletXCharacter(String avName, BulletXScene parent_scene, PhysicsVector pos) : this(avName, parent_scene, pos, new PhysicsVector(), new PhysicsVector(), new PhysicsVector(), AxiomQuaternion.Identity) { } + public BulletXCharacter(String avName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity, PhysicsVector size, PhysicsVector acceleration, AxiomQuaternion orientation) : base(avName) @@ -1026,45 +1035,54 @@ namespace OpenSim.Region.Physics.BulletXPlugin parent_scene.ddWorld.AddRigidBody(rigidBody); } } + public override int PhysicsActorType { - get { return (int)ActorTypes.Agent; } + get { return (int) ActorTypes.Agent; } set { return; } } + public override PhysicsVector Position { get { return base.Position; } set { base.Position = value; } } + public override PhysicsVector Velocity { get { return base.Velocity; } set { base.Velocity = value; } } + public override PhysicsVector Size { get { return base.Size; } set { base.Size = value; } } + public override PhysicsVector Acceleration { get { return base.Acceleration; } } + public override AxiomQuaternion Orientation { get { return base.Orientation; } set { base.Orientation = value; } } + public override bool Flying { get { return base.Flying; } set { base.Flying = value; } } + public override bool IsColliding { get { return base.IsColliding; } set { base.IsColliding = value; } } + public override bool Kinematic { get { return base.Kinematic; } @@ -1075,10 +1093,12 @@ namespace OpenSim.Region.Physics.BulletXPlugin { base.SetAcceleration(accel); } + public override void AddForce(PhysicsVector force) { base.AddForce(force); } + public override void SetMomentum(PhysicsVector momentum) { base.SetMomentum(momentum); @@ -1117,6 +1137,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin } rigidBody.LinearVelocity = vec; } + //This validation is very basic internal override void ValidateHeight(float heighmapPositionValue) { @@ -1131,6 +1152,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin Speed(new PhysicsVector(rigidBody.LinearVelocity.X, rigidBody.LinearVelocity.Y, 0.0f)); } } + internal override void UpdateKinetics() { _position = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.CenterOfMassPosition); @@ -1154,12 +1176,15 @@ namespace OpenSim.Region.Physics.BulletXPlugin public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector size, AxiomQuaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool isPhysical) - : this(primName, parent_scene, pos, new PhysicsVector(), size, new PhysicsVector(), rotation, mesh, pbs, isPhysical) + : this( + primName, parent_scene, pos, new PhysicsVector(), size, new PhysicsVector(), rotation, mesh, pbs, + isPhysical) { } + public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity, PhysicsVector size, - PhysicsVector acceleration, AxiomQuaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, + PhysicsVector acceleration, AxiomQuaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool isPhysical) : base(primName) { @@ -1177,27 +1202,28 @@ namespace OpenSim.Region.Physics.BulletXPlugin CreateRigidBody(parent_scene, mesh, pos, size); } + public override int PhysicsActorType { - get { return (int)ActorTypes.Prim; } + get { return (int) ActorTypes.Prim; } set { return; } } + public override PhysicsVector Position { get { return base.Position; } set { base.Position = value; } } + public override PhysicsVector Velocity { get { return base.Velocity; } set { base.Velocity = value; } } + public override PhysicsVector Size { - get - { - return _size; - } + get { return _size; } set { lock (BulletXScene.BulletXLock) @@ -1207,29 +1233,30 @@ namespace OpenSim.Region.Physics.BulletXPlugin } } } + public override PhysicsVector Acceleration { get { return base.Acceleration; } } + public override AxiomQuaternion Orientation { get { return base.Orientation; } set { base.Orientation = value; } } + public override float ActorMass { get { //For now all prims are boxes - return (_physical ? 1 : 0) * _density * _size.X * _size.Y * _size.Z; + return (_physical ? 1 : 0)*_density*_size.X*_size.Y*_size.Z; } } + public override bool IsPhysical { - get - { - return base.IsPhysical; - } + get { return base.IsPhysical; } set { base.IsPhysical = value; @@ -1238,27 +1265,30 @@ namespace OpenSim.Region.Physics.BulletXPlugin //--- PhysicsPluginManager.PhysicsPluginMessage("Physical - Recreate", true); //--- - ReCreateRigidBody(this._size); + ReCreateRigidBody(_size); } else { //--- PhysicsPluginManager.PhysicsPluginMessage("Physical - SetMassProps", true); //--- - this.rigidBody.SetMassProps(Mass, new Vector3()); + rigidBody.SetMassProps(Mass, new Vector3()); } } } + public override bool Flying { get { return base.Flying; } set { base.Flying = value; } } + public override bool IsColliding { get { return base.IsColliding; } set { base.IsColliding = value; } } + public override bool Kinematic { get { return base.Kinematic; } @@ -1272,10 +1302,12 @@ namespace OpenSim.Region.Physics.BulletXPlugin _acceleration = accel; } } + public override void AddForce(PhysicsVector force) { base.AddForce(force); } + public override void SetMomentum(PhysicsVector momentum) { base.SetMomentum(momentum); @@ -1296,6 +1328,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin Speed(new PhysicsVector(rigidBody.LinearVelocity.X, rigidBody.LinearVelocity.Y, 0.0f)); } } + internal override void UpdateKinetics() { if (_physical) //Updates properties. Prim updates its properties physically @@ -1320,7 +1353,6 @@ namespace OpenSim.Region.Physics.BulletXPlugin { m_lastUpdateSent = false; base.ScheduleTerseUpdate(); - } m_prev_position = _position; } @@ -1333,7 +1365,9 @@ namespace OpenSim.Region.Physics.BulletXPlugin } #region Methods for updating values of RigidBody - internal protected void CreateRigidBody(BulletXScene parent_scene, IMesh mesh, PhysicsVector pos, PhysicsVector size) + + protected internal void CreateRigidBody(BulletXScene parent_scene, IMesh mesh, PhysicsVector pos, + PhysicsVector size) { //For RigidBody Constructor. The next values might change float _linearDamping = 0.0f; @@ -1349,27 +1383,31 @@ namespace OpenSim.Region.Physics.BulletXPlugin CollisionShape _collisionShape; if (mesh == null) { - _collisionShape = new XnaDevRu.BulletX.BoxShape(BulletXMaths.PhysicsVectorToXnaVector3(size) / 2.0f); - } else { + _collisionShape = new BoxShape(BulletXMaths.PhysicsVectorToXnaVector3(size)/2.0f); + } + else + { int iVertexCount = mesh.getVertexList().Count; int[] indices = mesh.getIndexListAsInt(); Vector3[] v3Vertices = new Vector3[iVertexCount]; for (int i = 0; i < iVertexCount; i++) { - PhysicsVector v=mesh.getVertexList()[i]; + PhysicsVector v = mesh.getVertexList()[i]; if (v != null) // Note, null has special meaning. See meshing code for details v3Vertices[i] = BulletXMaths.PhysicsVectorToXnaVector3(v); else - v3Vertices[i] = MonoXnaCompactMaths.Vector3.Zero; + v3Vertices[i] = Vector3.Zero; } TriangleIndexVertexArray triMesh = new TriangleIndexVertexArray(indices, v3Vertices); - _collisionShape = new XnaDevRu.BulletX.TriangleMeshShape(triMesh); + _collisionShape = new TriangleMeshShape(triMesh); } DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset); Vector3 _localInertia = new Vector3(); if (_physical) _collisionShape.CalculateLocalInertia(Mass, out _localInertia); //Always when mass > 0 - rigidBody = new RigidBody(Mass, _motionState, _collisionShape, _localInertia, _linearDamping, _angularDamping, _friction, _restitution); + rigidBody = + new RigidBody(Mass, _motionState, _collisionShape, _localInertia, _linearDamping, _angularDamping, + _friction, _restitution); //rigidBody.ActivationState = ActivationState.DisableDeactivation; //It's seems that there are a bug with rigidBody constructor and its CenterOfMassPosition Vector3 _vDebugTranslation; @@ -1379,30 +1417,34 @@ namespace OpenSim.Region.Physics.BulletXPlugin parent_scene.ddWorld.AddRigidBody(rigidBody); } } - internal protected void ReCreateRigidBody(PhysicsVector size) + + protected internal void ReCreateRigidBody(PhysicsVector size) { //There is a bug when trying to remove a rigidBody that is colliding with something.. try { - this._parent_scene.ddWorld.RemoveRigidBody(rigidBody); + _parent_scene.ddWorld.RemoveRigidBody(rigidBody); } catch (Exception ex) { - this._parent_scene.BulletXMessage(this._parent_scene.is_ex_message + ex.Message, true); + _parent_scene.BulletXMessage(_parent_scene.is_ex_message + ex.Message, true); rigidBody.ActivationState = ActivationState.DisableSimulation; - this._parent_scene.AddForgottenRigidBody(rigidBody); + _parent_scene.AddForgottenRigidBody(rigidBody); } - CreateRigidBody(this._parent_scene, null, this._position, size); // Note, null for the meshing definitely is wrong. It's here for the moment to apease the compiler - if (_physical) Speed();//Static objects don't have linear velocity + CreateRigidBody(_parent_scene, null, _position, size); + // Note, null for the meshing definitely is wrong. It's here for the moment to apease the compiler + if (_physical) Speed(); //Static objects don't have linear velocity ReOrient(); GC.Collect(); } - internal protected override void ReSize(PhysicsVector _newSize) + + protected internal override void ReSize(PhysicsVector _newSize) { //I wonder to know how to resize with a simple instruction in BulletX. It seems that for now there isn't //so i have to do it manually. That's recreating rigidbody ReCreateRigidBody(_newSize); } + #endregion } @@ -1486,4 +1528,4 @@ namespace OpenSim.Region.Physics.BulletXPlugin return height; } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/BulletXPlugin/TriangleIndexVertexArray.cs b/OpenSim/Region/Physics/BulletXPlugin/TriangleIndexVertexArray.cs index 4f63687..e73c953 100644 --- a/OpenSim/Region/Physics/BulletXPlugin/TriangleIndexVertexArray.cs +++ b/OpenSim/Region/Physics/BulletXPlugin/TriangleIndexVertexArray.cs @@ -34,8 +34,8 @@ */ using System; using System.Collections.Generic; -using System.Text; using MonoXnaCompactMaths; +using XnaDevRu.BulletX; namespace OpenSim.Region.Physics.BulletXPlugin { @@ -52,7 +52,8 @@ namespace OpenSim.Region.Physics.BulletXPlugin private Vector3[] _vertexBase; private int _vertexStride; - public IndexedMesh(int numTriangleIndices, int[] triangleIndexBase, int triangleIndexStride, int numVertices, Vector3[] vertexBase, int vertexStride) + public IndexedMesh(int numTriangleIndices, int[] triangleIndexBase, int triangleIndexStride, int numVertices, + Vector3[] vertexBase, int vertexStride) { _numTriangles = numTriangleIndices; _triangleIndexBase = triangleIndexBase; @@ -72,25 +73,57 @@ namespace OpenSim.Region.Physics.BulletXPlugin _vertexStride = 24; } - public int TriangleCount { get { return _numTriangles; } set { _numTriangles = value; } } - public int[] TriangleIndexBase { get { return _triangleIndexBase; } set { _triangleIndexBase = value; } } - public int TriangleIndexStride { get { return _triangleIndexStride; } set { _triangleIndexStride = value; } } - public int VertexCount { get { return _numVertices; } set { _numVertices = value; } } - public Vector3[] VertexBase { get { return _vertexBase; } set { _vertexBase = value; } } - public int VertexStride { get { return _vertexStride; } set { _vertexStride = value; } } + public int TriangleCount + { + get { return _numTriangles; } + set { _numTriangles = value; } + } + + public int[] TriangleIndexBase + { + get { return _triangleIndexBase; } + set { _triangleIndexBase = value; } + } + + public int TriangleIndexStride + { + get { return _triangleIndexStride; } + set { _triangleIndexStride = value; } + } + + public int VertexCount + { + get { return _numVertices; } + set { _numVertices = value; } + } + + public Vector3[] VertexBase + { + get { return _vertexBase; } + set { _vertexBase = value; } + } + + public int VertexStride + { + get { return _vertexStride; } + set { _vertexStride = value; } + } } /// /// TriangleIndexVertexArray allows to use multiple meshes, by indexing into existing triangle/index arrays. /// Additional meshes can be added using addIndexedMesh /// - public class TriangleIndexVertexArray : XnaDevRu.BulletX.StridingMeshInterface + public class TriangleIndexVertexArray : StridingMeshInterface { - List _indexedMeshes = new List(); + private List _indexedMeshes = new List(); - public TriangleIndexVertexArray() { } + public TriangleIndexVertexArray() + { + } - public TriangleIndexVertexArray(int numTriangleIndices, int[] triangleIndexBase, int triangleIndexStride, int numVertices, Vector3[] vertexBase, int vertexStride) + public TriangleIndexVertexArray(int numTriangleIndices, int[] triangleIndexBase, int triangleIndexStride, + int numVertices, Vector3[] vertexBase, int vertexStride) { IndexedMesh mesh = new IndexedMesh(); mesh.TriangleCount = numTriangleIndices; @@ -104,19 +137,23 @@ namespace OpenSim.Region.Physics.BulletXPlugin } public TriangleIndexVertexArray(int[] triangleIndexBase, Vector3[] vertexBase) - : this(triangleIndexBase.Length, triangleIndexBase, 32, vertexBase.Length, vertexBase, 24) { } + : this(triangleIndexBase.Length, triangleIndexBase, 32, vertexBase.Length, vertexBase, 24) + { + } public void AddIndexedMesh(IndexedMesh indexedMesh) { _indexedMeshes.Add(indexedMesh); } - public override void GetLockedVertexIndexBase(out List verts, out List indicies, out int numfaces, int subpart) + public override void GetLockedVertexIndexBase(out List verts, out List indicies, out int numfaces, + int subpart) { throw new Exception("The method or operation is not implemented."); } - public override void GetLockedReadOnlyVertexIndexBase(out List verts, out List indicies, out int numfaces, int subpart) + public override void GetLockedReadOnlyVertexIndexBase(out List verts, out List indicies, + out int numfaces, int subpart) { IndexedMesh m = _indexedMeshes[0]; Vector3[] vertexBase = m.VertexBase; @@ -158,4 +195,4 @@ namespace OpenSim.Region.Physics.BulletXPlugin throw new Exception("The method or operation is not implemented."); } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/Manager/AssemblyInfo.cs b/OpenSim/Region/Physics/Manager/AssemblyInfo.cs index 3d95d6d..983a2b9 100644 --- a/OpenSim/Region/Physics/Manager/AssemblyInfo.cs +++ b/OpenSim/Region/Physics/Manager/AssemblyInfo.cs @@ -55,4 +55,4 @@ using System.Runtime.InteropServices; // You can specify all values by your own or you can build default build and revision // numbers with the '*' character (the default): -[assembly : AssemblyVersion("1.0.*")] +[assembly : AssemblyVersion("1.0.*")] \ No newline at end of file diff --git a/OpenSim/Region/Physics/Manager/IMesher.cs b/OpenSim/Region/Physics/Manager/IMesher.cs index 1648a98..80b3320 100644 --- a/OpenSim/Region/Physics/Manager/IMesher.cs +++ b/OpenSim/Region/Physics/Manager/IMesher.cs @@ -28,8 +28,6 @@ using System; using System.Collections.Generic; -using System.Text; - using OpenSim.Framework; namespace OpenSim.Region.Physics.Manager @@ -39,7 +37,8 @@ namespace OpenSim.Region.Physics.Manager IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size); } - public interface IVertex { + public interface IVertex + { } public interface IMesh @@ -48,7 +47,5 @@ namespace OpenSim.Region.Physics.Manager int[] getIndexListAsInt(); int[] getIndexListAsIntLocked(); float[] getVertexListAsFloatLocked(); - - } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/Manager/PhysicsActor.cs b/OpenSim/Region/Physics/Manager/PhysicsActor.cs index 5894ab0..d393b62 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsActor.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsActor.cs @@ -25,10 +25,10 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ -using Axiom.Math; -using OpenSim.Framework; using System; using System.Collections.Generic; +using Axiom.Math; +using OpenSim.Framework; namespace OpenSim.Region.Physics.Manager { @@ -37,14 +37,16 @@ namespace OpenSim.Region.Physics.Manager public delegate void VelocityUpdate(PhysicsVector velocity); public delegate void OrientationUpdate(Quaternion orientation); + public enum ActorTypes : int { Unknown = 0, Agent = 1, - Prim = 2, + Prim = 2, Ground = 3 } - public class CollisionEventUpdate : EventArgs + + public class CollisionEventUpdate : EventArgs { // Raising the event on the object, so don't need to provide location.. further up the tree knows that info. @@ -53,52 +55,53 @@ namespace OpenSim.Region.Physics.Manager public bool m_startOrEnd; //public uint m_LocalID; public List m_objCollisionList; + public CollisionEventUpdate(uint localID, int colliderType, bool startOrEnd, List objCollisionList) { m_colliderType = colliderType; m_startOrEnd = startOrEnd; m_objCollisionList = objCollisionList; - } - public CollisionEventUpdate(bool startOrEnd){ - m_colliderType = (int)ActorTypes.Unknown; + + public CollisionEventUpdate(bool startOrEnd) + { + m_colliderType = (int) ActorTypes.Unknown; m_startOrEnd = startOrEnd; m_objCollisionList = null; } - public CollisionEventUpdate() { - m_colliderType = (int)ActorTypes.Unknown; + + public CollisionEventUpdate() + { + m_colliderType = (int) ActorTypes.Unknown; m_startOrEnd = false; m_objCollisionList = null; } - public int collidertype{ - get { - return m_colliderType; - } - set { - m_colliderType = value; - } + + public int collidertype + { + get { return m_colliderType; } + set { m_colliderType = value; } } - public bool startOrEnd { - get { - return m_startOrEnd; - } - set { - m_startOrEnd = value; - } + + public bool startOrEnd + { + get { return m_startOrEnd; } + set { m_startOrEnd = value; } } - public void addCollider(uint localID) { + + public void addCollider(uint localID) + { m_objCollisionList.Add(localID); } } - - - public abstract class PhysicsActor - { + { public delegate void RequestTerseUpdate(); + public delegate void CollisionUpdate(EventArgs e); + public delegate void OutOfBounds(PhysicsVector pos); #pragma warning disable 67 @@ -117,10 +120,8 @@ namespace OpenSim.Region.Physics.Manager public abstract PhysicsVector Size { get; set; } - public abstract PrimitiveBaseShape Shape - { - set; - } + public abstract PrimitiveBaseShape Shape { set; } + public virtual void RequestPhysicsterseUpdate() { // Make a temporary copy of the event to avoid possibility of @@ -131,8 +132,8 @@ namespace OpenSim.Region.Physics.Manager { OnRequestTerseUpdate(); } - } + public virtual void RaiseOutOfBounds(PhysicsVector pos) { // Make a temporary copy of the event to avoid possibility of @@ -143,8 +144,8 @@ namespace OpenSim.Region.Physics.Manager { OnOutOfBounds(pos); } - } + public virtual void SendCollisionUpdate(EventArgs e) { CollisionUpdate handler = OnCollisionUpdate; @@ -159,7 +160,7 @@ namespace OpenSim.Region.Physics.Manager public abstract float Mass { get; } - public abstract PhysicsVector Force { get;} + public abstract PhysicsVector Force { get; } public abstract PhysicsVector GeometricCenter { get; } @@ -172,7 +173,7 @@ namespace OpenSim.Region.Physics.Manager public abstract Quaternion Orientation { get; set; } public abstract int PhysicsActorType { get; set; } - public abstract bool IsPhysical {get; set;} + public abstract bool IsPhysical { get; set; } public abstract bool Flying { get; set; } public abstract bool SetAlwaysRun { get; set; } @@ -198,48 +199,54 @@ namespace OpenSim.Region.Physics.Manager get { return PhysicsVector.Zero; } set { return; } } + public override bool SetAlwaysRun { get { return false; } set { return; } } + public override bool CollidingGround { - get {return false;} - set {return;} + get { return false; } + set { return; } } - public override bool CollidingObj + + public override bool CollidingObj { get { return false; } set { return; } } + public override PhysicsVector Size { get { return PhysicsVector.Zero; } set { return; } } + public override float Mass { get { return 0f; } } + public override PhysicsVector Force { get { return PhysicsVector.Zero; } } + public override PhysicsVector CenterOfMass { get { return PhysicsVector.Zero; } } + public override PhysicsVector GeometricCenter { get { return PhysicsVector.Zero; } } + public override PrimitiveBaseShape Shape { - set - { - return; - } + set { return; } } public override PhysicsVector Velocity @@ -270,6 +277,7 @@ namespace OpenSim.Region.Physics.Manager get { return false; } set { return; } } + public override bool ThrottleUpdates { get { return false; } @@ -281,9 +289,10 @@ namespace OpenSim.Region.Physics.Manager get { return false; } set { return; } } + public override int PhysicsActorType { - get { return (int)ActorTypes.Unknown; } + get { return (int) ActorTypes.Unknown; } set { return; } } @@ -297,14 +306,16 @@ namespace OpenSim.Region.Physics.Manager { return; } + public override PhysicsVector RotationalVelocity { get { return PhysicsVector.Zero; } set { return; } } + public override void SetMomentum(PhysicsVector momentum) { return; } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs b/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs index badcc04..a4ac54f 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs @@ -30,7 +30,6 @@ using System.Collections.Generic; using System.IO; using System.Reflection; using OpenSim.Framework.Console; -using Nini.Config; namespace OpenSim.Region.Physics.Manager { @@ -91,7 +90,7 @@ namespace OpenSim.Region.Physics.Manager plugHard = new ZeroMesherPlugin(); _MeshPlugins.Add(plugHard.GetName(), plugHard); MainLog.Instance.Verbose("PHYSICS", "Added meshing engine: " + plugHard.GetName()); - + // And now walk all assemblies (DLLs effectively) and see if they are home // of a plugin that is of interest for us string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Physics"); @@ -129,7 +128,7 @@ namespace OpenSim.Region.Physics.Manager if (meshTypeInterface != null) { IMeshingPlugin plug = - (IMeshingPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); + (IMeshingPlugin) Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); _MeshPlugins.Add(plug.GetName(), plug); MainLog.Instance.Verbose("PHYSICS", "Added meshing engine: " + plug.GetName()); } @@ -155,6 +154,7 @@ namespace OpenSim.Region.Physics.Manager MainLog.Instance.Verbose("PHYSICS", message); } } + //--- } @@ -171,4 +171,4 @@ namespace OpenSim.Region.Physics.Manager string GetName(); IMesher GetMesher(); } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/Manager/PhysicsScene.cs b/OpenSim/Region/Physics/Manager/PhysicsScene.cs index c63a66d..37481f1 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsScene.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsScene.cs @@ -28,7 +28,6 @@ using Axiom.Math; using OpenSim.Framework; using OpenSim.Framework.Console; -using OpenSim.Region.Physics.Manager; namespace OpenSim.Region.Physics.Manager { @@ -45,6 +44,7 @@ namespace OpenSim.Region.Physics.Manager { get { return new NullPhysicsScene(); } } + public virtual void TriggerPhysicsBasedRestart() { physicsCrash handler = OnPhysicsCrash; @@ -52,9 +52,8 @@ namespace OpenSim.Region.Physics.Manager { OnPhysicsCrash(); } - } - + public abstract void Initialise(IMesher meshmerizer); @@ -68,6 +67,7 @@ namespace OpenSim.Region.Physics.Manager PhysicsVector size, Quaternion rotation); //To be removed public abstract PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation, bool isPhysical); + public abstract void AddPhysicsActorTaint(PhysicsActor prim); public abstract float Simulate(float timeStep); @@ -111,21 +111,24 @@ namespace OpenSim.Region.Physics.Manager return PhysicsActor.Null; } */ + public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation) //To be removed { - return this.AddPrimShape(primName, pbs, position, size, rotation, false); + return AddPrimShape(primName, pbs, position, size, rotation, false); } + public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation, bool isPhysical) { MainLog.Instance.Verbose("PHYSICS", "NullPhysicsScene : AddPrim({0},{1})", position, size); return PhysicsActor.Null; } + public override void AddPhysicsActorTaint(PhysicsActor prim) { - } + public override float Simulate(float timeStep) { m_workIndicator = (m_workIndicator + 1)%10; @@ -154,4 +157,4 @@ namespace OpenSim.Region.Physics.Manager } } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/Manager/PhysicsVector.cs b/OpenSim/Region/Physics/Manager/PhysicsVector.cs index be82fca..1f5d0dc 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsVector.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsVector.cs @@ -28,7 +28,6 @@ using System; - namespace OpenSim.Region.Physics.Manager { public class PhysicsVector @@ -68,27 +67,27 @@ namespace OpenSim.Region.Physics.Manager public static PhysicsVector cross(PhysicsVector a, PhysicsVector b) { - return new PhysicsVector(a.Y * b.Z - a.Z * b.Y, a.Z * b.X - a.X * b.Z, a.X * b.Y - a.Y * b.X); + return new PhysicsVector(a.Y*b.Z - a.Z*b.Y, a.Z*b.X - a.X*b.Z, a.X*b.Y - a.Y*b.X); } public float length() { - return (float)Math.Sqrt(X*X + Y*Y + Z*Z); + return (float) Math.Sqrt(X*X + Y*Y + Z*Z); } - public static PhysicsVector operator / (PhysicsVector v, float f) + public static PhysicsVector operator /(PhysicsVector v, float f) { - return new PhysicsVector(v.X / f, v.Y / f, v.Z / f); + return new PhysicsVector(v.X/f, v.Y/f, v.Z/f); } public static PhysicsVector operator *(PhysicsVector v, float f) { - return new PhysicsVector(v.X * f, v.Y * f, v.Z * f); + return new PhysicsVector(v.X*f, v.Y*f, v.Z*f); } public static PhysicsVector operator *(float f, PhysicsVector v) { - return v * f; + return v*f; } public virtual bool IsIdentical(PhysicsVector v, float tolerance) @@ -101,4 +100,4 @@ namespace OpenSim.Region.Physics.Manager return false; } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/Manager/ZeroMesher.cs b/OpenSim/Region/Physics/Manager/ZeroMesher.cs index a88656e..7dae4ac 100644 --- a/OpenSim/Region/Physics/Manager/ZeroMesher.cs +++ b/OpenSim/Region/Physics/Manager/ZeroMesher.cs @@ -27,11 +27,8 @@ */ using System; -using System.Collections.Generic; -using System.Text; using OpenSim.Framework; - /* * This is the zero mesher. * Whatever you want him to mesh, he can't, telling you that by responding with a null pointer. @@ -62,13 +59,11 @@ namespace OpenSim.Region.Physics.Manager } } - public class ZeroMesher: IMesher + public class ZeroMesher : IMesher { - public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size) { return null; } } - -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/Meshing/Extruder.cs b/OpenSim/Region/Physics/Meshing/Extruder.cs index eecac5a..7ef5b5b 100644 --- a/OpenSim/Region/Physics/Meshing/Extruder.cs +++ b/OpenSim/Region/Physics/Meshing/Extruder.cs @@ -26,24 +26,22 @@ * */ -using System; -using System.Collections.Generic; -using System.Text; +using OpenSim.Region.Physics.Manager; namespace OpenSim.Region.Physics.Meshing { - class Extruder + internal class Extruder { public float startParameter; public float stopParameter; - public Manager.PhysicsVector size; + public PhysicsVector size; public Mesh Extrude(Mesh m) { // Currently only works for iSteps=1; Mesh result = new Mesh(); - Mesh workingPlus = m.Clone(); + Mesh workingPlus = m.Clone(); Mesh workingMinus = m.Clone(); foreach (Vertex v in workingPlus.vertices) @@ -80,14 +78,14 @@ namespace OpenSim.Region.Physics.Meshing for (int i = 0; i < workingPlus.vertices.Count; i++) { int iNext = (i + 1); - + if (workingPlus.vertices[i] == null) // Can't make a simplex here { - iLastNull = i+1; + iLastNull = i + 1; continue; } - if (i == workingPlus.vertices.Count-1) // End of list + if (i == workingPlus.vertices.Count - 1) // End of list { iNext = iLastNull; } @@ -101,11 +99,12 @@ namespace OpenSim.Region.Physics.Meshing tSide = new Triangle(workingPlus.vertices[i], workingMinus.vertices[i], workingPlus.vertices[iNext]); result.Add(tSide); - tSide = new Triangle(workingPlus.vertices[iNext], workingMinus.vertices[i], workingMinus.vertices[iNext]); + tSide = + new Triangle(workingPlus.vertices[iNext], workingMinus.vertices[i], workingMinus.vertices[iNext]); result.Add(tSide); } return result; } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/Meshing/HelperTypes.cs b/OpenSim/Region/Physics/Meshing/HelperTypes.cs index be82c32..ac06614 100644 --- a/OpenSim/Region/Physics/Meshing/HelperTypes.cs +++ b/OpenSim/Region/Physics/Meshing/HelperTypes.cs @@ -30,9 +30,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; -using OpenSim.Framework.Console; using OpenSim.Region.Physics.Manager; - using OpenSim.Region.Physics.Meshing; public class Vertex : PhysicsVector, IComparable @@ -54,7 +52,7 @@ public class Vertex : PhysicsVector, IComparable public static Vertex FromAngle(double angle) { - return new Vertex((float)Math.Cos(angle), (float)Math.Sin(angle), 0.0f); + return new Vertex((float) Math.Cos(angle), (float) Math.Sin(angle), 0.0f); } @@ -101,6 +99,7 @@ public class Vertex : PhysicsVector, IComparable { return me.CompareTo(other) < 0; } + public String ToRaw() { // Why this stuff with the number formatter? @@ -117,7 +116,6 @@ public class Vertex : PhysicsVector, IComparable return s1; } - } public class Triangle @@ -283,7 +281,7 @@ public class Triangle float l = n.length(); // Normalized "normal" - n = n / l; + n = n/l; return n; } @@ -300,7 +298,7 @@ public class Triangle // debugging purposes public String ToStringRaw() { - String output = v1.ToRaw() + " " + v2.ToRaw() + " " +v3.ToRaw(); + String output = v1.ToRaw() + " " + v2.ToRaw() + " " + v3.ToRaw(); return output; } } \ No newline at end of file diff --git a/OpenSim/Region/Physics/Meshing/Mesh.cs b/OpenSim/Region/Physics/Meshing/Mesh.cs index 2ebfa1c..9c2667e 100644 --- a/OpenSim/Region/Physics/Meshing/Mesh.cs +++ b/OpenSim/Region/Physics/Meshing/Mesh.cs @@ -26,14 +26,11 @@ * */ + using System; -using System.IO; using System.Collections.Generic; -using System.Text; - +using System.IO; using System.Runtime.InteropServices; - - using OpenSim.Region.Physics.Manager; namespace OpenSim.Region.Physics.Meshing @@ -66,9 +63,9 @@ namespace OpenSim.Region.Physics.Meshing foreach (Triangle t in triangles) { int iV1, iV2, iV3; - iV1 = this.vertices.IndexOf(t.v1); - iV2 = this.vertices.IndexOf(t.v2); - iV3 = this.vertices.IndexOf(t.v3); + iV1 = vertices.IndexOf(t.v1); + iV2 = vertices.IndexOf(t.v2); + iV3 = vertices.IndexOf(t.v3); Triangle newT = new Triangle(result.vertices[iV1], result.vertices[iV2], result.vertices[iV3]); result.Add(newT); @@ -77,8 +74,7 @@ namespace OpenSim.Region.Physics.Meshing return result; } - - + public void Add(Triangle triangle) { int i; @@ -160,15 +156,15 @@ namespace OpenSim.Region.Physics.Meshing public float[] getVertexListAsFloatLocked() { - float[] result = new float[vertices.Count * 3]; + float[] result = new float[vertices.Count*3]; for (int i = 0; i < vertices.Count; i++) { Vertex v = vertices[i]; if (v == null) continue; - result[3 * i + 0] = v.X; - result[3 * i + 1] = v.Y; - result[3 * i + 2] = v.Z; + result[3*i + 0] = v.X; + result[3*i + 1] = v.Y; + result[3*i + 2] = v.Z; } GCHandle.Alloc(result, GCHandleType.Pinned); return result; @@ -176,13 +172,13 @@ namespace OpenSim.Region.Physics.Meshing public int[] getIndexListAsInt() { - int[] result = new int[triangles.Count * 3]; + int[] result = new int[triangles.Count*3]; for (int i = 0; i < triangles.Count; i++) { Triangle t = triangles[i]; - result[3 * i + 0] = vertices.IndexOf(t.v1); - result[3 * i + 1] = vertices.IndexOf(t.v2); - result[3 * i + 2] = vertices.IndexOf(t.v3); + result[3*i + 0] = vertices.IndexOf(t.v1); + result[3*i + 1] = vertices.IndexOf(t.v2); + result[3*i + 2] = vertices.IndexOf(t.v3); } return result; } @@ -202,7 +198,6 @@ namespace OpenSim.Region.Physics.Meshing foreach (Triangle t in newMesh.triangles) Add(t); - } // Do a linear transformation of mesh. @@ -213,9 +208,9 @@ namespace OpenSim.Region.Physics.Meshing if (v == null) continue; float x, y, z; - x = v.X * matrix[0, 0] + v.Y * matrix[1, 0] + v.Z * matrix[2, 0]; - y = v.X * matrix[0, 1] + v.Y * matrix[1, 1] + v.Z * matrix[2, 1]; - z = v.X * matrix[0, 2] + v.Y * matrix[1, 2] + v.Z * matrix[2, 2]; + x = v.X*matrix[0, 0] + v.Y*matrix[1, 0] + v.Z*matrix[2, 0]; + y = v.X*matrix[0, 1] + v.Y*matrix[1, 1] + v.Z*matrix[2, 1]; + z = v.X*matrix[0, 2] + v.Y*matrix[1, 2] + v.Z*matrix[2, 2]; v.X = x + offset[0]; v.Y = y + offset[1]; v.Z = z + offset[2]; @@ -237,5 +232,4 @@ namespace OpenSim.Region.Physics.Meshing sw.Close(); } } - -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index 9c35f81..3217dd8 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs @@ -27,18 +27,13 @@ */ using System; -using System.IO; -using System.Globalization; -using System.Diagnostics; using System.Collections.Generic; -using System.Runtime.InteropServices; using OpenSim.Framework; using OpenSim.Framework.Console; using OpenSim.Region.Physics.Manager; namespace OpenSim.Region.Physics.Meshing { - public class MeshmerizerPlugin : IMeshingPlugin { public MeshmerizerPlugin() @@ -61,10 +56,11 @@ namespace OpenSim.Region.Physics.Meshing // Setting baseDir to a path will enable the dumping of raw files // raw files can be imported by blender so a visual inspection of the results can be done // const string baseDir = "rawFiles"; - const string baseDir = null; + private const string baseDir = null; - static void IntersectionParameterPD(PhysicsVector p1, PhysicsVector r1, PhysicsVector p2, PhysicsVector r2, ref float lambda, ref float mu) - { + private static void IntersectionParameterPD(PhysicsVector p1, PhysicsVector r1, PhysicsVector p2, + PhysicsVector r2, ref float lambda, ref float mu) + { // p1, p2, points on the straight // r1, r2, directional vectors of the straight. Not necessarily of length 1! // note, that l, m can be scaled such, that the range 0..1 is mapped to the area between two points, @@ -88,9 +84,8 @@ namespace OpenSim.Region.Physics.Meshing float p1y = p1.Y; float p2x = p2.X; float p2y = p2.Y; - lambda = (-p2x * r2y + p1x * r2y + (p2y - p1y) * r2x) / denom; - mu = (-p2x * r1y + p1x * r1y + (p2y - p1y) * r1x) / denom; - + lambda = (-p2x*r2y + p1x*r2y + (p2y - p1y)*r2x)/denom; + mu = (-p2x*r1y + p1x*r1y + (p2y - p1y)*r1x)/denom; } private static List FindInfluencedTriangles(List triangles, Vertex v) @@ -105,8 +100,8 @@ namespace OpenSim.Region.Physics.Meshing } return influenced; } - - + + private static void InsertVertices(List vertices, int usedForSeed, List triangles) { // This is a variant of the delaunay algorithm @@ -126,10 +121,10 @@ namespace OpenSim.Region.Physics.Meshing // do not fulfill this condition with respect to the new triangle // Find the triangles that are influenced by the new vertex - Vertex v=vertices[iCurrentVertex]; + Vertex v = vertices[iCurrentVertex]; if (v == null) - continue; // Null is polygon stop marker. Ignore it - List influencedTriangles=FindInfluencedTriangles(triangles, v); + continue; // Null is polygon stop marker. Ignore it + List influencedTriangles = FindInfluencedTriangles(triangles, v); List simplices = new List(); @@ -177,12 +172,11 @@ namespace OpenSim.Region.Physics.Meshing } } } - } - - static Mesh CreateBoxMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size) - // Builds the z (+ and -) surfaces of a box shaped prim + + private static Mesh CreateBoxMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size) + // Builds the z (+ and -) surfaces of a box shaped prim { UInt16 hollowFactor = primShape.ProfileHollow; UInt16 profileBegin = primShape.ProfileBegin; @@ -201,7 +195,7 @@ namespace OpenSim.Region.Physics.Meshing Vertex MP = new Vertex(-0.5f, +0.5f, 0.0f); Vertex PP = new Vertex(+0.5f, +0.5f, 0.0f); - Meshing.SimpleHull outerHull = new SimpleHull(); + SimpleHull outerHull = new SimpleHull(); outerHull.AddVertex(MM); outerHull.AddVertex(PM); outerHull.AddVertex(PP); @@ -210,9 +204,10 @@ namespace OpenSim.Region.Physics.Meshing // Deal with cuts now if ((profileBegin != 0) || (profileEnd != 0)) { - double fProfileBeginAngle = profileBegin / 50000.0 * 360.0; // In degree, for easier debugging and understanding - fProfileBeginAngle -= (90.0 + 45.0); // for some reasons, the SL client counts from the corner -X/-Y - double fProfileEndAngle = 360.0 - profileEnd / 50000.0 * 360.0; // Pathend comes as complement to 1.0 + double fProfileBeginAngle = profileBegin/50000.0*360.0; + // In degree, for easier debugging and understanding + fProfileBeginAngle -= (90.0 + 45.0); // for some reasons, the SL client counts from the corner -X/-Y + double fProfileEndAngle = 360.0 - profileEnd/50000.0*360.0; // Pathend comes as complement to 1.0 fProfileEndAngle -= (90.0 + 45.0); if (fProfileBeginAngle < fProfileEndAngle) fProfileEndAngle -= 360.0; @@ -222,20 +217,23 @@ namespace OpenSim.Region.Physics.Meshing // and we approximate this arc by a polygon chain // Also note, that these vectors are of length 1.0 and thus their endpoints lay outside the model space // So it can easily be subtracted from the outer hull - int iSteps = (int)(((fProfileBeginAngle - fProfileEndAngle) / 45.0) + .5); // how many steps do we need with approximately 45 degree - double dStepWidth=(fProfileBeginAngle-fProfileEndAngle)/iSteps; + int iSteps = (int) (((fProfileBeginAngle - fProfileEndAngle)/45.0) + .5); + // how many steps do we need with approximately 45 degree + double dStepWidth = (fProfileBeginAngle - fProfileEndAngle)/iSteps; Vertex origin = new Vertex(0.0f, 0.0f, 0.0f); // Note the sequence of vertices here. It's important to have the other rotational sense than in outerHull SimpleHull cutHull = new SimpleHull(); cutHull.AddVertex(origin); - for (int i=0; i 0) { float hollowFactorF = (float) hollowFactor/(float) 50000; - Vertex IMM = new Vertex(-0.5f * hollowFactorF, -0.5f * hollowFactorF, 0.0f); - Vertex IPM = new Vertex(+0.5f * hollowFactorF, -0.5f * hollowFactorF, 0.0f); - Vertex IMP = new Vertex(-0.5f * hollowFactorF, +0.5f * hollowFactorF, 0.0f); - Vertex IPP = new Vertex(+0.5f * hollowFactorF, +0.5f * hollowFactorF, 0.0f); + Vertex IMM = new Vertex(-0.5f*hollowFactorF, -0.5f*hollowFactorF, 0.0f); + Vertex IPM = new Vertex(+0.5f*hollowFactorF, -0.5f*hollowFactorF, 0.0f); + Vertex IMP = new Vertex(-0.5f*hollowFactorF, +0.5f*hollowFactorF, 0.0f); + Vertex IPP = new Vertex(+0.5f*hollowFactorF, +0.5f*hollowFactorF, 0.0f); SimpleHull holeHull = new SimpleHull(); @@ -263,7 +261,6 @@ namespace OpenSim.Region.Physics.Meshing SimpleHull hollowedHull = SimpleHull.SubtractHull(outerHull, holeHull); outerHull = hollowedHull; - } Mesh m = new Mesh(); @@ -286,7 +283,7 @@ namespace OpenSim.Region.Physics.Meshing m.Remove(Seed2); m.Remove(Seed3); m.DumpRaw(baseDir, primName, "Proto seeds removed"); - + m.RemoveTrianglesOutside(outerHull); m.DumpRaw(baseDir, primName, "Proto outsides removed"); @@ -374,7 +371,7 @@ namespace OpenSim.Region.Physics.Meshing switch (primShape.ProfileShape) { case ProfileShape.Square: - mesh=CreateBoxMesh(primName, primShape, size); + mesh = CreateBoxMesh(primName, primShape, size); CalcNormals(mesh); break; default: @@ -389,5 +386,4 @@ namespace OpenSim.Region.Physics.Meshing return mesh; } } - -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/Meshing/SimpleHull.cs b/OpenSim/Region/Physics/Meshing/SimpleHull.cs index a769053..809f3d5 100644 --- a/OpenSim/Region/Physics/Meshing/SimpleHull.cs +++ b/OpenSim/Region/Physics/Meshing/SimpleHull.cs @@ -28,9 +28,8 @@ using System; using System.Collections.Generic; -using System.Text; - using OpenSim.Framework.Console; +using OpenSim.Region.Physics.Manager; namespace OpenSim.Region.Physics.Meshing { @@ -43,17 +42,18 @@ namespace OpenSim.Region.Physics.Meshing // is defined by the hull lies inside or outside the simplex chain public class SimpleHull { - List vertices = new List(); - List holeVertices = new List(); // Only used, when the hull is hollow + private List vertices = new List(); + private List holeVertices = new List(); // Only used, when the hull is hollow // Adds a vertex to the end of the list - public void AddVertex(Vertex v) { + public void AddVertex(Vertex v) + { vertices.Add(v); } - override public String ToString() + public override String ToString() { - String result=""; + String result = ""; foreach (Vertex v in vertices) { result += "b:" + v.ToString() + "\n"; @@ -63,7 +63,8 @@ namespace OpenSim.Region.Physics.Meshing } - public List getVertices() { + public List getVertices() + { List newVertices = new List(); newVertices.AddRange(vertices); @@ -81,27 +82,27 @@ namespace OpenSim.Region.Physics.Meshing result.AddVertex(v.Clone()); } - foreach (Vertex v in this.holeVertices) + foreach (Vertex v in holeVertices) { result.holeVertices.Add(v.Clone()); } - + return result; } public bool IsPointIn(Vertex v1) { - int iCounter=0; - List simplices=buildSimplexList(); + int iCounter = 0; + List simplices = buildSimplexList(); foreach (Simplex s in simplices) { // Send a ray along the positive X-Direction // Note, that this direction must correlate with the "below" interpretation // of handling for the special cases below - Manager.PhysicsVector intersection = s.RayIntersect(v1, new Manager.PhysicsVector(1.0f, 0.0f, 0.0f), true); + PhysicsVector intersection = s.RayIntersect(v1, new PhysicsVector(1.0f, 0.0f, 0.0f), true); if (intersection == null) - continue; // No intersection. Done. More tests to follow otherwise + continue; // No intersection. Done. More tests to follow otherwise // Did we hit the end of a simplex? // Then this can be one of two special cases: @@ -111,19 +112,21 @@ namespace OpenSim.Region.Physics.Meshing // Solution: If the other vertex is "below" the ray, we don't count it // Thus corners pointing down are counted twice, corners pointing up are not counted // borders are counted once - if (intersection.IsIdentical(s.v1, 0.001f)) { + if (intersection.IsIdentical(s.v1, 0.001f)) + { if (s.v2.Y < v1.Y) continue; } // Do this for the other vertex two - if (intersection.IsIdentical(s.v2, 0.001f)) { - if (s.v1.Y buildSimplexList() { - + private List buildSimplexList() + { List result = new List(); // Not asserted but assumed: at least three vertices - for (int i=0; i simple = buildSimplexList(); foreach (Simplex sTest in simple) { - Manager.PhysicsVector vvTemp = Simplex.Intersect(sTest, s, -.001f, -.001f, 0.999f, .999f); - - Vertex vTemp=null; + PhysicsVector vvTemp = Simplex.Intersect(sTest, s, -.001f, -.001f, 0.999f, .999f); + + Vertex vTemp = null; if (vvTemp != null) vTemp = new Vertex(vvTemp); - if (vTemp!=null) { - - Manager.PhysicsVector diff=(s.v1-vTemp); - float distTemp=diff.length(); + if (vTemp != null) + { + PhysicsVector diff = (s.v1 - vTemp); + float distTemp = diff.length(); - if (bestIntersection==null || distTemp many, many intersections + if (z1 == 0.0f) + { +// Means they are identical -> many, many intersections lambda = Single.NaN; mu = Single.NaN; - } else { + } + else + { lambda = Single.PositiveInfinity; mu = Single.PositiveInfinity; } return; - } - - lambda = z1 / denom; - mu = z2 / denom; - + lambda = z1/denom; + mu = z2/denom; } @@ -145,12 +144,12 @@ namespace OpenSim.Region.Physics.Meshing // upperBorder2 : 1.0 // Set these to values near the given parameters (e.g. 0.001 instead of 1 to exclude simplex starts safely, or to -0.001 to include them safely) public static PhysicsVector Intersect( - Simplex s1, - Simplex s2, - float lowerBorder1, - float lowerBorder2, - float upperBorder1, - float upperBorder2) + Simplex s1, + Simplex s2, + float lowerBorder1, + float lowerBorder2, + float upperBorder1, + float upperBorder2) { PhysicsVector firstSimplexDirection = s1.v2 - s1.v1; PhysicsVector secondSimplexDirection = s2.v2 - s2.v1; @@ -181,8 +180,7 @@ namespace OpenSim.Region.Physics.Meshing if (mu > upperBorder2) // outside simplex 2 return null; - return s1.v1 + lambda * firstSimplexDirection; - + return s1.v1 + lambda*firstSimplexDirection; } // Intersects the simplex with a ray. The ray is defined as all p=origin + lambda*direction @@ -212,15 +210,12 @@ namespace OpenSim.Region.Physics.Meshing return null; if (lambda == 1.0 && !bEndsIncluded) - return null; // The end of the simplices are not included + return null; // The end of the simplices are not included if (lambda < 0.0f) // we're before v1; return null; - return this.v1 + lambda * simplexDirection; - + return v1 + lambda*simplexDirection; } - - } } \ No newline at end of file diff --git a/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs index 1e5713b..1ea5458 100644 --- a/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs +++ b/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs @@ -55,4 +55,4 @@ using System.Runtime.InteropServices; // You can specify all values by your own or you can build default build and revision // numbers with the '*' character (the default): -[assembly : AssemblyVersion("1.0.*")] +[assembly : AssemblyVersion("1.0.*")] \ No newline at end of file diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index 9676db4..a118e7c 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -27,11 +27,9 @@ */ using System; -using System.Collections.Generic; using Axiom.Math; using Ode.NET; using OpenSim.Framework; -using OpenSim.Framework.Console; using OpenSim.Region.Physics.Manager; namespace OpenSim.Region.Physics.OdePlugin @@ -87,7 +85,9 @@ namespace OpenSim.Region.Physics.OdePlugin _acceleration = new PhysicsVector(); _parent_scene = parent_scene; - m_StandUpRotation = new d.Matrix3(0.8184158f, -0.5744568f, -0.0139677f, 0.5744615f, 0.8185215f, -0.004074608f, 0.01377355f, -0.004689182f, 0.9998941f); + m_StandUpRotation = + new d.Matrix3(0.8184158f, -0.5744568f, -0.0139677f, 0.5744615f, 0.8185215f, -0.004074608f, 0.01377355f, + -0.004689182f, 0.9998941f); for (int i = 0; i < 11; i++) { @@ -105,12 +105,9 @@ namespace OpenSim.Region.Physics.OdePlugin d.GeomSetBody(Shell, Body); - - d.BodySetRotation(Body, ref m_StandUpRotation); - //Amotor = d.JointCreateAMotor(parent_scene.world, IntPtr.Zero); //d.JointAttach(Amotor, Body, IntPtr.Zero); //d.JointSetAMotorMode(Amotor, dAMotorEuler); @@ -124,45 +121,47 @@ namespace OpenSim.Region.Physics.OdePlugin //d.JointSetAMotorParam(Amotor, 0, -0); //d.JointSetAMotorParam(Amotor, 0x200, -0); //d.JointSetAMotorParam(Amotor, 0x100, -0); - // d.JointSetAMotorParam(Amotor, 0, 0); - // d.JointSetAMotorParam(Amotor, 3, 0); - // d.JointSetAMotorParam(Amotor, 2, 0); - - - + // d.JointSetAMotorParam(Amotor, 0, 0); + // d.JointSetAMotorParam(Amotor, 3, 0); + // d.JointSetAMotorParam(Amotor, 2, 0); } m_name = avName; parent_scene.geom_name_map[Shell] = avName; - parent_scene.actor_name_map[Shell] = (PhysicsActor)this; + parent_scene.actor_name_map[Shell] = (PhysicsActor) this; } + public override int PhysicsActorType { - get { return (int)ActorTypes.Agent; } + get { return (int) ActorTypes.Agent; } set { return; } } + public override bool SetAlwaysRun { get { return m_alwaysRun; } set { m_alwaysRun = value; } } + public override bool IsPhysical { get { return false; } set { return; } } + public override bool ThrottleUpdates { get { return false; } set { return; } } + public override bool Flying { get { return flying; } set { flying = value; } } + public override bool IsColliding { - get { return m_iscolliding; } set { @@ -193,24 +192,22 @@ namespace OpenSim.Region.Physics.OdePlugin // Equal truecounts and false counts means we're colliding with something. - if (falsecount > 1.2 * truecount) + if (falsecount > 1.2*truecount) { m_iscolliding = false; } else { m_iscolliding = true; - - } if (m_wascolliding != m_iscolliding) { //base.SendCollisionUpdate(new CollisionEventUpdate()); - } m_wascolliding = m_iscolliding; } } + public override bool CollidingGround { get { return m_iscollidingGround; } @@ -243,7 +240,7 @@ namespace OpenSim.Region.Physics.OdePlugin // Equal truecounts and false counts means we're colliding with something. - if (falsecount > 1.2 * truecount) + if (falsecount > 1.2*truecount) { m_iscollidingGround = false; } @@ -258,10 +255,12 @@ namespace OpenSim.Region.Physics.OdePlugin m_wascollidingGround = m_iscollidingGround; } } + public override bool CollidingObj { get { return m_iscollidingObj; } - set { + set + { m_iscollidingObj = value; if (value) m_pidControllerActive = false; @@ -269,10 +268,12 @@ namespace OpenSim.Region.Physics.OdePlugin m_pidControllerActive = true; } } + public void SetPidStatus(bool status) { m_pidControllerActive = status; } + public override PhysicsVector Position { get { return _position; } @@ -285,14 +286,16 @@ namespace OpenSim.Region.Physics.OdePlugin } } } + public override PhysicsVector RotationalVelocity { get { return m_rotationalVelocity; } set { m_rotationalVelocity = value; } } + public override PhysicsVector Size { - get { return new PhysicsVector(CAPSULE_RADIUS * 2, CAPSULE_RADIUS * 2, CAPSULE_LENGTH); } + get { return new PhysicsVector(CAPSULE_RADIUS*2, CAPSULE_RADIUS*2, CAPSULE_LENGTH); } set { m_pidControllerActive = true; @@ -303,7 +306,7 @@ namespace OpenSim.Region.Physics.OdePlugin float capsuleradius = CAPSULE_RADIUS; capsuleradius = 0.2f; - CAPSULE_LENGTH = (SetSize.Z - ((SetSize.Z * 0.43f))); // subtract 43% of the size + CAPSULE_LENGTH = (SetSize.Z - ((SetSize.Z*0.43f))); // subtract 43% of the size d.BodyDestroy(Body); d.GeomDestroy(Shell); //MainLog.Instance.Verbose("PHYSICS", "Set Avatar Height To: " + (CAPSULE_RADIUS + CAPSULE_LENGTH)); @@ -311,25 +314,27 @@ namespace OpenSim.Region.Physics.OdePlugin d.MassSetCapsule(out ShellMass, m_density, 3, CAPSULE_RADIUS, CAPSULE_LENGTH); Body = d.BodyCreate(_parent_scene.world); d.BodySetMass(Body, ref ShellMass); - d.BodySetPosition(Body, _position.X, _position.Y, _position.Z + Math.Abs(CAPSULE_LENGTH - prevCapsule)); + d.BodySetPosition(Body, _position.X, _position.Y, + _position.Z + Math.Abs(CAPSULE_LENGTH - prevCapsule)); d.GeomSetBody(Shell, Body); } _parent_scene.geom_name_map[Shell] = m_name; - _parent_scene.actor_name_map[Shell] = (PhysicsActor)this; + _parent_scene.actor_name_map[Shell] = (PhysicsActor) this; } } + public override float Mass { - get { - - float AVvolume = (float)(Math.PI * Math.Pow(CAPSULE_RADIUS, 2) * CAPSULE_LENGTH); - return m_density * AVvolume; + get + { + float AVvolume = (float) (Math.PI*Math.Pow(CAPSULE_RADIUS, 2)*CAPSULE_LENGTH); + return m_density*AVvolume; } } public override PhysicsVector Force { - get { return new PhysicsVector(_target_velocity.X,_target_velocity.Y,_target_velocity.Z); } + get { return new PhysicsVector(_target_velocity.X, _target_velocity.Y, _target_velocity.Z); } } public override PhysicsVector CenterOfMass @@ -344,18 +349,17 @@ namespace OpenSim.Region.Physics.OdePlugin public override PrimitiveBaseShape Shape { - set - { - return; - } + set { return; } } public override PhysicsVector Velocity { get { return _velocity; } - set { + set + { m_pidControllerActive = true; - _target_velocity = value; } + _target_velocity = value; + } } public override bool Kinematic @@ -390,6 +394,7 @@ namespace OpenSim.Region.Physics.OdePlugin //m_lastUpdateSent = false; } + public void doForce(PhysicsVector force) { if (!collidelock) @@ -413,13 +418,11 @@ namespace OpenSim.Region.Physics.OdePlugin //d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, -servo, 0.0f, 0.0f, -1.0f); //m_lastUpdateSent = false; - } - } + public override void SetMomentum(PhysicsVector momentum) { - } public void Move(float timeStep) @@ -442,7 +445,6 @@ namespace OpenSim.Region.Physics.OdePlugin else { movementdivisor = 0.8f; - } // if velocity is zero, use position control; otherwise, velocity control @@ -457,11 +459,11 @@ namespace OpenSim.Region.Physics.OdePlugin if (m_pidControllerActive) { d.Vector3 pos = d.BodyGetPosition(Body); - vec.X = (_target_velocity.X - vel.X) * PID_D + (_zeroPosition.X - pos.X) * PID_P; - vec.Y = (_target_velocity.Y - vel.Y) * PID_D + (_zeroPosition.Y - pos.Y) * PID_P; + vec.X = (_target_velocity.X - vel.X)*PID_D + (_zeroPosition.X - pos.X)*PID_P; + vec.Y = (_target_velocity.Y - vel.Y)*PID_D + (_zeroPosition.Y - pos.Y)*PID_P; if (flying) { - vec.Z = (_target_velocity.Z - vel.Z) * (PID_D + 5100) + (_zeroPosition.Z - pos.Z) * PID_P; + vec.Z = (_target_velocity.Z - vel.Z)*(PID_D + 5100) + (_zeroPosition.Z - pos.Z)*PID_P; } } //PidStatus = true; @@ -472,21 +474,20 @@ namespace OpenSim.Region.Physics.OdePlugin _zeroFlag = false; if (m_iscolliding || flying) { - - vec.X = ((_target_velocity.X / movementdivisor) - vel.X) * PID_D; - vec.Y = ((_target_velocity.Y / movementdivisor) - vel.Y) * PID_D; + vec.X = ((_target_velocity.X/movementdivisor) - vel.X)*PID_D; + vec.Y = ((_target_velocity.Y/movementdivisor) - vel.Y)*PID_D; } if (m_iscolliding && !flying && _target_velocity.Z > 0.0f) { d.Vector3 pos = d.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; if (_target_velocity.X > 0) { - vec.X = ((_target_velocity.X - vel.X) / 1.2f) * PID_D; + vec.X = ((_target_velocity.X - vel.X)/1.2f)*PID_D; } if (_target_velocity.Y > 0) { - vec.Y = ((_target_velocity.Y - vel.Y) / 1.2f) * PID_D; + vec.Y = ((_target_velocity.Y - vel.Y)/1.2f)*PID_D; } } else if (!m_iscolliding && !flying) @@ -494,19 +495,18 @@ namespace OpenSim.Region.Physics.OdePlugin d.Vector3 pos = d.BodyGetPosition(Body); if (_target_velocity.X > 0) { - vec.X = ((_target_velocity.X - vel.X) / 1.2f) * PID_D; + vec.X = ((_target_velocity.X - vel.X)/1.2f)*PID_D; } if (_target_velocity.Y > 0) { - vec.Y = ((_target_velocity.Y - vel.Y) / 1.2f) * PID_D; + vec.Y = ((_target_velocity.Y - vel.Y)/1.2f)*PID_D; } - } if (flying) { - vec.Z = (_target_velocity.Z - vel.Z) * (PID_D + 5100); + vec.Z = (_target_velocity.Z - vel.Z)*(PID_D + 5100); } } if (flying) @@ -546,13 +546,12 @@ namespace OpenSim.Region.Physics.OdePlugin int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position); //if (primScenAvatarIn == "0") //{ - //MainLog.Instance.Verbose("Physics", "Avatar " + m_name + " in space with no prim. Arr:':" + arrayitem[0].ToString() + "," + arrayitem[1].ToString()); + //MainLog.Instance.Verbose("Physics", "Avatar " + m_name + " in space with no prim. Arr:':" + arrayitem[0].ToString() + "," + arrayitem[1].ToString()); //} //else //{ // MainLog.Instance.Verbose("Physics", "Avatar " + m_name + " in Prim space':" + primScenAvatarIn + ". Arr:" + arrayitem[0].ToString() + "," + arrayitem[1].ToString()); //} - } } else @@ -586,12 +585,11 @@ namespace OpenSim.Region.Physics.OdePlugin { lock (OdeScene.OdeLock) { - // d.JointDestroy(Amotor); + // d.JointDestroy(Amotor); d.GeomDestroy(Shell); _parent_scene.geom_name_map.Remove(Shell); d.BodyDestroy(Body); } } } - -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 35328b8..5fef47d 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -27,16 +27,13 @@ */ using System; -using System.Collections.Generic; using Axiom.Math; using Ode.NET; using OpenSim.Framework; -using OpenSim.Framework.Console; using OpenSim.Region.Physics.Manager; namespace OpenSim.Region.Physics.OdePlugin { - public class OdePrim : PhysicsActor { public PhysicsVector _position; @@ -57,7 +54,7 @@ namespace OpenSim.Region.Physics.OdePlugin private IMesh _mesh; private PrimitiveBaseShape _pbs; private OdeScene _parent_scene; - public IntPtr m_targetSpace = (IntPtr)0; + public IntPtr m_targetSpace = (IntPtr) 0; public IntPtr prim_geom; public IntPtr _triMeshData; private bool iscolliding = false; @@ -65,18 +62,17 @@ namespace OpenSim.Region.Physics.OdePlugin private bool m_throttleUpdates = false; private int throttleCounter = 0; public bool outofBounds = false; - private float m_density = 10.000006836f;// Aluminum g/cm3; + private float m_density = 10.000006836f; // Aluminum g/cm3; - public bool _zeroFlag = false; private bool m_lastUpdateSent = false; - public IntPtr Body = (IntPtr)0; + public IntPtr Body = (IntPtr) 0; private String m_primName; private PhysicsVector _target_velocity; public d.Mass pMass; - + private int debugcounter = 0; public OdePrim(String primName, OdeScene parent_scene, IntPtr targetSpace, PhysicsVector pos, PhysicsVector size, @@ -123,7 +119,6 @@ namespace OpenSim.Region.Physics.OdePlugin // linksets *should* be in a space together.. but are not currently if (m_isphysical) m_targetSpace = _parent_scene.space; - } m_primName = primName; @@ -147,25 +142,28 @@ namespace OpenSim.Region.Physics.OdePlugin d.GeomSetQuaternion(prim_geom, ref myrot); - if (m_isphysical && Body == (IntPtr)0) + if (m_isphysical && Body == (IntPtr) 0) { enableBody(); } parent_scene.geom_name_map[prim_geom] = primName; - parent_scene.actor_name_map[prim_geom] = (PhysicsActor)this; + parent_scene.actor_name_map[prim_geom] = (PhysicsActor) this; // don't do .add() here; old geoms get recycled with the same hash } } + public override int PhysicsActorType { - get { return (int)ActorTypes.Prim; } + get { return (int) ActorTypes.Prim; } set { return; } } + public override bool SetAlwaysRun { get { return false; } set { return; } } + public void enableBody() { // Sets the geom to a body @@ -185,13 +183,14 @@ namespace OpenSim.Region.Physics.OdePlugin _parent_scene.addActivePrim(this); } + private float CalculateMass() { float volume = 0; - + // No material is passed to the physics engines yet.. soo.. // we're using the m_density constant in the class definition - + float returnMass = 0; @@ -199,17 +198,17 @@ namespace OpenSim.Region.Physics.OdePlugin { case ProfileShape.Square: // Profile Volume - - volume = _size.X * _size.Y * _size.Z; + + volume = _size.X*_size.Y*_size.Z; // If the user has 'hollowed out' // ProfileHollow is one of those 0 to 50000 values :P // we like percentages better.. so turning into a percentage - if (((float)_pbs.ProfileHollow / 50000f) > 0.0) + if (((float) _pbs.ProfileHollow/50000f) > 0.0) { - float hollowAmount = (float)_pbs.ProfileHollow / 50000f; - + float hollowAmount = (float) _pbs.ProfileHollow/50000f; + // calculate the hollow volume by it's shape compared to the prim shape float hollowVolume = 0; switch (_pbs.HollowShape) @@ -217,29 +216,29 @@ namespace OpenSim.Region.Physics.OdePlugin case HollowShape.Square: case HollowShape.Same: // Cube Hollow volume calculation - float hollowsizex = _size.X * hollowAmount; - float hollowsizey = _size.Y * hollowAmount; - float hollowsizez = _size.Z * hollowAmount; - hollowVolume = hollowsizex * hollowsizey * hollowsizez; + float hollowsizex = _size.X*hollowAmount; + float hollowsizey = _size.Y*hollowAmount; + float hollowsizez = _size.Z*hollowAmount; + hollowVolume = hollowsizex*hollowsizey*hollowsizez; break; case HollowShape.Circle: // Hollow shape is a perfect cyllinder in respect to the cube's scale // Cyllinder hollow volume calculation - float hRadius = _size.X / 2; + float hRadius = _size.X/2; float hLength = _size.Z; // pi * r2 * h - hollowVolume = ((float)(Math.PI * Math.Pow(hRadius, 2) * hLength) * hollowAmount); + hollowVolume = ((float) (Math.PI*Math.Pow(hRadius, 2)*hLength)*hollowAmount); break; case HollowShape.Triangle: // Equilateral Triangular Prism volume hollow calculation // Triangle is an Equilateral Triangular Prism with aLength = to _size.Y - float aLength = _size.Y; + float aLength = _size.Y; // 1/2 abh - hollowVolume = (float)((0.5 * aLength * _size.X * _size.Z) * hollowAmount); + hollowVolume = (float) ((0.5*aLength*_size.X*_size.Z)*hollowAmount); break; default: @@ -247,15 +246,14 @@ namespace OpenSim.Region.Physics.OdePlugin break; } volume = volume - hollowVolume; - } - + break; default: // we don't have all of the volume formulas yet so // use the common volume formula for all - volume = _size.X * _size.Y * _size.Z; + volume = _size.X*_size.Y*_size.Z; break; } @@ -273,70 +271,70 @@ namespace OpenSim.Region.Physics.OdePlugin float PathCutStartAmount = _pbs.ProfileBegin; if (((PathCutStartAmount + PathCutEndAmount)/50000f) > 0.0f) { + float pathCutAmount = ((PathCutStartAmount + PathCutEndAmount)/50000f); - float pathCutAmount = ((PathCutStartAmount + PathCutEndAmount) / 50000f); - // Check the return amount for sanity - if (pathCutAmount >= 0.99f) - pathCutAmount=0.99f; + if (pathCutAmount >= 0.99f) + pathCutAmount = 0.99f; - volume = volume - (volume * pathCutAmount); + volume = volume - (volume*pathCutAmount); } - + // Mass = density * volume - returnMass = m_density * volume; + returnMass = m_density*volume; return returnMass; } public void setMass() - { - if (Body != (IntPtr)0) + { + if (Body != (IntPtr) 0) { d.MassSetBoxTotal(out pMass, CalculateMass(), _size.X, _size.Y, _size.Z); d.BodySetMass(Body, ref pMass); } } - public void disableBody() { //this kills the body so things like 'mesh' can re-create it. - if (Body != (IntPtr)0) + if (Body != (IntPtr) 0) { _parent_scene.remActivePrim(this); d.BodyDestroy(Body); - Body = (IntPtr)0; + Body = (IntPtr) 0; } } + public void setMesh(OdeScene parent_scene, IMesh mesh) { //Kill Body so that mesh can re-make the geom - if (IsPhysical && Body != (IntPtr)0) + if (IsPhysical && Body != (IntPtr) 0) { disableBody(); } float[] vertexList = mesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory int[] indexList = mesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage - int VertexCount = vertexList.GetLength(0) / 3; + int VertexCount = vertexList.GetLength(0)/3; int IndexCount = indexList.GetLength(0); - + _triMeshData = d.GeomTriMeshDataCreate(); - d.GeomTriMeshDataBuildSimple(_triMeshData, vertexList, 3 * sizeof(float), VertexCount, indexList, IndexCount, - 3 * sizeof(int)); + d.GeomTriMeshDataBuildSimple(_triMeshData, vertexList, 3*sizeof (float), VertexCount, indexList, IndexCount, + 3*sizeof (int)); d.GeomTriMeshDataPreprocess(_triMeshData); prim_geom = d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null); - - if (IsPhysical && Body == (IntPtr)0) + + if (IsPhysical && Body == (IntPtr) 0) { // Recreate the body enableBody(); } } + public void ProcessTaints(float timestep) { if (m_taintposition != _position) @@ -357,14 +355,14 @@ namespace OpenSim.Region.Physics.OdePlugin if (m_taintshape) changeshape(timestep); // - } + public void Move(float timestep) { if (m_isphysical) { // This is a fallback.. May no longer be necessary. - if (Body == (IntPtr)0) + if (Body == (IntPtr) 0) enableBody(); //Prim auto disable after 20 frames, ///if you move it, re-enable the prim manually. @@ -382,35 +380,35 @@ namespace OpenSim.Region.Physics.OdePlugin m_taintposition = _position; } + public void rotate(float timestep) { - d.Quaternion myrot = new d.Quaternion(); myrot.W = _orientation.w; myrot.X = _orientation.x; myrot.Y = _orientation.y; myrot.Z = _orientation.z; d.GeomSetQuaternion(prim_geom, ref myrot); - if (m_isphysical && Body != (IntPtr)0) + if (m_isphysical && Body != (IntPtr) 0) { d.BodySetQuaternion(Body, ref myrot); } m_taintrot = _orientation; } + public void changePhysicsStatus(float timestap) { if (m_isphysical == true) { - if (Body == (IntPtr)0) + if (Body == (IntPtr) 0) { enableBody(); } - } else { - if (Body != (IntPtr)0) + if (Body != (IntPtr) 0) { disableBody(); } @@ -419,6 +417,7 @@ namespace OpenSim.Region.Physics.OdePlugin m_taintPhysics = m_isphysical; } + public void changesize(float timestamp) { string oldname = _parent_scene.geom_name_map[prim_geom]; @@ -429,7 +428,7 @@ namespace OpenSim.Region.Physics.OdePlugin // Cleanup meshing here } //kill body to rebuild - if (IsPhysical && Body != (IntPtr)0) + if (IsPhysical && Body != (IntPtr) 0) { disableBody(); } @@ -442,10 +441,8 @@ namespace OpenSim.Region.Physics.OdePlugin // we don't need to do space calculation because the client sends a position update also. // Construction of new prim - if (this._parent_scene.needsMeshing(_pbs)) + if (_parent_scene.needsMeshing(_pbs)) { - - // Don't need to re-enable body.. it's done in SetMesh IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size); // createmesh returns null when it's a shape that isn't a cube. @@ -463,8 +460,6 @@ namespace OpenSim.Region.Physics.OdePlugin myrot.Y = _orientation.y; myrot.Z = _orientation.z; d.GeomSetQuaternion(prim_geom, ref myrot); - - } } else @@ -480,7 +475,7 @@ namespace OpenSim.Region.Physics.OdePlugin //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z); - if (IsPhysical && Body == (IntPtr)0) + if (IsPhysical && Body == (IntPtr) 0) { // Re creates body on size. // EnableBody also does setMass() @@ -493,12 +488,13 @@ namespace OpenSim.Region.Physics.OdePlugin m_taintsize = _size; } + public void changeshape(float timestamp) { string oldname = _parent_scene.geom_name_map[prim_geom]; // Cleanup of old prim geometry and Bodies - if (IsPhysical && Body != (IntPtr)0) + if (IsPhysical && Body != (IntPtr) 0) { disableBody(); } @@ -509,7 +505,7 @@ namespace OpenSim.Region.Physics.OdePlugin } // Construction of new prim - if (this._parent_scene.needsMeshing(_pbs)) + if (_parent_scene.needsMeshing(_pbs)) { IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size); if (mesh != null) @@ -525,7 +521,7 @@ namespace OpenSim.Region.Physics.OdePlugin { prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z); } - if (IsPhysical && Body == (IntPtr)0) + if (IsPhysical && Body == (IntPtr) 0) { //re-create new body enableBody(); @@ -544,11 +540,13 @@ namespace OpenSim.Region.Physics.OdePlugin m_taintshape = false; } + public override bool IsPhysical { get { return m_isphysical; } set { m_isphysical = value; } } + public void setPrimForRemoval() { m_taintremove = true; @@ -556,9 +554,7 @@ namespace OpenSim.Region.Physics.OdePlugin public override bool Flying { - get - { - return false; //no flying prims for you + get { return false; //no flying prims for you } set { } } @@ -568,16 +564,19 @@ namespace OpenSim.Region.Physics.OdePlugin get { return iscolliding; } set { iscolliding = value; } } + public override bool CollidingGround { get { return false; } set { return; } } + public override bool CollidingObj { get { return false; } set { return; } } + public override bool ThrottleUpdates { get { return m_throttleUpdates; } @@ -588,20 +587,13 @@ namespace OpenSim.Region.Physics.OdePlugin { get { return _position; } - set - { - _position = value; - - } + set { _position = value; } } public override PhysicsVector Size { get { return _size; } - set - { - _size = value; - } + set { _size = value; } } public override float Mass @@ -626,10 +618,7 @@ namespace OpenSim.Region.Physics.OdePlugin public override PrimitiveBaseShape Shape { - set - { - _pbs = value; - } + set { _pbs = value; } } public override PhysicsVector Velocity @@ -639,9 +628,9 @@ namespace OpenSim.Region.Physics.OdePlugin // Averate previous velocity with the new one so // client object interpolation works a 'little' better PhysicsVector returnVelocity = new PhysicsVector(); - returnVelocity.X = (m_lastVelocity.X + _velocity.X) / 2; - returnVelocity.Y = (m_lastVelocity.Y + _velocity.Y) / 2; - returnVelocity.Z = (m_lastVelocity.Z + _velocity.Z) / 2; + returnVelocity.X = (m_lastVelocity.X + _velocity.X)/2; + returnVelocity.Y = (m_lastVelocity.Y + _velocity.Y)/2; + returnVelocity.Z = (m_lastVelocity.Z + _velocity.Z)/2; return returnVelocity; } set { _velocity = value; } @@ -656,11 +645,7 @@ namespace OpenSim.Region.Physics.OdePlugin public override Quaternion Orientation { get { return _orientation; } - set - { - _orientation = value; - - } + set { _orientation = value; } } public override PhysicsVector Acceleration @@ -688,7 +673,7 @@ namespace OpenSim.Region.Physics.OdePlugin { // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! - if (Body != (IntPtr)0) + if (Body != (IntPtr) 0) { d.Vector3 vec = d.BodyGetPosition(Body); d.Quaternion ori = d.BodyGetQuaternion(Body); @@ -715,8 +700,6 @@ namespace OpenSim.Region.Physics.OdePlugin // It's a hack and will generate a console message if it fails. - - //IsPhysical = false; base.RaiseOutOfBounds(_position); _velocity.X = 0; @@ -736,7 +719,6 @@ namespace OpenSim.Region.Physics.OdePlugin && (Math.Abs(m_lastposition.Y - l_position.Y) < 0.02) && (Math.Abs(m_lastposition.Z - l_position.Z) < 0.02)) { - _zeroFlag = true; } else @@ -746,7 +728,6 @@ namespace OpenSim.Region.Physics.OdePlugin } - if (_zeroFlag) { // Supposedly this is supposed to tell SceneObjectGroup that @@ -811,10 +792,10 @@ namespace OpenSim.Region.Physics.OdePlugin m_rotationalVelocity.Z = 0; _zeroFlag = true; } - } + public override void SetMomentum(PhysicsVector momentum) { } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs index 8bb822e..f2c9b57 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs @@ -28,6 +28,7 @@ using System; using System.Collections.Generic; +using System.Runtime.InteropServices; using Axiom.Math; using Ode.NET; using OpenSim.Framework; @@ -99,17 +100,17 @@ namespace OpenSim.Region.Physics.OdePlugin private d.Contact TerrainContact; private d.Contact AvatarMovementprimContact; private d.Contact AvatarMovementTerrainContact; - + private int m_physicsiterations = 10; private float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag private PhysicsActor PANull = new NullPhysicsActor(); private float step_time = 0.0f; public IntPtr world; - + public IntPtr space; // split static geometry collision handling into spaces of 30 meters - public IntPtr[,] staticPrimspace = new IntPtr[(int)(300/metersInSpace),(int)(300/metersInSpace)]; - + public IntPtr[,] staticPrimspace = new IntPtr[(int) (300/metersInSpace),(int) (300/metersInSpace)]; + public static Object OdeLock = new Object(); public IMesher mesher; @@ -126,7 +127,7 @@ namespace OpenSim.Region.Physics.OdePlugin contact.surface.soft_erp = 0.005f; contact.surface.soft_cfm = 0.00003f; */ - + contact.surface.mu = 250.0f; contact.surface.bounce = 0.2f; @@ -151,7 +152,7 @@ namespace OpenSim.Region.Physics.OdePlugin contactgroup = d.JointGroupCreate(0); //contactgroup - + d.WorldSetGravity(world, 0.0f, 0.0f, -10.0f); d.WorldSetAutoDisableFlag(world, false); d.WorldSetContactSurfaceLayer(world, 0.001f); @@ -165,10 +166,9 @@ namespace OpenSim.Region.Physics.OdePlugin { for (int j = 0; j < staticPrimspace.GetLength(1); j++) { - staticPrimspace[i,j] = IntPtr.Zero; + staticPrimspace[i, j] = IntPtr.Zero; } } - } public override void Initialise(IMesher meshmerizer) @@ -184,25 +184,25 @@ namespace OpenSim.Region.Physics.OdePlugin private void near(IntPtr space, IntPtr g1, IntPtr g2) { // no lock here! It's invoked from within Simulate(), which is thread-locked - if (d.GeomIsSpace(g1) || d.GeomIsSpace(g2) ) + if (d.GeomIsSpace(g1) || d.GeomIsSpace(g2)) { // Separating static prim geometry spaces. // We'll be calling near recursivly if one // of them is a space to find all of the // contact points in the space - + d.SpaceCollide2(g1, g2, IntPtr.Zero, nearCallback); //Colliding a space or a geom with a space or a geom. //Collide all geoms in each space.. //if (d.GeomIsSpace(g1)) d.SpaceCollide(g1, IntPtr.Zero, nearCallback); //if (d.GeomIsSpace(g2)) d.SpaceCollide(g2, IntPtr.Zero, nearCallback); - } - else + } + else { // Colliding Geom To Geom // This portion of the function 'was' blatantly ripped off from BoxStack.cs - + IntPtr b1 = d.GeomGetBody(g1); IntPtr b2 = d.GeomGetBody(g2); @@ -213,7 +213,7 @@ namespace OpenSim.Region.Physics.OdePlugin return; d.GeomClassID id = d.GeomGetClass(g1); - + String name1 = null; String name2 = null; @@ -228,21 +228,22 @@ namespace OpenSim.Region.Physics.OdePlugin if (id == d.GeomClassID.TriMeshClass) { - // MainLog.Instance.Verbose("near: A collision was detected between {1} and {2}", 0, name1, name2); + // MainLog.Instance.Verbose("near: A collision was detected between {1} and {2}", 0, name1, name2); //System.Console.WriteLine("near: A collision was detected between {1} and {2}", 0, name1, name2); } - + int count = 0; try { count = d.Collide(g1, g2, contacts.GetLength(0), contacts, d.ContactGeom.SizeOf); } - catch (System.Runtime.InteropServices.SEHException) + catch (SEHException) { - MainLog.Instance.Error("PHYSICS", "The Operating system shut down ODE because of corrupt memory. This could be a result of really irregular terrain. If this repeats continuously, restart using Basic Physics and terrain fill your terrain. Restarting the sim."); + MainLog.Instance.Error("PHYSICS", + "The Operating system shut down ODE because of corrupt memory. This could be a result of really irregular terrain. If this repeats continuously, restart using Basic Physics and terrain fill your terrain. Restarting the sim."); base.TriggerPhysicsBasedRestart(); } - + for (int i = 0; i < count; i++) { IntPtr joint; @@ -263,17 +264,17 @@ namespace OpenSim.Region.Physics.OdePlugin // We only need to test p2 for 'jump crouch purposes' p2.IsColliding = true; - - switch(p1.PhysicsActorType) { - case (int)ActorTypes.Agent: + switch (p1.PhysicsActorType) + { + case (int) ActorTypes.Agent: p2.CollidingObj = true; break; - case (int)ActorTypes.Prim: - if (p2.Velocity.X >0 || p2.Velocity.Y > 0 || p2.Velocity.Z > 0) + case (int) ActorTypes.Prim: + if (p2.Velocity.X > 0 || p2.Velocity.Y > 0 || p2.Velocity.Z > 0) p2.CollidingObj = true; break; - case (int)ActorTypes.Unknown: + case (int) ActorTypes.Unknown: p2.CollidingGround = true; break; default: @@ -282,7 +283,9 @@ namespace OpenSim.Region.Physics.OdePlugin } // we don't want prim or avatar to explode + #region InterPenetration Handling - Unintended physics explosions + if (contacts[i].depth >= 0.08f) { if (contacts[i].depth >= 1.00f) @@ -290,30 +293,31 @@ namespace OpenSim.Region.Physics.OdePlugin //MainLog.Instance.Debug("PHYSICS",contacts[i].depth.ToString()); } // If you interpenetrate a prim with an agent - if ((p2.PhysicsActorType == (int)ActorTypes.Agent && p1.PhysicsActorType == (int)ActorTypes.Prim) || (p1.PhysicsActorType == (int)ActorTypes.Agent && p2.PhysicsActorType == (int)ActorTypes.Prim)) + if ((p2.PhysicsActorType == (int) ActorTypes.Agent && + p1.PhysicsActorType == (int) ActorTypes.Prim) || + (p1.PhysicsActorType == (int) ActorTypes.Agent && + p2.PhysicsActorType == (int) ActorTypes.Prim)) { - - if (p2.PhysicsActorType == (int)ActorTypes.Agent) + if (p2.PhysicsActorType == (int) ActorTypes.Agent) { p2.CollidingObj = true; //contacts[i].depth = 0.003f; p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 2.5f); - OdeCharacter character = (OdeCharacter)p2; + OdeCharacter character = (OdeCharacter) p2; character.SetPidStatus(true); //contacts[i].pos = new d.Vector3(contacts[i].pos.X + (p1.Size.X / 2), contacts[i].pos.Y + (p1.Size.Y / 2), contacts[i].pos.Z + (p1.Size.Z / 2)); - } else { contacts[i].depth = 0.0000000f; } - if (p1.PhysicsActorType == (int)ActorTypes.Agent) + if (p1.PhysicsActorType == (int) ActorTypes.Agent) { p1.CollidingObj = true; //contacts[i].depth = 0.003f; p1.Velocity = p1.Velocity + new PhysicsVector(0, 0, 2.5f); //contacts[i].pos = new d.Vector3(contacts[i].pos.X + (p2.Size.X / 2), contacts[i].pos.Y + (p2.Size.Y / 2), contacts[i].pos.Z + (p2.Size.Z / 2)); - OdeCharacter character = (OdeCharacter)p2; + OdeCharacter character = (OdeCharacter) p2; character.SetPidStatus(true); } else @@ -322,39 +326,45 @@ namespace OpenSim.Region.Physics.OdePlugin } } // If you interpenetrate a prim with another prim - if (p1.PhysicsActorType == (int)ActorTypes.Prim && p2.PhysicsActorType == (int)ActorTypes.Prim) + if (p1.PhysicsActorType == (int) ActorTypes.Prim && p2.PhysicsActorType == (int) ActorTypes.Prim) { // Don't collide, one or both prim will explode. contacts[i].depth = -1f; } if (contacts[i].depth >= 1.00f) { - if ((p2.PhysicsActorType == (int)ActorTypes.Agent && p1.PhysicsActorType == (int)ActorTypes.Unknown) || (p1.PhysicsActorType == (int)ActorTypes.Agent && p2.PhysicsActorType == (int)ActorTypes.Unknown)) + if ((p2.PhysicsActorType == (int) ActorTypes.Agent && + p1.PhysicsActorType == (int) ActorTypes.Unknown) || + (p1.PhysicsActorType == (int) ActorTypes.Agent && + p2.PhysicsActorType == (int) ActorTypes.Unknown)) { - - if (p2.PhysicsActorType == (int)ActorTypes.Agent) + if (p2.PhysicsActorType == (int) ActorTypes.Agent) { - OdeCharacter character = (OdeCharacter)p2; - + OdeCharacter character = (OdeCharacter) p2; + //p2.CollidingObj = true; contacts[i].depth = 0.003f; p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 0.5f); - contacts[i].pos = new d.Vector3(contacts[i].pos.X + (p1.Size.X / 2), contacts[i].pos.Y + (p1.Size.Y / 2), contacts[i].pos.Z + (p1.Size.Z / 2)); + contacts[i].pos = + new d.Vector3(contacts[i].pos.X + (p1.Size.X/2), + contacts[i].pos.Y + (p1.Size.Y/2), + contacts[i].pos.Z + (p1.Size.Z/2)); character.SetPidStatus(true); - } else { - } - if (p1.PhysicsActorType == (int)ActorTypes.Agent) + if (p1.PhysicsActorType == (int) ActorTypes.Agent) { - OdeCharacter character = (OdeCharacter)p2; + OdeCharacter character = (OdeCharacter) p2; //p2.CollidingObj = true; contacts[i].depth = 0.003f; p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 0.5f); - contacts[i].pos = new d.Vector3(contacts[i].pos.X + (p1.Size.X / 2), contacts[i].pos.Y + (p1.Size.Y / 2), contacts[i].pos.Z + (p1.Size.Z / 2)); + contacts[i].pos = + new d.Vector3(contacts[i].pos.X + (p1.Size.X/2), + contacts[i].pos.Y + (p1.Size.Y/2), + contacts[i].pos.Z + (p1.Size.Z/2)); character.SetPidStatus(true); } else @@ -364,18 +374,18 @@ namespace OpenSim.Region.Physics.OdePlugin } } } + #endregion if (contacts[i].depth >= 0f) { if (name1 == "Terrain" || name2 == "Terrain") { - - if ((p2.PhysicsActorType == (int)ActorTypes.Agent) && (Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f)) + if ((p2.PhysicsActorType == (int) ActorTypes.Agent) && + (Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f)) { AvatarMovementTerrainContact.geom = contacts[i]; joint = d.JointCreateContact(world, contactgroup, ref AvatarMovementTerrainContact); - } else { @@ -385,11 +395,11 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - if ((p2.PhysicsActorType == (int)ActorTypes.Agent) && (Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f)) + if ((p2.PhysicsActorType == (int) ActorTypes.Agent) && + (Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f)) { AvatarMovementprimContact.geom = contacts[i]; joint = d.JointCreateContact(world, contactgroup, ref AvatarMovementprimContact); - } else { @@ -399,7 +409,7 @@ namespace OpenSim.Region.Physics.OdePlugin } d.JointAttach(joint, b1, b2); } - + if (count > 3) { p2.ThrottleUpdates = true; @@ -421,7 +431,7 @@ namespace OpenSim.Region.Physics.OdePlugin } // If the sim is running slow this frame, // don't process collision for prim! - if (timeStep < (m_SkipFramesAtms / 3)) + if (timeStep < (m_SkipFramesAtms/3)) { foreach (OdePrim chr in _activeprims) { @@ -432,16 +442,16 @@ namespace OpenSim.Region.Physics.OdePlugin //foreach (OdePrim ch2 in _prims) /// should be a separate space -- lots of avatars will be N**2 slow //{ - //if (ch2.IsPhysical && d.BodyIsEnabled(ch2.Body)) - //{ - // Only test prim that are 0.03 meters away in one direction. - // This should be Optimized! - - //if ((Math.Abs(ch2.Position.X - chr.Position.X) < 0.03) || (Math.Abs(ch2.Position.Y - chr.Position.Y) < 0.03) || (Math.Abs(ch2.Position.X - chr.Position.X) < 0.03)) - //{ - //d.SpaceCollide2(chr.prim_geom, ch2.prim_geom, IntPtr.Zero, nearCallback); - //} - //} + //if (ch2.IsPhysical && d.BodyIsEnabled(ch2.Body)) + //{ + // Only test prim that are 0.03 meters away in one direction. + // This should be Optimized! + + //if ((Math.Abs(ch2.Position.X - chr.Position.X) < 0.03) || (Math.Abs(ch2.Position.Y - chr.Position.Y) < 0.03) || (Math.Abs(ch2.Position.X - chr.Position.X) < 0.03)) + //{ + //d.SpaceCollide2(chr.prim_geom, ch2.prim_geom, IntPtr.Zero, nearCallback); + //} + //} //} } } @@ -456,7 +466,6 @@ namespace OpenSim.Region.Physics.OdePlugin if (d.BodyIsEnabled(chr.Body)) { d.SpaceCollide2(LandGeom, chr.prim_geom, IntPtr.Zero, nearCallback); - } } } @@ -492,7 +501,6 @@ namespace OpenSim.Region.Physics.OdePlugin p.setPrimForRemoval(); AddPhysicsActorTaint(prim); - } } } @@ -519,13 +527,14 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'removeprim from scene':" + ((OdePrim)prim).m_targetSpace.ToString()); + MainLog.Instance.Verbose("Physics", + "Invalid Scene passed to 'removeprim from scene':" + + ((OdePrim) prim).m_targetSpace.ToString()); } } } - //If there are no more geometries in the sub-space, we don't need it in the main space anymore if (d.SpaceGetNumGeoms(prim.m_targetSpace) == 0) { @@ -541,17 +550,18 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'removeprim from scene':" + ((OdePrim)prim).m_targetSpace.ToString()); + MainLog.Instance.Verbose("Physics", + "Invalid Scene passed to 'removeprim from scene':" + + ((OdePrim) prim).m_targetSpace.ToString()); } } - } + } } d.GeomDestroy(prim.prim_geom); _prims.Remove(prim); } - } public void resetSpaceArrayItemToZero(IntPtr space) @@ -566,7 +576,7 @@ namespace OpenSim.Region.Physics.OdePlugin } } - public void resetSpaceArrayItemToZero(int arrayitemX,int arrayitemY) + public void resetSpaceArrayItemToZero(int arrayitemX, int arrayitemY) { staticPrimspace[arrayitemX, arrayitemY] = IntPtr.Zero; } @@ -582,16 +592,17 @@ namespace OpenSim.Region.Physics.OdePlugin // never be called if the prim is physical(active) if (currentspace != space) { - if (d.SpaceQuery(currentspace, geom) && currentspace != (IntPtr)0) + if (d.SpaceQuery(currentspace, geom) && currentspace != (IntPtr) 0) { if (d.GeomIsSpace(currentspace)) { - d.SpaceRemove(currentspace, geom); } else { - MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + currentspace.ToString() + " Geom:" + geom.ToString()); + MainLog.Instance.Verbose("Physics", + "Invalid Scene passed to 'recalculatespace':" + currentspace.ToString() + + " Geom:" + geom.ToString()); } } else @@ -599,7 +610,7 @@ namespace OpenSim.Region.Physics.OdePlugin IntPtr sGeomIsIn = d.GeomGetSpace(geom); if (!(sGeomIsIn.Equals(null))) { - if (sGeomIsIn != (IntPtr)0) + if (sGeomIsIn != (IntPtr) 0) { if (d.GeomIsSpace(currentspace)) { @@ -607,7 +618,9 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + sGeomIsIn.ToString() + " Geom:" + geom.ToString()); + MainLog.Instance.Verbose("Physics", + "Invalid Scene passed to 'recalculatespace':" + + sGeomIsIn.ToString() + " Geom:" + geom.ToString()); } } } @@ -617,7 +630,7 @@ namespace OpenSim.Region.Physics.OdePlugin //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 (currentspace != (IntPtr)0) + if (currentspace != (IntPtr) 0) { if (d.GeomIsSpace(currentspace)) { @@ -628,9 +641,10 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + currentspace.ToString() + " Geom:" + geom.ToString()); + MainLog.Instance.Verbose("Physics", + "Invalid Scene passed to 'recalculatespace':" + + currentspace.ToString() + " Geom:" + geom.ToString()); } - } } } @@ -639,15 +653,16 @@ namespace OpenSim.Region.Physics.OdePlugin // this is a physical object that got disabled. ;.; if (d.SpaceQuery(currentspace, geom)) { - if (currentspace != (IntPtr)0) + if (currentspace != (IntPtr) 0) if (d.GeomIsSpace(currentspace)) { d.SpaceRemove(currentspace, geom); } else { - MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + currentspace.ToString() + " Geom:" + geom.ToString()); - + MainLog.Instance.Verbose("Physics", + "Invalid Scene passed to 'recalculatespace':" + + currentspace.ToString() + " Geom:" + geom.ToString()); } } else @@ -655,7 +670,7 @@ namespace OpenSim.Region.Physics.OdePlugin IntPtr sGeomIsIn = d.GeomGetSpace(geom); if (!(sGeomIsIn.Equals(null))) { - if (sGeomIsIn != (IntPtr)0) + if (sGeomIsIn != (IntPtr) 0) { if (d.GeomIsSpace(sGeomIsIn)) { @@ -663,14 +678,16 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + sGeomIsIn.ToString() + " Geom:" + geom.ToString()); + MainLog.Instance.Verbose("Physics", + "Invalid Scene passed to 'recalculatespace':" + + sGeomIsIn.ToString() + " Geom:" + geom.ToString()); } } } } } - + // The routines in the Position and Size sections do the 'inserting' into the space, // so all we have to do is make sure that the space that we're putting the prim into // is in the 'main' space. @@ -679,17 +696,18 @@ namespace OpenSim.Region.Physics.OdePlugin if (newspace == IntPtr.Zero) { - newspace = createprimspace(iprimspaceArrItem[0],iprimspaceArrItem[1]); + newspace = createprimspace(iprimspaceArrItem[0], iprimspaceArrItem[1]); d.HashSpaceSetLevels(newspace, -4, 66); } - + return newspace; } - public IntPtr createprimspace(int iprimspaceArrItemX, int iprimspaceArrItemY) { + public IntPtr createprimspace(int iprimspaceArrItemX, int iprimspaceArrItemY) + { // creating a new space for prim and inserting it into main space. staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY] = d.HashSpaceCreate(IntPtr.Zero); - d.SpaceAdd(space, staticPrimspace[iprimspaceArrItemX,iprimspaceArrItemY]); + d.SpaceAdd(space, staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]); return staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]; } @@ -697,7 +715,7 @@ namespace OpenSim.Region.Physics.OdePlugin { int[] xyspace = calculateSpaceArrayItemFromPos(pos); //MainLog.Instance.Verbose("Physics", "Attempting to use arrayItem: " + xyspace[0].ToString() + "," + xyspace[1].ToString()); - IntPtr locationbasedspace = staticPrimspace[xyspace[0],xyspace[1]]; + IntPtr locationbasedspace = staticPrimspace[xyspace[0], xyspace[1]]; //locationbasedspace = space; return locationbasedspace; @@ -706,17 +724,17 @@ namespace OpenSim.Region.Physics.OdePlugin public int[] calculateSpaceArrayItemFromPos(PhysicsVector pos) { int[] returnint = new int[2]; - - returnint[0] = (int)(pos.X / metersInSpace); - - if (returnint[0] > ((int)(259f / metersInSpace))) - returnint[0] = ((int)(259f / metersInSpace)); + + returnint[0] = (int) (pos.X/metersInSpace); + + if (returnint[0] > ((int) (259f/metersInSpace))) + returnint[0] = ((int) (259f/metersInSpace)); if (returnint[0] < 0) returnint[0] = 0; - returnint[1] = (int)(pos.Y / metersInSpace); - if (returnint[0] > ((int)(259f / metersInSpace))) - returnint[0] = ((int)(259f / metersInSpace)); + returnint[1] = (int) (pos.Y/metersInSpace); + if (returnint[0] > ((int) (259f/metersInSpace))) + returnint[0] = ((int) (259f/metersInSpace)); if (returnint[0] < 0) returnint[0] = 0; @@ -726,7 +744,6 @@ namespace OpenSim.Region.Physics.OdePlugin private PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool isphysical) { - PhysicsVector pos = new PhysicsVector(); pos.X = position.X; pos.Y = position.Y; @@ -741,21 +758,21 @@ namespace OpenSim.Region.Physics.OdePlugin rot.y = rotation.y; rot.z = rotation.z; - + int[] iprimspaceArrItem = calculateSpaceArrayItemFromPos(pos); IntPtr targetspace = calculateSpaceForGeom(pos); if (targetspace == IntPtr.Zero) - targetspace = createprimspace(iprimspaceArrItem[0],iprimspaceArrItem[1]); + targetspace = createprimspace(iprimspaceArrItem[0], iprimspaceArrItem[1]); OdePrim newPrim; lock (OdeLock) { newPrim = new OdePrim(name, this, targetspace, pos, siz, rot, mesh, pbs, isphysical); - + _prims.Add(newPrim); } - + return newPrim; } @@ -763,16 +780,14 @@ namespace OpenSim.Region.Physics.OdePlugin { // adds active prim.. (ones that should be iterated over in collisions_optimized - _activeprims.Add(activatePrim); - + _activeprims.Add(activatePrim); } + public void remActivePrim(OdePrim deactivatePrim) { - - _activeprims.Remove(deactivatePrim); - - + _activeprims.Remove(deactivatePrim); } + public int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount) { /* String name1 = null; @@ -818,7 +833,7 @@ namespace OpenSim.Region.Physics.OdePlugin return 1; } - + public bool needsMeshing(PrimitiveBaseShape pbs) { if (pbs.ProfileHollow != 0) @@ -833,7 +848,7 @@ namespace OpenSim.Region.Physics.OdePlugin public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation) //To be removed { - return this.AddPrimShape(primName, pbs, position, size, rotation, false); + return AddPrimShape(primName, pbs, position, size, rotation, false); } public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, @@ -848,12 +863,12 @@ namespace OpenSim.Region.Physics.OdePlugin /// support simple box & hollow box now; later, more shapes if (needsMeshing(pbs)) { - mesh = mesher.CreateMesh(primName, pbs, size); + mesh = mesher.CreateMesh(primName, pbs, size); } - + break; } - + result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical); @@ -864,10 +879,9 @@ namespace OpenSim.Region.Physics.OdePlugin { if (prim is OdePrim) { - OdePrim taintedprim = ((OdePrim)prim); + OdePrim taintedprim = ((OdePrim) prim); if (!(_taintedPrim.Contains(taintedprim))) _taintedPrim.Add(taintedprim); - } } @@ -877,19 +891,18 @@ namespace OpenSim.Region.Physics.OdePlugin step_time += timeStep; - - // If We're loaded down by something else, - // or debugging with the Visual Studio project on pause - // skip a few frames to catch up gracefully. - // without shooting the physicsactors all over the place - + + // If We're loaded down by something else, + // or debugging with the Visual Studio project on pause + // skip a few frames to catch up gracefully. + // without shooting the physicsactors all over the place if (step_time >= m_SkipFramesAtms) { // Instead of trying to catch up, it'll do one physics frame only step_time = ODE_STEPSIZE; - this.m_physicsiterations = 5; + m_physicsiterations = 5; } else { @@ -897,35 +910,36 @@ namespace OpenSim.Region.Physics.OdePlugin } lock (OdeLock) { - // Process 10 frames if the sim is running normal.. - // process 5 frames if the sim is running slow - try{ + // Process 10 frames if the sim is running normal.. + // process 5 frames if the sim is running slow + try + { d.WorldSetQuickStepNumIterations(world, m_physicsiterations); } - catch (System.StackOverflowException) + catch (StackOverflowException) { - MainLog.Instance.Error("PHYSICS", "The operating system wasn't able to allocate enough memory for the simulation. Restarting the sim."); + MainLog.Instance.Error("PHYSICS", + "The operating system wasn't able to allocate enough memory for the simulation. Restarting the sim."); base.TriggerPhysicsBasedRestart(); } int i = 0; - - + + // Figure out the Frames Per Second we're going at. - - fps = (((step_time / ODE_STEPSIZE * m_physicsiterations)*2)* 10); - + + fps = (((step_time/ODE_STEPSIZE*m_physicsiterations)*2)*10); + while (step_time > 0.0f) { - foreach (OdeCharacter actor in _characters) { - actor.Move(timeStep); - actor.collidelock = true; + actor.Move(timeStep); + actor.collidelock = true; } - + collision_optimized(timeStep); d.WorldQuickStep(world, ODE_STEPSIZE); d.JointGroupEmpty(contactgroup); @@ -933,7 +947,7 @@ namespace OpenSim.Region.Physics.OdePlugin { actor.collidelock = false; } - + step_time -= ODE_STEPSIZE; i++; } @@ -941,7 +955,6 @@ namespace OpenSim.Region.Physics.OdePlugin foreach (OdeCharacter actor in _characters) { actor.UpdatePositionAndVelocity(); - } bool processedtaints = false; foreach (OdePrim prim in _taintedPrim) @@ -963,7 +976,6 @@ namespace OpenSim.Region.Physics.OdePlugin if (actor.IsPhysical && (d.BodyIsEnabled(actor.Body) || !actor._zeroFlag)) { actor.UpdatePositionAndVelocity(); - } } } @@ -984,25 +996,25 @@ namespace OpenSim.Region.Physics.OdePlugin public float[] ResizeTerrain512(float[] heightMap) { float[] returnarr = new float[262144]; - float[,] resultarr = new float[m_regionWidth, m_regionHeight]; + float[,] resultarr = new float[m_regionWidth,m_regionHeight]; // Filling out the array into it's multi-dimentional components for (int y = 0; y < m_regionHeight; y++) { for (int x = 0; x < m_regionWidth; x++) { - resultarr[y,x] = heightMap[y * m_regionWidth + x]; + resultarr[y, x] = heightMap[y*m_regionWidth + x]; } } // Resize using interpolation - + // This particular way is quick but it only works on a multiple of the original // The idea behind this method can be described with the following diagrams // second pass and third pass happen in the same loop really.. just separated // them to show what this does. - + // First Pass // ResultArr: // 1,1,1,1,1,1 @@ -1054,12 +1066,12 @@ namespace OpenSim.Region.Physics.OdePlugin // 4th # // on single loop. - float[,] resultarr2 = new float[512, 512]; + float[,] resultarr2 = new float[512,512]; for (int y = 0; y < m_regionHeight; y++) { for (int x = 0; x < m_regionWidth; x++) { - resultarr2[y*2,x*2] = resultarr[y,x]; + resultarr2[y*2, x*2] = resultarr[y, x]; if (y < m_regionHeight) { @@ -1067,16 +1079,17 @@ namespace OpenSim.Region.Physics.OdePlugin { if (x + 1 < m_regionWidth) { - resultarr2[(y * 2) + 1, x * 2] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x+1] + resultarr[y+1, x+1])/4); + resultarr2[(y*2) + 1, x*2] = ((resultarr[y, x] + resultarr[y + 1, x] + + resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4); } else { - resultarr2[(y * 2) + 1, x * 2] = ((resultarr[y, x] + resultarr[y + 1, x]) / 2); + resultarr2[(y*2) + 1, x*2] = ((resultarr[y, x] + resultarr[y + 1, x])/2); } } else { - resultarr2[(y * 2) + 1, x * 2] = resultarr[y, x]; + resultarr2[(y*2) + 1, x*2] = resultarr[y, x]; } } if (x < m_regionWidth) @@ -1085,31 +1098,32 @@ namespace OpenSim.Region.Physics.OdePlugin { if (y + 1 < m_regionHeight) { - resultarr2[y * 2, (x * 2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x + 1] + resultarr[y + 1, x + 1]) / 4); + resultarr2[y*2, (x*2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] + + resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4); } else { - resultarr2[y * 2, (x * 2) + 1] = ((resultarr[y, x] + resultarr[y, x + 1]) / 2); + resultarr2[y*2, (x*2) + 1] = ((resultarr[y, x] + resultarr[y, x + 1])/2); } } else { - resultarr2[y * 2, (x * 2) + 1] = resultarr[y, x]; + resultarr2[y*2, (x*2) + 1] = resultarr[y, x]; } } if (x < m_regionWidth && y < m_regionHeight) { if ((x + 1 < m_regionWidth) && (y + 1 < m_regionHeight)) { - resultarr2[(y * 2) + 1, (x * 2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x + 1] + resultarr[y + 1, x + 1]) / 4); + resultarr2[(y*2) + 1, (x*2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] + + resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4); } else { - resultarr2[(y * 2) + 1, (x * 2) + 1] = resultarr[y, x]; + resultarr2[(y*2) + 1, (x*2) + 1] = resultarr[y, x]; } } } - } //Flatten out the array int i = 0; @@ -1119,7 +1133,7 @@ namespace OpenSim.Region.Physics.OdePlugin { if (resultarr2[y, x] <= 0) returnarr[i] = 0.0000001f; - else + else returnarr[i] = resultarr2[y, x]; i++; @@ -1127,8 +1141,8 @@ namespace OpenSim.Region.Physics.OdePlugin } return returnarr; - } + public override void SetTerrain(float[] heightMap) { // this._heightmap[i] = (double)heightMap[i]; @@ -1137,8 +1151,8 @@ namespace OpenSim.Region.Physics.OdePlugin const uint heightmapWidth = m_regionWidth + 2; const uint heightmapHeight = m_regionHeight + 2; - const uint heightmapWidthSamples = 2 * m_regionWidth + 2; - const uint heightmapHeightSamples = 2 * m_regionHeight + 2; + const uint heightmapWidthSamples = 2*m_regionWidth + 2; + const uint heightmapHeightSamples = 2*m_regionHeight + 2; const float scale = 1.0f; const float offset = 0.0f; const float thickness = 2.0f; @@ -1166,7 +1180,8 @@ namespace OpenSim.Region.Physics.OdePlugin } IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, heightmapWidth, heightmapHeight, - (int) heightmapWidthSamples, (int) heightmapHeightSamples, scale, offset, thickness, wrap); + (int) heightmapWidthSamples, (int) heightmapHeightSamples, scale, + offset, thickness, wrap); d.GeomHeightfieldDataSetBounds(HeightmapData, m_regionWidth, m_regionHeight); LandGeom = d.CreateHeightfield(space, HeightmapData, 1); geom_name_map[LandGeom] = "Terrain"; @@ -1193,7 +1208,4 @@ namespace OpenSim.Region.Physics.OdePlugin { } } - - - -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/POSPlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/POSPlugin/AssemblyInfo.cs index da9f587..3bb71d4 100644 --- a/OpenSim/Region/Physics/POSPlugin/AssemblyInfo.cs +++ b/OpenSim/Region/Physics/POSPlugin/AssemblyInfo.cs @@ -55,4 +55,4 @@ using System.Runtime.InteropServices; // You can specify all values by your own or you can build default build and revision // numbers with the '*' character (the default): -[assembly : AssemblyVersion("1.0.*")] +[assembly : AssemblyVersion("1.0.*")] \ No newline at end of file diff --git a/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs b/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs index 26310f9..1bc3490 100644 --- a/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs +++ b/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs @@ -25,8 +25,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ -using System.Collections.Generic; using System; +using System.Collections.Generic; using Axiom.Math; using OpenSim.Framework; using OpenSim.Region.Physics.Manager; @@ -114,10 +114,10 @@ namespace OpenSim.Region.Physics.POSPlugin public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation) { - return this.AddPrimShape(primName, pbs, position, size, rotation, false); + return AddPrimShape(primName, pbs, position, size, rotation, false); } - public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, + public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation, bool isPhysical) { POSPrim prim = new POSPrim(); @@ -136,18 +136,20 @@ namespace OpenSim.Region.Physics.POSPlugin " sizeX: " + p.Size.X * 0.5 + 0.5); */ - Vector3 rotatedPos = p.Orientation.Inverse() * new Vector3(c.Position.X - p.Position.X, c.Position.Y - p.Position.Y, c.Position.Z - p.Position.Z); - Vector3 avatarSize = p.Orientation.Inverse() * new Vector3(c.Size.X, c.Size.Y, c.Size.Z); + Vector3 rotatedPos = p.Orientation.Inverse()* + new Vector3(c.Position.X - p.Position.X, c.Position.Y - p.Position.Y, + c.Position.Z - p.Position.Z); + Vector3 avatarSize = p.Orientation.Inverse()*new Vector3(c.Size.X, c.Size.Y, c.Size.Z); - if (Math.Abs(rotatedPos.x) >= (p.Size.X * 0.5 + Math.Abs(avatarSize.x))) + if (Math.Abs(rotatedPos.x) >= (p.Size.X*0.5 + Math.Abs(avatarSize.x))) { return false; } - if (Math.Abs(rotatedPos.y) >= (p.Size.Y * 0.5 + Math.Abs(avatarSize.y))) + if (Math.Abs(rotatedPos.y) >= (p.Size.Y*0.5 + Math.Abs(avatarSize.y))) { return false; } - if (Math.Abs(rotatedPos.z) >= (p.Size.Z * 0.5 + Math.Abs(avatarSize.z))) + if (Math.Abs(rotatedPos.z) >= (p.Size.Z*0.5 + Math.Abs(avatarSize.z))) { return false; } @@ -182,12 +184,12 @@ namespace OpenSim.Region.Physics.POSPlugin if (!character.Flying) { - character._target_velocity.Z += gravity * timeStep; + character._target_velocity.Z += gravity*timeStep; } bool forcedZ = false; - character.Position.X += character._target_velocity.X * timeStep; - character.Position.Y += character._target_velocity.Y * timeStep; + character.Position.X += character._target_velocity.X*timeStep; + character.Position.Y += character._target_velocity.Y*timeStep; if (character.Position.Y < 0) { @@ -207,15 +209,15 @@ namespace OpenSim.Region.Physics.POSPlugin character.Position.X = 255.9F; } - float terrainheight = _heightMap[(int)character.Position.Y * 256 + (int)character.Position.X]; - if (character.Position.Z + (character._target_velocity.Z * timeStep) < terrainheight + 2) + float terrainheight = _heightMap[(int) character.Position.Y*256 + (int) character.Position.X]; + if (character.Position.Z + (character._target_velocity.Z*timeStep) < terrainheight + 2) { character.Position.Z = terrainheight + 1.0f; forcedZ = true; } else { - character.Position.Z += character._target_velocity.Z * timeStep; + character.Position.Z += character._target_velocity.Z*timeStep; } /// this is it -- the magic you've all been waiting for! Ladies and gentlemen -- @@ -224,21 +226,21 @@ namespace OpenSim.Region.Physics.POSPlugin if (check_all_prims(character)) { - character.Position.Z = oldposZ; // first try Z axis + character.Position.Z = oldposZ; // first try Z axis if (check_all_prims(character)) { - character.Position.Z = oldposZ + 0.4f; // try harder + character.Position.Z = oldposZ + 0.4f; // try harder if (check_all_prims(character)) { character.Position.X = oldposX; character.Position.Y = oldposY; character.Position.Z = oldposZ; - character.Position.X = character.Position.X + (character._target_velocity.X * timeStep); + character.Position.X = character.Position.X + (character._target_velocity.X*timeStep); if (check_all_prims(character)) { character.Position.X = oldposX; } - character.Position.Y = character.Position.Y + (character._target_velocity.Y * timeStep); + character.Position.Y = character.Position.Y + (character._target_velocity.Y*timeStep); if (check_all_prims(character)) { character.Position.Y = oldposY; @@ -253,7 +255,7 @@ namespace OpenSim.Region.Physics.POSPlugin { forcedZ = true; } - } + } if (character.Position.Y < 0) { @@ -273,8 +275,8 @@ namespace OpenSim.Region.Physics.POSPlugin character.Position.X = 255.9F; } - character._velocity.X = (character.Position.X - oldposX) / timeStep; - character._velocity.Y = (character.Position.Y - oldposY) / timeStep; + character._velocity.X = (character.Position.X - oldposX)/timeStep; + character._velocity.Y = (character.Position.Y - oldposY)/timeStep; if (forcedZ) { @@ -284,7 +286,7 @@ namespace OpenSim.Region.Physics.POSPlugin } else { - character._velocity.Z = (character.Position.Z - oldposZ) / timeStep; + character._velocity.Z = (character.Position.Z - oldposZ)/timeStep; } } return fps; @@ -326,31 +328,37 @@ namespace OpenSim.Region.Physics.POSPlugin _position = new PhysicsVector(); _acceleration = new PhysicsVector(); } + public override int PhysicsActorType { - get { return (int)ActorTypes.Agent; } + get { return (int) ActorTypes.Agent; } set { return; } } + public override PhysicsVector RotationalVelocity { get { return m_rotationalVelocity; } set { m_rotationalVelocity = value; } } + public override bool SetAlwaysRun { get { return false; } set { return; } } + public override bool IsPhysical { get { return false; } set { return; } } + public override bool ThrottleUpdates { get { return false; } set { return; } } + public override bool Flying { get { return flying; } @@ -362,16 +370,19 @@ namespace OpenSim.Region.Physics.POSPlugin get { return iscolliding; } set { iscolliding = value; } } + public override bool CollidingGround { get { return false; } set { return; } } + public override bool CollidingObj { get { return false; } set { return; } } + public override PhysicsVector Position { get { return _position; } @@ -383,18 +394,22 @@ namespace OpenSim.Region.Physics.POSPlugin get { return new PhysicsVector(0.5f, 0.5f, 1.0f); } set { } } + public override float Mass { get { return 0f; } } + public override PhysicsVector Force { get { return PhysicsVector.Zero; } } + public override PhysicsVector CenterOfMass { get { return PhysicsVector.Zero; } } + public override PhysicsVector GeometricCenter { get { return PhysicsVector.Zero; } @@ -402,10 +417,7 @@ namespace OpenSim.Region.Physics.POSPlugin public override PrimitiveBaseShape Shape { - set - { - return; - } + set { return; } } public override PhysicsVector Velocity @@ -461,41 +473,49 @@ namespace OpenSim.Region.Physics.POSPlugin _position = new PhysicsVector(); _acceleration = new PhysicsVector(); } + public override int PhysicsActorType { - get { return (int)ActorTypes.Prim; } + get { return (int) ActorTypes.Prim; } set { return; } } + public override PhysicsVector RotationalVelocity { get { return m_rotationalVelocity; } set { m_rotationalVelocity = value; } } + public override bool IsPhysical { get { return false; } set { return; } } + public override bool ThrottleUpdates { get { return false; } set { return; } } + public override bool IsColliding { get { return iscolliding; } set { iscolliding = value; } } + public override bool CollidingGround { get { return false; } set { return; } } + public override bool CollidingObj { get { return false; } set { return; } } + public override PhysicsVector Position { get { return _position; } @@ -530,10 +550,7 @@ namespace OpenSim.Region.Physics.POSPlugin public override PrimitiveBaseShape Shape { - set - { - return; - } + set { return; } } public override PhysicsVector Velocity @@ -571,6 +588,7 @@ namespace OpenSim.Region.Physics.POSPlugin public override void SetMomentum(PhysicsVector momentum) { } + public override bool Flying { get { return false; } @@ -583,4 +601,4 @@ namespace OpenSim.Region.Physics.POSPlugin set { return; } } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/PhysXPlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/PhysXPlugin/AssemblyInfo.cs index 8e6d2a6..36cb952 100644 --- a/OpenSim/Region/Physics/PhysXPlugin/AssemblyInfo.cs +++ b/OpenSim/Region/Physics/PhysXPlugin/AssemblyInfo.cs @@ -55,4 +55,4 @@ using System.Runtime.InteropServices; // You can specify all values by your own or you can build default build and revision // numbers with the '*' character (the default): -[assembly : AssemblyVersion("1.0.*")] +[assembly : AssemblyVersion("1.0.*")] \ No newline at end of file diff --git a/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs b/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs index 8525e75..20bf358 100644 --- a/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs +++ b/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs @@ -128,17 +128,19 @@ namespace OpenSim.Region.Physics.PhysXPlugin public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation) //To be removed { - return this.AddPrimShape(primName, pbs, position, size, rotation, false); + return AddPrimShape(primName, pbs, position, size, rotation, false); } + public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation, bool isPhysical) { return AddPrim(position, size, rotation); } + public override void AddPhysicsActorTaint(PhysicsActor prim) { - } + public override float Simulate(float timeStep) { float fps = 0f; @@ -209,51 +211,61 @@ namespace OpenSim.Region.Physics.PhysXPlugin _acceleration = new PhysicsVector(); _character = character; } + public override int PhysicsActorType { - get { return (int)ActorTypes.Agent; } + get { return (int) ActorTypes.Agent; } set { return; } } + public override bool SetAlwaysRun { get { return false; } set { return; } } + public override bool IsPhysical { get { return false; } set { return; } } + public override bool ThrottleUpdates { get { return false; } set { return; } } + public override bool Flying { get { return flying; } set { flying = value; } } + public override bool IsColliding { get { return iscolliding; } set { iscolliding = value; } } + public override bool CollidingGround { get { return false; } set { return; } } + public override bool CollidingObj { get { return false; } set { return; } } + public override PhysicsVector RotationalVelocity { get { return m_rotationalVelocity; } set { m_rotationalVelocity = value; } } + public override PhysicsVector Position { get { return _position; } @@ -273,22 +285,27 @@ namespace OpenSim.Region.Physics.PhysXPlugin get { return PhysicsVector.Zero; } set { } } + public override float Mass { get { return 0f; } } + public override PhysicsVector Force { get { return PhysicsVector.Zero; } } + public override PhysicsVector CenterOfMass { get { return PhysicsVector.Zero; } } + public override PhysicsVector GeometricCenter { get { return PhysicsVector.Zero; } } + public override PhysicsVector Velocity { get { return _velocity; } @@ -345,23 +362,21 @@ namespace OpenSim.Region.Physics.PhysXPlugin gravityAccel = 0; } } + public override PrimitiveBaseShape Shape { - set - { - return; - } + set { return; } + } + + public void UpdatePosition() + { + Vec3 vec = _character.Position; + _position.X = vec.X; + _position.Y = vec.Y; + _position.Z = vec.Z; } - - public void UpdatePosition() - { - Vec3 vec = this._character.Position; - this._position.X = vec.X; - this._position.Y = vec.Y; - this._position.Z = vec.Z; - } - } - + } + public class PhysXPrim : PhysicsActor { @@ -376,55 +391,62 @@ namespace OpenSim.Region.Physics.PhysXPlugin _acceleration = new PhysicsVector(); _prim = prim; } + public override int PhysicsActorType { - get { return (int)ActorTypes.Prim; } + get { return (int) ActorTypes.Prim; } set { return; } } + public override bool IsPhysical { get { return false; } set { return; } } + public override bool SetAlwaysRun { get { return false; } set { return; } } + public override bool ThrottleUpdates { get { return false; } set { return; } } + public override PhysicsVector RotationalVelocity { get { return m_rotationalVelocity; } set { m_rotationalVelocity = value; } } + public override bool Flying { get { return false; //no flying prims for you } set { } } + public override bool IsColliding { - get - { - return false; - } + get { return false; } set { } } + public override bool CollidingGround { get { return false; } set { return; } } + public override bool CollidingObj { get { return false; } set { return; } } + public override PhysicsVector Position { get @@ -449,75 +471,52 @@ namespace OpenSim.Region.Physics.PhysXPlugin public override PrimitiveBaseShape Shape { - set - { - return; - } + set { return; } } public override PhysicsVector Velocity { - get - { - return _velocity; - } - set - { - _velocity = value; - } + get { return _velocity; } + set { _velocity = value; } } - + public override bool Kinematic { - get - { - return this._prim.Kinematic; - } - set - { - this._prim.Kinematic = value; - } + get { return _prim.Kinematic; } + set { _prim.Kinematic = value; } } - + public override Quaternion Orientation { get { Quaternion res = new Quaternion(); - PhysXWrapper.Quaternion quat = this._prim.GetOrientation(); + PhysXWrapper.Quaternion quat = _prim.GetOrientation(); res.w = quat.W; res.x = quat.X; res.y = quat.Y; res.z = quat.Z; return res; } - set - { - - } + set { } } - + public override PhysicsVector Acceleration { - get - { - return _acceleration; - } - + get { return _acceleration; } } - public void SetAcceleration (PhysicsVector accel) + + public void SetAcceleration(PhysicsVector accel) { - this._acceleration = accel; + _acceleration = accel; } - + public override void AddForce(PhysicsVector force) { - } - + public override void SetMomentum(PhysicsVector momentum) { - } public override PhysicsVector Size @@ -545,6 +544,5 @@ namespace OpenSim.Region.Physics.PhysXPlugin { get { return PhysicsVector.Zero; } } - } -} +} \ No newline at end of file -- cgit v1.1