From 270f7e653aac947120b2b79f774b017041885ea5 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Thu, 27 Jan 2011 11:05:26 -0800 Subject: [PATCH] Add rotationalVelocity and acceleration to variables that are synced in PhysicsActor. Remove unused Prop class. --- .../PhysEngineToSceneConnector.cs | 4 ++ .../SceneToPhysEngineConnector.cs | 4 ++ .../SceneToPhysEngineSyncServer.cs | 5 +- .../Region/Physics/Manager/PhysicsActor.cs | 16 +++++-- .../Region/Physics/OdePlugin/ODECharacter.cs | 1 + OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 1 + .../Region/Physics/PEPlugin/PECharacter.cs | 35 ++++++++------ OpenSim/Region/Physics/PEPlugin/PEPrim.cs | 11 ----- OpenSim/Region/Physics/PEPlugin/Prop.cs | 46 ------------------- 9 files changed, 48 insertions(+), 75 deletions(-) delete mode 100755 OpenSim/Region/Physics/PEPlugin/Prop.cs diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/PhysEngineToSceneConnector.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/PhysEngineToSceneConnector.cs index b1c4a5b59c..8b88ecb1de 100644 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/PhysEngineToSceneConnector.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/PhysEngineToSceneConnector.cs @@ -390,6 +390,8 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule pa.Position = data["position"].AsVector3(); pa.Force = data["force"].AsVector3(); pa.Velocity = data["velocity"].AsVector3(); + pa.RotationalVelocity = data["rotationalVelocity"].AsVector3(); + pa.Acceleration = data["acceleration"].AsVector3(); pa.Torque = data["torque"].AsVector3(); pa.Orientation = data["orientantion"].AsQuaternion(); pa.IsPhysical = data["isPhysical"].AsBoolean(); // receive?? @@ -444,6 +446,8 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule data["position"] = OSD.FromVector3(pa.Position); data["force"] = OSD.FromVector3(pa.Force); data["velocity"] = OSD.FromVector3(pa.Velocity); + data["rotationalVelocity"] = OSD.FromVector3(pa.RotationalVelocity); + data["acceleration"] = OSD.FromVector3(pa.Acceleration); data["torque"] = OSD.FromVector3(pa.Torque); data["orientation"] = OSD.FromQuaternion(pa.Orientation); data["isPhysical"] = OSD.FromBoolean(pa.IsPhysical); diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToPhysEngineConnector.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToPhysEngineConnector.cs index f4e66d54a1..075232d623 100644 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToPhysEngineConnector.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToPhysEngineConnector.cs @@ -350,6 +350,8 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule pa.Position = data["position"].AsVector3(); pa.Force = data["force"].AsVector3(); pa.Velocity = data["velocity"].AsVector3(); + pa.RotationalVelocity = data["rotationalVelocity"].AsVector3(); + pa.Acceleration = data["acceleration"].AsVector3(); pa.Torque = data["torque"].AsVector3(); pa.Orientation = data["orientantion"].AsQuaternion(); pa.IsPhysical = data["isPhysical"].AsBoolean(); // receive?? @@ -402,6 +404,8 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule data["position"] = OSD.FromVector3(pa.Position); data["force"] = OSD.FromVector3(pa.Force); data["velocity"] = OSD.FromVector3(pa.Velocity); + data["rotationalVelocity"] = OSD.FromVector3(pa.RotationalVelocity); + data["acceleration"] = OSD.FromVector3(pa.Acceleration); data["torque"] = OSD.FromVector3(pa.Torque); data["orientation"] = OSD.FromQuaternion(pa.Orientation); data["isPhysical"] = OSD.FromBoolean(pa.IsPhysical); diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToPhysEngineSyncServer.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToPhysEngineSyncServer.cs index 8c61a466da..14b10033f4 100644 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToPhysEngineSyncServer.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToPhysEngineSyncServer.cs @@ -273,7 +273,10 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule public void SendUpdate(PhysicsActor pa) { // m_log.DebugFormat("{0}: SendUpdate for {1}", LogHeader, pa.LocalID); - this.m_sceneToPhysEngineConnector.SendPhysUpdateAttributes(pa); + if (m_sceneToPhysEngineConnector != null) + { + this.m_sceneToPhysEngineConnector.SendPhysUpdateAttributes(pa); + } } #endregion diff --git a/OpenSim/Region/Physics/Manager/PhysicsActor.cs b/OpenSim/Region/Physics/Manager/PhysicsActor.cs index cb205de207..6d578984dd 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsActor.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsActor.cs @@ -127,6 +127,7 @@ namespace OpenSim.Region.Physics.Manager public Vector3 position; public Vector3 force; public Vector3 velocity; + public Vector3 rotationalVelocity; public Vector3 torque; public Quaternion orientation; public Boolean isPhysical; @@ -140,6 +141,7 @@ namespace OpenSim.Region.Physics.Manager if (!AlmostEqual(position, pa.Position)) { position = pa.Position; ret = true; } if (!AlmostEqual(force, pa.Force)) { force = pa.Force; ret = true; } if (!AlmostEqual(velocity, pa.Velocity)) { velocity = pa.Velocity; ret = true; } + if (!AlmostEqual(rotationalVelocity, pa.RotationalVelocity)) { rotationalVelocity = pa.RotationalVelocity; ret = true; } if (!AlmostEqual(torque, pa.Torque)) { torque = pa.Torque; ret = true; } if (orientation != pa.Orientation) { orientation = pa.Orientation; ret = true; } if (isPhysical != pa.IsPhysical) { isPhysical = pa.IsPhysical; ret = true; } @@ -149,9 +151,9 @@ namespace OpenSim.Region.Physics.Manager } private bool AlmostEqual(Vector3 a, Vector3 b) { - if (Math.Abs(a.X - b.X) > 0.001) return false; - if (Math.Abs(a.Y - b.Y) > 0.001) return false; - if (Math.Abs(a.Z - b.Z) > 0.001) return false; + if (Math.Abs(a.X - b.X) > 0.01) return false; + if (Math.Abs(a.Y - b.Y) > 0.01) return false; + if (Math.Abs(a.Z - b.Z) > 0.01) return false; return true; } } @@ -273,7 +275,12 @@ namespace OpenSim.Region.Physics.Manager public abstract Vector3 Velocity { get; set; } public abstract Vector3 Torque { get; set; } public abstract float CollisionScore { get; set;} - public abstract Vector3 Acceleration { get; } + // RA: used to be abstract but made virtual so 'set' does not need to be added to all phys engines + private Vector3 _acceleration; + public virtual Vector3 Acceleration { + get { return _acceleration; } + set { _acceleration = value; } + } public abstract Quaternion Orientation { get; set; } public abstract int PhysicsActorType { get; set; } public abstract bool IsPhysical { get; set; } @@ -471,6 +478,7 @@ namespace OpenSim.Region.Physics.Manager public override Vector3 Acceleration { get { return Vector3.Zero; } + set { } } public override bool IsPhysical diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index 71684a2fbf..194ff9f2ce 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -835,6 +835,7 @@ namespace OpenSim.Region.Physics.OdePlugin public override Vector3 Acceleration { get { return _acceleration; } + set { _acceleration = value; } } public void SetAcceleration(Vector3 accel) diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 1b0feec8c4..7e61e7477f 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -2501,6 +2501,7 @@ Console.WriteLine(" JointCreateFixed"); public override Vector3 Acceleration { get { return _acceleration; } + set { _acceleration = value; } } diff --git a/OpenSim/Region/Physics/PEPlugin/PECharacter.cs b/OpenSim/Region/Physics/PEPlugin/PECharacter.cs index 4bdbcce943..b807e08613 100755 --- a/OpenSim/Region/Physics/PEPlugin/PECharacter.cs +++ b/OpenSim/Region/Physics/PEPlugin/PECharacter.cs @@ -44,7 +44,10 @@ public class PECharacter : PhysicsActor private bool _grabbed; private bool _selected; private Vector3 _position; - private float _mass; + private float _mass = 80f; + public float _density = 60f; + public float CAPSULE_RADIUS = 0.37f; + public float CAPSULE_LENGTH = 2.140599f; private Vector3 _force; private Vector3 _velocity; private Vector3 _torque; @@ -79,6 +82,7 @@ public class PECharacter : PhysicsActor { _position = pos; _size = size; + _density = density; return; } @@ -88,30 +92,25 @@ public class PECharacter : PhysicsActor public override Vector3 Size { get { return _size; } set { _size = value; - Prop.Set(_localID, PropType.Size, _size); } } public override PrimitiveBaseShape Shape { set { _pbs = value; - Prop.Set(_localID, PropType.Shape, _pbs); } } public override uint LocalID { set { _localID = value; - Prop.Set(_localID, PropType.LocalID, _localID); } get { return _localID; } } public override bool Grabbed { set { _grabbed = value; m_log.Debug("[RPE] PEChar set Grabbed"); - Prop.Set(_localID, PropType.Grabbed, _grabbed); } } public override bool Selected { set { _selected = value; m_log.Debug("[RPE] PEChar set Selected"); - Prop.Set(_localID, PropType.Selected, _selected); } } public override void CrossingFailure() { return; } @@ -122,16 +121,18 @@ public class PECharacter : PhysicsActor public override Vector3 Position { get { return _position; } set { _position = value; - Prop.Set(_localID, PropType.Position, _position); } } public override float Mass { - get { return _mass; } + get { + float AVvolume = (float) (Math.PI*Math.Pow(CAPSULE_RADIUS, 2)*CAPSULE_LENGTH); + _mass = _density*AVvolume; + return _mass; + } } public override Vector3 Force { get { return _force; } set { _force = value; - Prop.Set(_localID, PropType.Force, _force); } } @@ -152,19 +153,16 @@ public class PECharacter : PhysicsActor public override Vector3 Velocity { get { return _velocity; } set { _velocity = value; - Prop.Set(_localID, PropType.Velocity, _velocity); } } public override Vector3 Torque { get { return _torque; } set { _torque = value; - Prop.Set(_localID, PropType.Torque, _torque); } } public override float CollisionScore { get { return _collisionScore; } set { _collisionScore = value; - Prop.Set(_localID, PropType.CollisionScore, _collisionScore); } } public override Vector3 Acceleration { @@ -173,7 +171,6 @@ public class PECharacter : PhysicsActor public override Quaternion Orientation { get { return _orientation; } set { _orientation = value; - Prop.Set(_localID, PropType.Orientation, _orientation); } } public override int PhysicsActorType { @@ -261,6 +258,18 @@ public class PECharacter : PhysicsActor public override float APIDDamping { set { return; } } public override void AddForce(Vector3 force, bool pushforce) { + if (force.IsFinite()) + { + // base.ChangingActorID = RegionSyncServerModule.ActorID; + _velocity.X += force.X; + _velocity.Y += force.Y; + _velocity.Z += force.Z; + } + else + { + m_log.Warn("[PHYSICS]: Got a NaN force applied to a Character"); + } + //m_lastUpdateSent = false; } public override void AddAngularForce(Vector3 force, bool pushforce) { } diff --git a/OpenSim/Region/Physics/PEPlugin/PEPrim.cs b/OpenSim/Region/Physics/PEPlugin/PEPrim.cs index 793e098e35..0a930ebe2d 100755 --- a/OpenSim/Region/Physics/PEPlugin/PEPrim.cs +++ b/OpenSim/Region/Physics/PEPlugin/PEPrim.cs @@ -92,34 +92,29 @@ public sealed class PEPrim : PhysicsActor set { _size = value; // m_log.Debug("[REMOTE PRIM ENGINE] PEPrim set Size"); ChangingActorID = RegionSyncServerModule.ActorID; - Prop.Set(_localID, PropType.Size, _size); } } public override PrimitiveBaseShape Shape { set { _pbs = value; m_log.Debug("[REMOTE PRIM ENGINE] PEPrim set Shape"); ChangingActorID = RegionSyncServerModule.ActorID; - Prop.Set(_localID, PropType.Shape, _pbs); } } public override uint LocalID { set { _localID = value; // m_log.Debug("[REMOTE PRIM ENGINE] PEPrim set LocalID"); ChangingActorID = RegionSyncServerModule.ActorID; - Prop.Set(_localID, PropType.LocalID, _localID); } get { return _localID; } } public override bool Grabbed { set { _grabbed = value; m_log.Debug("[REMOTE PRIM ENGINE] PEPrim set Grabbed"); - Prop.Set(_localID, PropType.Grabbed, _grabbed); } } public override bool Selected { set { _selected = value; m_log.Debug("[REMOTE PRIM ENGINE] PEPrim set Selected"); - Prop.Set(_localID, PropType.Selected, _selected); } } public override void CrossingFailure() { return; } @@ -132,7 +127,6 @@ public sealed class PEPrim : PhysicsActor set { _position = value; ChangingActorID = RegionSyncServerModule.ActorID; // m_log.Debug("[REMOTE PRIM ENGINE] PEPrim set Position"); - Prop.Set(_localID, PropType.Position, _position); } } public override float Mass { @@ -143,7 +137,6 @@ public sealed class PEPrim : PhysicsActor set { _force = value; ChangingActorID = RegionSyncServerModule.ActorID; // m_log.Debug("[REMOTE PRIM ENGINE] PEPrim set Force"); - Prop.Set(_localID, PropType.Force, _force); } } @@ -165,21 +158,18 @@ public sealed class PEPrim : PhysicsActor get { return _velocity; } set { _velocity = value; ChangingActorID = RegionSyncServerModule.ActorID; - Prop.Set(_localID, PropType.Velocity, _velocity); } } public override Vector3 Torque { get { return _torque; } set { _torque = value; ChangingActorID = RegionSyncServerModule.ActorID; - Prop.Set(_localID, PropType.Torque, _torque); } } public override float CollisionScore { get { return _collisionScore; } set { _collisionScore = value; ChangingActorID = RegionSyncServerModule.ActorID; - Prop.Set(_localID, PropType.CollisionScore, _collisionScore); } } public override Vector3 Acceleration { @@ -189,7 +179,6 @@ public sealed class PEPrim : PhysicsActor get { return _orientation; } set { _orientation = value; ChangingActorID = RegionSyncServerModule.ActorID; - Prop.Set(_localID, PropType.Orientation, _orientation); } } public override int PhysicsActorType { diff --git a/OpenSim/Region/Physics/PEPlugin/Prop.cs b/OpenSim/Region/Physics/PEPlugin/Prop.cs deleted file mode 100755 index 8b68d69de6..0000000000 --- a/OpenSim/Region/Physics/PEPlugin/Prop.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Collections.Generic; -using OpenMetaverse; -using OpenSim.Framework; -using OpenSim.Region.Physics.Manager; - -namespace OpenSim.Region.Physics.PEPlugin -{ - public enum PropType - { - Size, - Shape, - LocalID, - Grabbed, - Selected, - Position, - Force, - Velocity, - Torque, - CollisionScore, - Orientation - }; - -public class Prop -{ - public static void Set(uint localID, PropType type, uint val) - { - } - public static void Set(uint localID, PropType type, Vector3 val) - { - } - public static void Set(uint localID, PropType type, PrimitiveBaseShape val) - { - } - public static void Set(uint localID, PropType type, bool val) - { - } - public static void Set(uint localID, PropType type, float val) - { - } - public static void Set(uint localID, PropType type, Quaternion val) - { - } - -} -}