From 33d6222e8dc40331e98c3549a040d3d206eed338 Mon Sep 17 00:00:00 2001 From: Charles Krinke Date: Wed, 31 Oct 2007 04:18:34 +0000 Subject: Thank you Teravus, very much, for a 'jump', 'crouch' and 'inertia' patch for all three physics plugins. --- OpenSim/Region/Environment/Scenes/ScenePresence.cs | 39 +++++- .../BasicPhysicsPlugin/BasicPhysicsPlugin.cs | 9 +- .../Region/Physics/BulletXPlugin/BulletXPlugin.cs | 14 ++- OpenSim/Region/Physics/Manager/PhysicsActor.cs | 9 +- OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 132 +++++++++++++++------ OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs | 17 ++- bin/data/avataranimations.xml | 3 + 7 files changed, 180 insertions(+), 43 deletions(-) diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs index 3b73893..b9c723b 100644 --- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs @@ -613,12 +613,27 @@ namespace OpenSim.Region.Environment.Scenes } else { - SendAnimPack(Animations.AnimsLLUUID["WALK"], 1); + if (((m_movementflag & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) && PhysicsActor.IsColliding) + { + SendAnimPack(Animations.AnimsLLUUID["CROUCHWALK"], 1); + } + else + { + SendAnimPack(Animations.AnimsLLUUID["WALK"], 1); + } + } } else { - SendAnimPack(Animations.AnimsLLUUID["STAND"], 1); + if (((m_movementflag & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) && PhysicsActor.IsColliding) + { + SendAnimPack(Animations.AnimsLLUUID["CROUCH"], 1); + } + else + { + SendAnimPack(Animations.AnimsLLUUID["STAND"], 1); + } } } } @@ -638,7 +653,21 @@ namespace OpenSim.Region.Environment.Scenes direc = direc*((0.03f)*128f); if (m_physicsActor.Flying) - direc *= 4; + { direc *= 4; } + else + { + if (!m_physicsActor.Flying && m_physicsActor.IsColliding) + { + //direc.z *= 40; + if (direc.z > 2.0f) + { + direc.z *= 3; + //System.Console.WriteLine("Jump"); + SendAnimPack(Animations.AnimsLLUUID["PRE_JUMP"], 1); + } + + } + } newVelocity.X = direc.x; newVelocity.Y = direc.y; @@ -867,7 +896,7 @@ namespace OpenSim.Region.Environment.Scenes protected void CheckForSignificantMovement() { - if (AbsolutePosition.GetDistanceTo(posLastSignificantMove) > 2.0) + if (AbsolutePosition.GetDistanceTo(posLastSignificantMove) > 0.02) { posLastSignificantMove = AbsolutePosition; if (OnSignificantClientMovement != null) @@ -982,6 +1011,8 @@ namespace OpenSim.Region.Environment.Scenes NewForce force = m_forcesList[i]; m_updateflag = true; + + Velocity = new LLVector3(force.X, force.Y, force.Z); m_newForce = true; } diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs index b412818..c516044 100644 --- a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs +++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs @@ -177,6 +177,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin private PhysicsVector _velocity; private PhysicsVector _acceleration; private bool flying; + private bool iscolliding; public BasicActor() { @@ -191,6 +192,12 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin set { flying = value; } } + public override bool IsColliding + { + get { return iscolliding; } + set { iscolliding = value; } + } + public override PhysicsVector Position { get { return _position; } @@ -239,4 +246,4 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin { } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs b/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs index 1658e2d..8b05295 100644 --- a/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs +++ b/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs @@ -643,6 +643,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin private PhysicsVector _acceleration; private AxiomQuaternion _orientation; private bool flying; + private bool iscolliding = false; private RigidBody rigidBody; public Vector3 RigidBodyPosition @@ -773,6 +774,11 @@ namespace OpenSim.Region.Physics.BulletXPlugin get { return flying; } set { flying = value; } } + public override bool IsColliding + { + get { return iscolliding; } + set { iscolliding = value; } + } public void SetAcceleration(PhysicsVector accel) { @@ -913,6 +919,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin private BulletXScene _parent_scene; //_physical value will be linked with the prim object value private Boolean _physical = false; + private Boolean iscolliding = false; public Vector3 RigidBodyPosition { @@ -1060,6 +1067,11 @@ namespace OpenSim.Region.Physics.BulletXPlugin set { } } + public override bool IsColliding + { + get { return iscolliding; } + set { iscolliding = value; } + } public Boolean Physical { get { return _physical; } @@ -1304,4 +1316,4 @@ namespace OpenSim.Region.Physics.BulletXPlugin return height; } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/Physics/Manager/PhysicsActor.cs b/OpenSim/Region/Physics/Manager/PhysicsActor.cs index b59c13a..74608ef 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsActor.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsActor.cs @@ -59,6 +59,8 @@ namespace OpenSim.Region.Physics.Manager public abstract Quaternion Orientation { get; set; } public abstract bool Flying { get; set; } + + public abstract bool IsColliding { get; set; } public abstract bool Kinematic { get; set; } @@ -103,6 +105,11 @@ namespace OpenSim.Region.Physics.Manager get { return false; } set { return; } } + public override bool IsColliding + { + get { return false; } + set { return; } + } public override bool Kinematic { @@ -120,4 +127,4 @@ namespace OpenSim.Region.Physics.Manager return; } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs index 27c3a6a..4afe784 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs @@ -83,8 +83,10 @@ namespace OpenSim.Region.Physics.OdePlugin private List _characters = new List(); private List _prims = new List(); public Dictionary geom_name_map = new Dictionary(); + public Dictionary actor_name_map = new Dictionary(); private d.ContactGeom[] contacts = new d.ContactGeom[30]; private d.Contact contact; + private PhysicsActor PANull = new NullPhysicsActor(); private float step_time = 0.0f; public IntPtr world; public IntPtr space; @@ -117,36 +119,33 @@ namespace OpenSim.Region.Physics.OdePlugin } _heightmap = new double[258*258]; + } // This function blatantly ripped off from BoxStack.cs private void near(IntPtr space, IntPtr g1, IntPtr g2) { // no lock here! It's invoked from within Simulate(), which is thread-locked + IntPtr b1 = d.GeomGetBody(g1); + IntPtr b2 = d.GeomGetBody(g2); + + if (g1 == g2) return; // Can't collide with yourself + - IntPtr b1 = d.GeomGetBody(g1); - IntPtr b2 = d.GeomGetBody(g2); if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact)) return; + d.GeomClassID id = d.GeomGetClass(g1); if (id == d.GeomClassID.TriMeshClass) { - String name1 = null; - String name2 = null; - if (!geom_name_map.TryGetValue(g1, out name1)) - { - name1 = "null"; - } - if (!geom_name_map.TryGetValue(g2, out name2)) - { - name2 = "null"; - } + -// 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 = d.Collide(g1, g2, contacts.GetLength(0), contacts, d.ContactGeom.SizeOf); @@ -155,6 +154,22 @@ namespace OpenSim.Region.Physics.OdePlugin contact.geom = contacts[i]; IntPtr joint = d.JointCreateContact(world, contactgroup, ref contact); d.JointAttach(joint, b1, b2); + PhysicsActor p1; + PhysicsActor p2; + + + if (!actor_name_map.TryGetValue(g1, out p1)) + { + p1 = PANull; + } + if (!actor_name_map.TryGetValue(g2, out p2)) + { + p2 = PANull; + } + + p1.IsColliding = true; + p2.IsColliding = true; + //System.Console.WriteLine("near: A collision was detected between {1} and {2}", 0, name1, name2); } } @@ -162,10 +177,19 @@ namespace OpenSim.Region.Physics.OdePlugin { foreach (OdeCharacter chr in _characters) { + chr.IsColliding = false; + } + foreach (OdeCharacter chr in _characters) + { + + + d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback); foreach (OdeCharacter ch2 in _characters) /// should be a separate space -- lots of avatars will be N**2 slow - { + { + + d.SpaceCollide2(chr.Shell, ch2.Shell, IntPtr.Zero, nearCallback); } } @@ -333,8 +357,9 @@ namespace OpenSim.Region.Physics.OdePlugin { foreach (OdeCharacter actor in _characters) { - actor.Move(timeStep); + actor.Move(timeStep); } + collision_optimized(); d.WorldQuickStep(world, ODE_STEPSIZE); d.JointGroupEmpty(contactgroup); @@ -457,6 +482,8 @@ namespace OpenSim.Region.Physics.OdePlugin public static float CAPSULE_RADIUS = 0.5f; public static float CAPSULE_LENGTH = 0.9f; private bool flying = false; + private bool iscolliding = false; + private bool jumping = false; //private float gravityAccel; public IntPtr Body; private OdeScene _parent_scene; @@ -480,6 +507,7 @@ namespace OpenSim.Region.Physics.OdePlugin d.GeomSetBody(Shell, Body); } parent_scene.geom_name_map[Shell] = avName; + parent_scene.actor_name_map[Shell] = (PhysicsActor)this; } public override bool Flying @@ -487,7 +515,12 @@ namespace OpenSim.Region.Physics.OdePlugin get { return flying; } set { flying = value; } } - + public override bool IsColliding + { + get { return iscolliding; } + set + {iscolliding = value;} + } public override PhysicsVector Position { get { return _position; } @@ -538,12 +571,35 @@ namespace OpenSim.Region.Physics.OdePlugin public override void AddForce(PhysicsVector force) { + + _target_velocity.X += force.X; + _target_velocity.Y += force.Y; + _target_velocity.Z += force.Z; + + } + public void doForce(PhysicsVector force) + { + d.BodyAddForce(Body, force.X, force.Y, force.Z); + + // ok -- let's stand up straight! + d.Vector3 feet; + d.Vector3 head; + d.BodyGetRelPointPos(Body, 0.0f, 0.0f, -1.0f, out feet); + d.BodyGetRelPointPos(Body, 0.0f, 0.0f, 1.0f, out head); + float posture = head.Z - feet.Z; + // restoring force proportional to lack of posture: + float servo = (2.5f - posture) * POSTURE_SERVO; + d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, servo, 0.0f, 0.0f, 1.0f); + d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, -servo, 0.0f, 0.0f, -1.0f); + + } public override void SetMomentum(PhysicsVector momentum) { - } + } + public void Move(float timeStep) { // no lock; for now it's only called from within Simulate() @@ -551,7 +607,7 @@ namespace OpenSim.Region.Physics.OdePlugin d.Vector3 vel = d.BodyGetLinearVel(Body); // if velocity is zero, use position control; otherwise, velocity control - if (_target_velocity.X == 0.0f & _target_velocity.Y == 0.0f & _target_velocity.Z == 0.0f) + if (_target_velocity.X == 0.0f & _target_velocity.Y == 0.0f & _target_velocity.Z == 0.0f & iscolliding) { // keep track of where we stopped. No more slippin' & slidin' if (!_zeroFlag) @@ -569,9 +625,19 @@ namespace OpenSim.Region.Physics.OdePlugin } else { + _zeroFlag = false; - vec.X = (_target_velocity.X - vel.X)*PID_D; - vec.Y = (_target_velocity.Y - vel.Y)*PID_D; + if (iscolliding || flying) + { + vec.X = (_target_velocity.X - vel.X) * PID_D; + vec.Y = (_target_velocity.Y - vel.Y) * PID_D; + } + if (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; + } + if (flying) { vec.Z = (_target_velocity.Z - vel.Z)*PID_D; @@ -581,19 +647,7 @@ namespace OpenSim.Region.Physics.OdePlugin { vec.Z += 10.0f; } - d.BodyAddForce(Body, vec.X, vec.Y, vec.Z); - - // ok -- let's stand up straight! - d.Vector3 feet; - d.Vector3 head; - d.BodyGetRelPointPos(Body, 0.0f, 0.0f, -1.0f, out feet); - d.BodyGetRelPointPos(Body, 0.0f, 0.0f, 1.0f, out head); - float posture = head.Z - feet.Z; - - // restoring force proportional to lack of posture: - float servo = (2.5f - posture)*POSTURE_SERVO; - d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, servo, 0.0f, 0.0f, 1.0f); - d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, -servo, 0.0f, 0.0f, -1.0f); + doForce(vec); } public void UpdatePositionAndVelocity() @@ -649,6 +703,7 @@ namespace OpenSim.Region.Physics.OdePlugin private OdeScene _parent_scene; public IntPtr prim_geom; public IntPtr _triMeshData; + private bool iscolliding = false; public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size, Quaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) @@ -661,6 +716,7 @@ namespace OpenSim.Region.Physics.OdePlugin _mesh = mesh; _pbs = pbs; _parent_scene = parent_scene; + lock (OdeScene.OdeLock) { @@ -681,6 +737,7 @@ namespace OpenSim.Region.Physics.OdePlugin myrot.Z = rotation.z; d.GeomSetQuaternion(prim_geom, ref myrot); parent_scene.geom_name_map[prim_geom] = primName; + parent_scene.actor_name_map[prim_geom] = (PhysicsActor) this; // don't do .add() here; old geoms get recycled with the same hash } } @@ -708,6 +765,13 @@ namespace OpenSim.Region.Physics.OdePlugin set { } } + public override bool IsColliding + { + get { return iscolliding; } + set { iscolliding = value; } + } + + public override PhysicsVector Position { get { return _position; } @@ -793,4 +857,4 @@ namespace OpenSim.Region.Physics.OdePlugin { } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs b/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs index 4896359..cad66d7 100644 --- a/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs +++ b/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs @@ -182,6 +182,7 @@ namespace OpenSim.Region.Physics.PhysXPlugin private PhysicsVector _acceleration; private NxCharacter _character; private bool flying; + private bool iscolliding = false; private float gravityAccel; public PhysXCharacter(NxCharacter character) @@ -197,6 +198,11 @@ namespace OpenSim.Region.Physics.PhysXPlugin get { return flying; } set { flying = value; } } + public override bool IsColliding + { + get { return iscolliding; } + set { iscolliding = value; } + } public override PhysicsVector Position { @@ -305,7 +311,14 @@ namespace OpenSim.Region.Physics.PhysXPlugin } set { } } - + public override bool IsColliding + { + get + { + return false; //no flying prims for you + } + set { } + } public override PhysicsVector Position { get @@ -379,4 +392,4 @@ namespace OpenSim.Region.Physics.PhysXPlugin { } } -} \ No newline at end of file +} diff --git a/bin/data/avataranimations.xml b/bin/data/avataranimations.xml index 9995311..2238474 100644 --- a/bin/data/avataranimations.xml +++ b/bin/data/avataranimations.xml @@ -8,4 +8,7 @@ 6ed24bd8-91aa-4b12-ccc7-c97c857ab4e0 aec4610c-757f-bc4e-c092-c6e9caf18daf 1a5fe8ac-a804-8a5d-7cbd-56bd83184568 + 7a4e87fe-de39-6fcb-6223-024b00893244 + 201f3fdf-cb1f-dbec-201f-7333e328ae7c + 47f5f6fb-22e5-ae44-f871-73aaaf4a6022 -- cgit v1.1