From abacfba287efe89ead9bff529d62f65a253eceb8 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Fri, 14 Mar 2008 05:22:52 +0000 Subject: * Preliminary work with the ODEPlugin to collect collision data. --- .../Region/Environment/Scenes/SceneObjectGroup.cs | 3 + .../Region/Environment/Scenes/SceneObjectPart.cs | 3 +- OpenSim/Region/Environment/Scenes/ScenePresence.cs | 1 + .../Region/Environment/Scenes/SceneXmlLoader.cs | 4 + OpenSim/Region/Physics/Manager/PhysicsActor.cs | 16 +- OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 1 + OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 5 +- OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 175 ++++++++++++++++++++- .../Common/ScriptEngineBase/EventManager.cs | 6 +- 9 files changed, 196 insertions(+), 18 deletions(-) diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs index 1f4cdd5..041dc4e 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs @@ -545,6 +545,9 @@ namespace OpenSim.Region.Environment.Scenes new Quaternion(dupe.RootPart.RotationOffset.W, dupe.RootPart.RotationOffset.X, dupe.RootPart.RotationOffset.Y, dupe.RootPart.RotationOffset.Z), dupe.RootPart.PhysActor.IsPhysical); + + dupe.RootPart.PhysActor.LocalID = dupe.RootPart.LocalId; + dupe.RootPart.DoPhysicsPropertyUpdate(dupe.RootPart.PhysActor.IsPhysical, true); } // Now we've made a copy that replaces this one, we need to diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs index b708d04..ffb9d36 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs @@ -785,7 +785,7 @@ namespace OpenSim.Region.Environment.Scenes new PhysicsVector(Scale.X, Scale.Y, Scale.Z), new Quaternion(RotationOffset.W, RotationOffset.X, RotationOffset.Y, RotationOffset.Z), RigidBody); - + PhysActor.LocalID = LocalId; DoPhysicsPropertyUpdate(RigidBody, true); } @@ -1305,6 +1305,7 @@ namespace OpenSim.Region.Environment.Scenes new PhysicsVector(Scale.X, Scale.Y, Scale.Z), new Quaternion(RotationOffset.W, RotationOffset.X, RotationOffset.Y, RotationOffset.Z), usePhysics); + PhysActor.LocalID = LocalId; DoPhysicsPropertyUpdate(usePhysics, true); } else diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs index 2f35fe3..1731cd9 100644 --- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs @@ -1809,6 +1809,7 @@ namespace OpenSim.Region.Environment.Scenes } //m_physicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; m_physicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; + m_physicsActor.LocalID = LocalId; } // Event called by the physics plugin to tell the avatar about a collision. diff --git a/OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs b/OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs index 2b05bb6..8666862 100644 --- a/OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs +++ b/OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs @@ -90,6 +90,7 @@ namespace OpenSim.Region.Environment.Scenes new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z), new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X, rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics); + rootPart.PhysActor.LocalID = rootPart.LocalId; rootPart.DoPhysicsPropertyUpdate(UsePhysics, true); } primCount++; @@ -192,6 +193,9 @@ namespace OpenSim.Region.Environment.Scenes new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z), new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X, rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics); + + rootPart.PhysActor.LocalID = rootPart.LocalId; + rootPart.DoPhysicsPropertyUpdate(UsePhysics, true); rootPart.Velocity = receivedVelocity; } diff --git a/OpenSim/Region/Physics/Manager/PhysicsActor.cs b/OpenSim/Region/Physics/Manager/PhysicsActor.cs index 2a35d43..9b8e1e1 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsActor.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsActor.cs @@ -52,28 +52,28 @@ namespace OpenSim.Region.Physics.Manager public int m_colliderType; - public bool m_startOrEnd; + public int m_GenericStartEnd; //public uint m_LocalID; public List m_objCollisionList; - public CollisionEventUpdate(uint localID, int colliderType, bool startOrEnd, List objCollisionList) + public CollisionEventUpdate(uint localID, int colliderType, int GenericStartEnd, List objCollisionList) { m_colliderType = colliderType; - m_startOrEnd = startOrEnd; + m_GenericStartEnd = GenericStartEnd; m_objCollisionList = objCollisionList; } public CollisionEventUpdate(bool startOrEnd) { m_colliderType = (int) ActorTypes.Unknown; - m_startOrEnd = startOrEnd; + m_GenericStartEnd = m_GenericStartEnd; m_objCollisionList = null; } public CollisionEventUpdate() { m_colliderType = (int) ActorTypes.Unknown; - m_startOrEnd = false; + m_GenericStartEnd = 1; m_objCollisionList = null; } @@ -83,10 +83,10 @@ namespace OpenSim.Region.Physics.Manager set { m_colliderType = value; } } - public bool startOrEnd + public int GenericStartEnd { - get { return m_startOrEnd; } - set { m_startOrEnd = value; } + get { return m_GenericStartEnd; } + set { m_GenericStartEnd = value; } } public void addCollider(uint localID) diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index 9bbbb22..dc12a9a 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -86,6 +86,7 @@ namespace OpenSim.Region.Physics.OdePlugin private bool m_hackSentFall = false; private bool m_hackSentFly = false; public uint m_localID = 0; + public bool m_returnCollisions = false; private float m_buoyancy = 0f; diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 6a38037..5370ddd 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -61,6 +61,7 @@ namespace OpenSim.Region.Physics.OdePlugin private bool m_taintPhysics = false; private bool m_collidesLand = true; private bool m_collidesWater = false; + public bool m_returnCollisions = false; // Default we're a Geometry private CollisionCategories m_collisionCategories = (CollisionCategories.Geom ); @@ -203,7 +204,9 @@ namespace OpenSim.Region.Physics.OdePlugin public override uint LocalID { - set { m_localID = value; } + set { + //m_log.Info("[PHYSICS]: Setting TrackerID: " + value); + m_localID = value; } } public override bool Grabbed diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs index 9f160a5..31627b6 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs @@ -79,6 +79,25 @@ namespace OpenSim.Region.Physics.OdePlugin } } + + public enum StatusIndicators : int + { + Generic = 0, + Start = 1, + End = 2 + } + + + public struct sCollisionData + { + public uint ColliderLocalId; + public uint CollidedWithLocalId; + public int NumberOfCollisions; + public int CollisionType; + public int StatusIndicator; + public int lastframe; + } + [Flags] public enum CollisionCategories : int { @@ -97,6 +116,7 @@ namespace OpenSim.Region.Physics.OdePlugin public class OdeScene : PhysicsScene { private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + private Dictionary m_storedCollisions = new Dictionary(); CollisionLocker ode; @@ -110,6 +130,8 @@ namespace OpenSim.Region.Physics.OdePlugin private float waterlevel = 0f; private int framecount = 0; + private int m_returncollisions = 10; + private IntPtr contactgroup; private IntPtr LandGeom = (IntPtr) 0; @@ -146,10 +168,20 @@ namespace OpenSim.Region.Physics.OdePlugin private float step_time = 0.0f; private int ms = 0; public IntPtr world; + private bool returncollisions = false; + private uint obj1LocalID = 0; + private uint obj2LocalID = 0; + private int ctype = 0; + private OdeCharacter cc1; + private OdePrim cp1; + private OdeCharacter cc2; + private OdePrim cp2; + private int cStartStop = 0; + private string cDictKey = ""; public IntPtr space; - private IntPtr tmpSpace; + //private IntPtr tmpSpace; // split static geometry collision handling into spaces of 30 meters public IntPtr[,] staticPrimspace = new IntPtr[(int) (300/metersInSpace),(int) (300/metersInSpace)]; @@ -357,10 +389,10 @@ namespace OpenSim.Region.Physics.OdePlugin lock (contacts) { - if (g1 == (IntPtr)0) - m_log.Info("g1=0"); - if (g2 == (IntPtr)0) - m_log.Info("g2=0"); + //if (g1 == (IntPtr)0) + //m_log.Info("g1=0"); + //if (g2 == (IntPtr)0) + //m_log.Info("g2=0"); count = d.Collide(g1, g2, contacts.GetLength(0), contacts, d.ContactGeom.SizeOf); } @@ -400,6 +432,10 @@ namespace OpenSim.Region.Physics.OdePlugin // We only need to test p2 for 'jump crouch purposes' p2.IsColliding = true; + if ((framecount % m_returncollisions) == 0) + collision_accounting_events(p1, p2); + + switch (p1.PhysicsActorType) { case (int)ActorTypes.Agent: @@ -437,6 +473,8 @@ namespace OpenSim.Region.Physics.OdePlugin (p1.PhysicsActorType == (int) ActorTypes.Agent && p2.PhysicsActorType == (int) ActorTypes.Prim)) { + + # region disabled code1 //contacts[i].depth = contacts[i].depth * 4.15f; /* @@ -472,6 +510,7 @@ namespace OpenSim.Region.Physics.OdePlugin } */ #endregion + } @@ -651,6 +690,132 @@ namespace OpenSim.Region.Physics.OdePlugin } + private void collision_accounting_events(PhysicsActor p1, PhysicsActor p2) + { + obj1LocalID = 0; + returncollisions = false; + obj2LocalID = 0; + ctype = 0; + cStartStop = 0; + + switch ((ActorTypes)p2.PhysicsActorType) + { + case ActorTypes.Agent: + cc2 = (OdeCharacter)p2; + if (cc2.m_returnCollisions) + { + obj1LocalID = cc2.m_localID; + switch ((ActorTypes)p1.PhysicsActorType) + { + case ActorTypes.Agent: + cc1 = (OdeCharacter)p1; + obj2LocalID = cc1.m_localID; + ctype = (int)CollisionCategories.Character; + + if (cc1.CollidingObj) + cStartStop = (int)StatusIndicators.Generic; + else + cStartStop = (int)StatusIndicators.Start; + + returncollisions = true; + break; + case ActorTypes.Prim: + cp1 = (OdePrim)p1; + obj2LocalID = cp1.m_localID; + ctype = (int)CollisionCategories.Geom; + + if (cp1.CollidingObj) + cStartStop = (int)StatusIndicators.Generic; + else + cStartStop = (int)StatusIndicators.Start; + + returncollisions = true; + break; + + case ActorTypes.Ground: + case ActorTypes.Unknown: + obj2LocalID = 0; + ctype = (int)CollisionCategories.Land; + returncollisions = true; + break; + } + + + } + + break; + case ActorTypes.Prim: + cp2 = (OdePrim)p2; + if (cp2.m_returnCollisions) + { + obj1LocalID = cp2.m_localID; + switch ((ActorTypes)p1.PhysicsActorType) + { + case ActorTypes.Agent: + cc1 = (OdeCharacter)p1; + obj2LocalID = cc1.m_localID; + ctype = (int)CollisionCategories.Character; + + if (cc1.CollidingObj) + cStartStop = (int)StatusIndicators.Generic; + else + cStartStop = (int)StatusIndicators.Start; + returncollisions = true; + + break; + case ActorTypes.Prim: + cp1 = (OdePrim)p1; + obj2LocalID = cp1.m_localID; + ctype = (int)CollisionCategories.Geom; + + if (cp1.CollidingObj) + cStartStop = (int)StatusIndicators.Generic; + else + cStartStop = (int)StatusIndicators.Start; + + returncollisions = true; + break; + + case ActorTypes.Ground: + case ActorTypes.Unknown: + obj2LocalID = 0; + ctype = (int)CollisionCategories.Land; + + returncollisions = true; + break; + } + } + + break; + } + if (returncollisions) + { + + lock (m_storedCollisions) + { + cDictKey = obj1LocalID.ToString() + obj2LocalID.ToString() + cStartStop.ToString() + ctype.ToString(); + if (m_storedCollisions.ContainsKey(cDictKey)) + { + sCollisionData objd = m_storedCollisions[cDictKey]; + objd.NumberOfCollisions += 1; + objd.lastframe = framecount; + m_storedCollisions[cDictKey] = objd; + } + else + { + sCollisionData objd = new sCollisionData(); + objd.ColliderLocalId = obj1LocalID; + objd.CollidedWithLocalId = obj2LocalID; + objd.CollisionType = ctype; + objd.NumberOfCollisions = 1; + objd.lastframe = framecount; + objd.StatusIndicator = cStartStop; + m_storedCollisions.Add(cDictKey, objd); + } + } + } + } + public int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount) { /* String name1 = null; diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventManager.cs index b091e04..efd9894 100644 --- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventManager.cs +++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventManager.cs @@ -134,17 +134,17 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase public void collision_start(uint localID, LLUUID itemID) { - myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "collision_start", EventQueueManager.llDetectNull); + myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "collision_start", EventQueueManager.llDetectNull, new object[] { (int)1 }); } public void collision(uint localID, LLUUID itemID) { - myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "collision", EventQueueManager.llDetectNull); + myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "collision", EventQueueManager.llDetectNull, new object[] { (int)1 }); } public void collision_end(uint localID, LLUUID itemID) { - myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "collision_end", EventQueueManager.llDetectNull); + myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "collision_end", EventQueueManager.llDetectNull, new object[] { (int)1 }); } public void land_collision_start(uint localID, LLUUID itemID) -- cgit v1.1