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 --- 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 ++++++++++++----------- 4 files changed, 309 insertions(+), 318 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') 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 -- cgit v1.1