Thank you Teravus, very much, for a 'jump', 'crouch' and 'inertia' patch for all three physics plugins.

afrisby
Charles Krinke 2007-10-31 04:18:34 +00:00
parent 98b238cf6b
commit 33d6222e8d
7 changed files with 182 additions and 45 deletions

View File

@ -612,9 +612,23 @@ namespace OpenSim.Region.Environment.Scenes
SendAnimPack(Animations.AnimsLLUUID["FLY"], 1); SendAnimPack(Animations.AnimsLLUUID["FLY"], 1);
} }
else else
{
if (((m_movementflag & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) && PhysicsActor.IsColliding)
{
SendAnimPack(Animations.AnimsLLUUID["CROUCHWALK"], 1);
}
else
{ {
SendAnimPack(Animations.AnimsLLUUID["WALK"], 1); SendAnimPack(Animations.AnimsLLUUID["WALK"], 1);
} }
}
}
else
{
if (((m_movementflag & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) && PhysicsActor.IsColliding)
{
SendAnimPack(Animations.AnimsLLUUID["CROUCH"], 1);
} }
else else
{ {
@ -622,6 +636,7 @@ namespace OpenSim.Region.Environment.Scenes
} }
} }
} }
}
protected void AddNewMovement(Vector3 vec, Quaternion rotation) protected void AddNewMovement(Vector3 vec, Quaternion rotation)
@ -638,7 +653,21 @@ namespace OpenSim.Region.Environment.Scenes
direc = direc*((0.03f)*128f); direc = direc*((0.03f)*128f);
if (m_physicsActor.Flying) 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.X = direc.x;
newVelocity.Y = direc.y; newVelocity.Y = direc.y;
@ -867,7 +896,7 @@ namespace OpenSim.Region.Environment.Scenes
protected void CheckForSignificantMovement() protected void CheckForSignificantMovement()
{ {
if (AbsolutePosition.GetDistanceTo(posLastSignificantMove) > 2.0) if (AbsolutePosition.GetDistanceTo(posLastSignificantMove) > 0.02)
{ {
posLastSignificantMove = AbsolutePosition; posLastSignificantMove = AbsolutePosition;
if (OnSignificantClientMovement != null) if (OnSignificantClientMovement != null)
@ -982,6 +1011,8 @@ namespace OpenSim.Region.Environment.Scenes
NewForce force = m_forcesList[i]; NewForce force = m_forcesList[i];
m_updateflag = true; m_updateflag = true;
Velocity = new LLVector3(force.X, force.Y, force.Z); Velocity = new LLVector3(force.X, force.Y, force.Z);
m_newForce = true; m_newForce = true;
} }

View File

@ -177,6 +177,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
private PhysicsVector _velocity; private PhysicsVector _velocity;
private PhysicsVector _acceleration; private PhysicsVector _acceleration;
private bool flying; private bool flying;
private bool iscolliding;
public BasicActor() public BasicActor()
{ {
@ -191,6 +192,12 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
set { flying = value; } set { flying = value; }
} }
public override bool IsColliding
{
get { return iscolliding; }
set { iscolliding = value; }
}
public override PhysicsVector Position public override PhysicsVector Position
{ {
get { return _position; } get { return _position; }

View File

@ -643,6 +643,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
private PhysicsVector _acceleration; private PhysicsVector _acceleration;
private AxiomQuaternion _orientation; private AxiomQuaternion _orientation;
private bool flying; private bool flying;
private bool iscolliding = false;
private RigidBody rigidBody; private RigidBody rigidBody;
public Vector3 RigidBodyPosition public Vector3 RigidBodyPosition
@ -773,6 +774,11 @@ namespace OpenSim.Region.Physics.BulletXPlugin
get { return flying; } get { return flying; }
set { flying = value; } set { flying = value; }
} }
public override bool IsColliding
{
get { return iscolliding; }
set { iscolliding = value; }
}
public void SetAcceleration(PhysicsVector accel) public void SetAcceleration(PhysicsVector accel)
{ {
@ -913,6 +919,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
private BulletXScene _parent_scene; private BulletXScene _parent_scene;
//_physical value will be linked with the prim object value //_physical value will be linked with the prim object value
private Boolean _physical = false; private Boolean _physical = false;
private Boolean iscolliding = false;
public Vector3 RigidBodyPosition public Vector3 RigidBodyPosition
{ {
@ -1060,6 +1067,11 @@ namespace OpenSim.Region.Physics.BulletXPlugin
set { } set { }
} }
public override bool IsColliding
{
get { return iscolliding; }
set { iscolliding = value; }
}
public Boolean Physical public Boolean Physical
{ {
get { return _physical; } get { return _physical; }

View File

@ -60,6 +60,8 @@ namespace OpenSim.Region.Physics.Manager
public abstract bool Flying { get; set; } public abstract bool Flying { get; set; }
public abstract bool IsColliding { get; set; }
public abstract bool Kinematic { get; set; } public abstract bool Kinematic { get; set; }
public abstract void AddForce(PhysicsVector force); public abstract void AddForce(PhysicsVector force);
@ -103,6 +105,11 @@ namespace OpenSim.Region.Physics.Manager
get { return false; } get { return false; }
set { return; } set { return; }
} }
public override bool IsColliding
{
get { return false; }
set { return; }
}
public override bool Kinematic public override bool Kinematic
{ {

View File

@ -83,8 +83,10 @@ namespace OpenSim.Region.Physics.OdePlugin
private List<OdeCharacter> _characters = new List<OdeCharacter>(); private List<OdeCharacter> _characters = new List<OdeCharacter>();
private List<OdePrim> _prims = new List<OdePrim>(); private List<OdePrim> _prims = new List<OdePrim>();
public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>(); public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>();
public Dictionary<IntPtr, PhysicsActor> actor_name_map = new Dictionary<IntPtr, PhysicsActor>();
private d.ContactGeom[] contacts = new d.ContactGeom[30]; private d.ContactGeom[] contacts = new d.ContactGeom[30];
private d.Contact contact; private d.Contact contact;
private PhysicsActor PANull = new NullPhysicsActor();
private float step_time = 0.0f; private float step_time = 0.0f;
public IntPtr world; public IntPtr world;
public IntPtr space; public IntPtr space;
@ -117,36 +119,33 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
_heightmap = new double[258*258]; _heightmap = new double[258*258];
} }
// This function blatantly ripped off from BoxStack.cs // This function blatantly ripped off from BoxStack.cs
private void near(IntPtr space, IntPtr g1, IntPtr g2) private void near(IntPtr space, IntPtr g1, IntPtr g2)
{ {
// no lock here! It's invoked from within Simulate(), which is thread-locked // 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) if (g1 == g2)
return; // Can't collide with yourself 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)) if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact))
return; return;
d.GeomClassID id = d.GeomGetClass(g1); d.GeomClassID id = d.GeomGetClass(g1);
if (id == d.GeomClassID.TriMeshClass) 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); 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]; contact.geom = contacts[i];
IntPtr joint = d.JointCreateContact(world, contactgroup, ref contact); IntPtr joint = d.JointCreateContact(world, contactgroup, ref contact);
d.JointAttach(joint, b1, b2); 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) foreach (OdeCharacter chr in _characters)
{ {
chr.IsColliding = false;
}
foreach (OdeCharacter chr in _characters)
{
d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback); d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback);
foreach (OdeCharacter ch2 in _characters) foreach (OdeCharacter ch2 in _characters)
/// should be a separate space -- lots of avatars will be N**2 slow /// should be a separate space -- lots of avatars will be N**2 slow
{ {
d.SpaceCollide2(chr.Shell, ch2.Shell, IntPtr.Zero, nearCallback); d.SpaceCollide2(chr.Shell, ch2.Shell, IntPtr.Zero, nearCallback);
} }
} }
@ -335,6 +359,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{ {
actor.Move(timeStep); actor.Move(timeStep);
} }
collision_optimized(); collision_optimized();
d.WorldQuickStep(world, ODE_STEPSIZE); d.WorldQuickStep(world, ODE_STEPSIZE);
d.JointGroupEmpty(contactgroup); d.JointGroupEmpty(contactgroup);
@ -457,6 +482,8 @@ namespace OpenSim.Region.Physics.OdePlugin
public static float CAPSULE_RADIUS = 0.5f; public static float CAPSULE_RADIUS = 0.5f;
public static float CAPSULE_LENGTH = 0.9f; public static float CAPSULE_LENGTH = 0.9f;
private bool flying = false; private bool flying = false;
private bool iscolliding = false;
private bool jumping = false;
//private float gravityAccel; //private float gravityAccel;
public IntPtr Body; public IntPtr Body;
private OdeScene _parent_scene; private OdeScene _parent_scene;
@ -480,6 +507,7 @@ namespace OpenSim.Region.Physics.OdePlugin
d.GeomSetBody(Shell, Body); d.GeomSetBody(Shell, Body);
} }
parent_scene.geom_name_map[Shell] = avName; parent_scene.geom_name_map[Shell] = avName;
parent_scene.actor_name_map[Shell] = (PhysicsActor)this;
} }
public override bool Flying public override bool Flying
@ -487,7 +515,12 @@ namespace OpenSim.Region.Physics.OdePlugin
get { return flying; } get { return flying; }
set { flying = value; } set { flying = value; }
} }
public override bool IsColliding
{
get { return iscolliding; }
set
{iscolliding = value;}
}
public override PhysicsVector Position public override PhysicsVector Position
{ {
get { return _position; } get { return _position; }
@ -538,10 +571,33 @@ namespace OpenSim.Region.Physics.OdePlugin
public override void AddForce(PhysicsVector force) 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 override void SetMomentum(PhysicsVector momentum)
{ {
} }
public void Move(float timeStep) public void Move(float timeStep)
@ -551,7 +607,7 @@ namespace OpenSim.Region.Physics.OdePlugin
d.Vector3 vel = d.BodyGetLinearVel(Body); d.Vector3 vel = d.BodyGetLinearVel(Body);
// if velocity is zero, use position control; otherwise, velocity control // 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' // keep track of where we stopped. No more slippin' & slidin'
if (!_zeroFlag) if (!_zeroFlag)
@ -569,9 +625,19 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
else else
{ {
_zeroFlag = false; _zeroFlag = false;
vec.X = (_target_velocity.X - vel.X)*PID_D; if (iscolliding || flying)
vec.Y = (_target_velocity.Y - vel.Y)*PID_D; {
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) if (flying)
{ {
vec.Z = (_target_velocity.Z - vel.Z)*PID_D; vec.Z = (_target_velocity.Z - vel.Z)*PID_D;
@ -581,19 +647,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{ {
vec.Z += 10.0f; vec.Z += 10.0f;
} }
d.BodyAddForce(Body, vec.X, vec.Y, vec.Z); doForce(vec);
// 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 void UpdatePositionAndVelocity() public void UpdatePositionAndVelocity()
@ -649,6 +703,7 @@ namespace OpenSim.Region.Physics.OdePlugin
private OdeScene _parent_scene; private OdeScene _parent_scene;
public IntPtr prim_geom; public IntPtr prim_geom;
public IntPtr _triMeshData; public IntPtr _triMeshData;
private bool iscolliding = false;
public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size, public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size,
Quaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) Quaternion rotation, Mesh mesh, PrimitiveBaseShape pbs)
@ -662,6 +717,7 @@ namespace OpenSim.Region.Physics.OdePlugin
_pbs = pbs; _pbs = pbs;
_parent_scene = parent_scene; _parent_scene = parent_scene;
lock (OdeScene.OdeLock) lock (OdeScene.OdeLock)
{ {
if (mesh != null) if (mesh != null)
@ -681,6 +737,7 @@ namespace OpenSim.Region.Physics.OdePlugin
myrot.Z = rotation.z; myrot.Z = rotation.z;
d.GeomSetQuaternion(prim_geom, ref myrot); d.GeomSetQuaternion(prim_geom, ref myrot);
parent_scene.geom_name_map[prim_geom] = primName; 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 // don't do .add() here; old geoms get recycled with the same hash
} }
} }
@ -708,6 +765,13 @@ namespace OpenSim.Region.Physics.OdePlugin
set { } set { }
} }
public override bool IsColliding
{
get { return iscolliding; }
set { iscolliding = value; }
}
public override PhysicsVector Position public override PhysicsVector Position
{ {
get { return _position; } get { return _position; }

View File

@ -182,6 +182,7 @@ namespace OpenSim.Region.Physics.PhysXPlugin
private PhysicsVector _acceleration; private PhysicsVector _acceleration;
private NxCharacter _character; private NxCharacter _character;
private bool flying; private bool flying;
private bool iscolliding = false;
private float gravityAccel; private float gravityAccel;
public PhysXCharacter(NxCharacter character) public PhysXCharacter(NxCharacter character)
@ -197,6 +198,11 @@ namespace OpenSim.Region.Physics.PhysXPlugin
get { return flying; } get { return flying; }
set { flying = value; } set { flying = value; }
} }
public override bool IsColliding
{
get { return iscolliding; }
set { iscolliding = value; }
}
public override PhysicsVector Position public override PhysicsVector Position
{ {
@ -305,7 +311,14 @@ namespace OpenSim.Region.Physics.PhysXPlugin
} }
set { } set { }
} }
public override bool IsColliding
{
get
{
return false; //no flying prims for you
}
set { }
}
public override PhysicsVector Position public override PhysicsVector Position
{ {
get get

View File

@ -8,4 +8,7 @@
<animation name="WALK">6ed24bd8-91aa-4b12-ccc7-c97c857ab4e0</animation> <animation name="WALK">6ed24bd8-91aa-4b12-ccc7-c97c857ab4e0</animation>
<animation name="FLY">aec4610c-757f-bc4e-c092-c6e9caf18daf</animation> <animation name="FLY">aec4610c-757f-bc4e-c092-c6e9caf18daf</animation>
<animation name="SIT">1a5fe8ac-a804-8a5d-7cbd-56bd83184568</animation> <animation name="SIT">1a5fe8ac-a804-8a5d-7cbd-56bd83184568</animation>
<animation name="PRE_JUMP">7a4e87fe-de39-6fcb-6223-024b00893244</animation>
<animation name="CROUCH">201f3fdf-cb1f-dbec-201f-7333e328ae7c</animation>
<animation name="CROUCHWALK">47f5f6fb-22e5-ae44-f871-73aaaf4a6022</animation>
</animations> </animations>