* Preliminary work with the ODEPlugin to collect collision data.

0.6.0-stable
Teravus Ovares 2008-03-14 05:22:52 +00:00
parent 94c39c793a
commit abacfba287
9 changed files with 196 additions and 18 deletions

View File

@ -545,6 +545,9 @@ namespace OpenSim.Region.Environment.Scenes
new Quaternion(dupe.RootPart.RotationOffset.W, dupe.RootPart.RotationOffset.X, new Quaternion(dupe.RootPart.RotationOffset.W, dupe.RootPart.RotationOffset.X,
dupe.RootPart.RotationOffset.Y, dupe.RootPart.RotationOffset.Z), dupe.RootPart.RotationOffset.Y, dupe.RootPart.RotationOffset.Z),
dupe.RootPart.PhysActor.IsPhysical); dupe.RootPart.PhysActor.IsPhysical);
dupe.RootPart.PhysActor.LocalID = dupe.RootPart.LocalId;
dupe.RootPart.DoPhysicsPropertyUpdate(dupe.RootPart.PhysActor.IsPhysical, true); dupe.RootPart.DoPhysicsPropertyUpdate(dupe.RootPart.PhysActor.IsPhysical, true);
} }
// Now we've made a copy that replaces this one, we need to // Now we've made a copy that replaces this one, we need to

View File

@ -785,7 +785,7 @@ namespace OpenSim.Region.Environment.Scenes
new PhysicsVector(Scale.X, Scale.Y, Scale.Z), new PhysicsVector(Scale.X, Scale.Y, Scale.Z),
new Quaternion(RotationOffset.W, RotationOffset.X, new Quaternion(RotationOffset.W, RotationOffset.X,
RotationOffset.Y, RotationOffset.Z), RigidBody); RotationOffset.Y, RotationOffset.Z), RigidBody);
PhysActor.LocalID = LocalId;
DoPhysicsPropertyUpdate(RigidBody, true); DoPhysicsPropertyUpdate(RigidBody, true);
} }
@ -1305,6 +1305,7 @@ namespace OpenSim.Region.Environment.Scenes
new PhysicsVector(Scale.X, Scale.Y, Scale.Z), new PhysicsVector(Scale.X, Scale.Y, Scale.Z),
new Quaternion(RotationOffset.W, RotationOffset.X, new Quaternion(RotationOffset.W, RotationOffset.X,
RotationOffset.Y, RotationOffset.Z), usePhysics); RotationOffset.Y, RotationOffset.Z), usePhysics);
PhysActor.LocalID = LocalId;
DoPhysicsPropertyUpdate(usePhysics, true); DoPhysicsPropertyUpdate(usePhysics, true);
} }
else else

View File

@ -1809,6 +1809,7 @@ namespace OpenSim.Region.Environment.Scenes
} }
//m_physicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; //m_physicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients;
m_physicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; m_physicsActor.OnCollisionUpdate += PhysicsCollisionUpdate;
m_physicsActor.LocalID = LocalId;
} }
// Event called by the physics plugin to tell the avatar about a collision. // Event called by the physics plugin to tell the avatar about a collision.

View File

@ -90,6 +90,7 @@ namespace OpenSim.Region.Environment.Scenes
new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z), new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z),
new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X, new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X,
rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics); rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics);
rootPart.PhysActor.LocalID = rootPart.LocalId;
rootPart.DoPhysicsPropertyUpdate(UsePhysics, true); rootPart.DoPhysicsPropertyUpdate(UsePhysics, true);
} }
primCount++; primCount++;
@ -192,6 +193,9 @@ namespace OpenSim.Region.Environment.Scenes
new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z), new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z),
new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X, new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X,
rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics); rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics);
rootPart.PhysActor.LocalID = rootPart.LocalId;
rootPart.DoPhysicsPropertyUpdate(UsePhysics, true); rootPart.DoPhysicsPropertyUpdate(UsePhysics, true);
rootPart.Velocity = receivedVelocity; rootPart.Velocity = receivedVelocity;
} }

View File

@ -52,28 +52,28 @@ namespace OpenSim.Region.Physics.Manager
public int m_colliderType; public int m_colliderType;
public bool m_startOrEnd; public int m_GenericStartEnd;
//public uint m_LocalID; //public uint m_LocalID;
public List<uint> m_objCollisionList; public List<uint> m_objCollisionList;
public CollisionEventUpdate(uint localID, int colliderType, bool startOrEnd, List<uint> objCollisionList) public CollisionEventUpdate(uint localID, int colliderType, int GenericStartEnd, List<uint> objCollisionList)
{ {
m_colliderType = colliderType; m_colliderType = colliderType;
m_startOrEnd = startOrEnd; m_GenericStartEnd = GenericStartEnd;
m_objCollisionList = objCollisionList; m_objCollisionList = objCollisionList;
} }
public CollisionEventUpdate(bool startOrEnd) public CollisionEventUpdate(bool startOrEnd)
{ {
m_colliderType = (int) ActorTypes.Unknown; m_colliderType = (int) ActorTypes.Unknown;
m_startOrEnd = startOrEnd; m_GenericStartEnd = m_GenericStartEnd;
m_objCollisionList = null; m_objCollisionList = null;
} }
public CollisionEventUpdate() public CollisionEventUpdate()
{ {
m_colliderType = (int) ActorTypes.Unknown; m_colliderType = (int) ActorTypes.Unknown;
m_startOrEnd = false; m_GenericStartEnd = 1;
m_objCollisionList = null; m_objCollisionList = null;
} }
@ -83,10 +83,10 @@ namespace OpenSim.Region.Physics.Manager
set { m_colliderType = value; } set { m_colliderType = value; }
} }
public bool startOrEnd public int GenericStartEnd
{ {
get { return m_startOrEnd; } get { return m_GenericStartEnd; }
set { m_startOrEnd = value; } set { m_GenericStartEnd = value; }
} }
public void addCollider(uint localID) public void addCollider(uint localID)

View File

@ -86,6 +86,7 @@ namespace OpenSim.Region.Physics.OdePlugin
private bool m_hackSentFall = false; private bool m_hackSentFall = false;
private bool m_hackSentFly = false; private bool m_hackSentFly = false;
public uint m_localID = 0; public uint m_localID = 0;
public bool m_returnCollisions = false;
private float m_buoyancy = 0f; private float m_buoyancy = 0f;

View File

@ -61,6 +61,7 @@ namespace OpenSim.Region.Physics.OdePlugin
private bool m_taintPhysics = false; private bool m_taintPhysics = false;
private bool m_collidesLand = true; private bool m_collidesLand = true;
private bool m_collidesWater = false; private bool m_collidesWater = false;
public bool m_returnCollisions = false;
// Default we're a Geometry // Default we're a Geometry
private CollisionCategories m_collisionCategories = (CollisionCategories.Geom ); private CollisionCategories m_collisionCategories = (CollisionCategories.Geom );
@ -203,7 +204,9 @@ namespace OpenSim.Region.Physics.OdePlugin
public override uint LocalID public override uint LocalID
{ {
set { m_localID = value; } set {
//m_log.Info("[PHYSICS]: Setting TrackerID: " + value);
m_localID = value; }
} }
public override bool Grabbed public override bool Grabbed

View File

@ -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] [Flags]
public enum CollisionCategories : int public enum CollisionCategories : int
{ {
@ -97,6 +116,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public class OdeScene : PhysicsScene public class OdeScene : PhysicsScene
{ {
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private Dictionary<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>();
CollisionLocker ode; CollisionLocker ode;
@ -110,6 +130,8 @@ namespace OpenSim.Region.Physics.OdePlugin
private float waterlevel = 0f; private float waterlevel = 0f;
private int framecount = 0; private int framecount = 0;
private int m_returncollisions = 10;
private IntPtr contactgroup; private IntPtr contactgroup;
private IntPtr LandGeom = (IntPtr) 0; private IntPtr LandGeom = (IntPtr) 0;
@ -146,10 +168,20 @@ namespace OpenSim.Region.Physics.OdePlugin
private float step_time = 0.0f; private float step_time = 0.0f;
private int ms = 0; private int ms = 0;
public IntPtr world; 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; public IntPtr space;
private IntPtr tmpSpace; //private IntPtr tmpSpace;
// split static geometry collision handling into spaces of 30 meters // 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)];
@ -357,10 +389,10 @@ namespace OpenSim.Region.Physics.OdePlugin
lock (contacts) lock (contacts)
{ {
if (g1 == (IntPtr)0) //if (g1 == (IntPtr)0)
m_log.Info("g1=0"); //m_log.Info("g1=0");
if (g2 == (IntPtr)0) //if (g2 == (IntPtr)0)
m_log.Info("g2=0"); //m_log.Info("g2=0");
count = d.Collide(g1, g2, contacts.GetLength(0), contacts, d.ContactGeom.SizeOf); 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' // We only need to test p2 for 'jump crouch purposes'
p2.IsColliding = true; p2.IsColliding = true;
if ((framecount % m_returncollisions) == 0)
collision_accounting_events(p1, p2);
switch (p1.PhysicsActorType) switch (p1.PhysicsActorType)
{ {
case (int)ActorTypes.Agent: case (int)ActorTypes.Agent:
@ -437,6 +473,8 @@ namespace OpenSim.Region.Physics.OdePlugin
(p1.PhysicsActorType == (int) ActorTypes.Agent && (p1.PhysicsActorType == (int) ActorTypes.Agent &&
p2.PhysicsActorType == (int) ActorTypes.Prim)) p2.PhysicsActorType == (int) ActorTypes.Prim))
{ {
# region disabled code1 # region disabled code1
//contacts[i].depth = contacts[i].depth * 4.15f; //contacts[i].depth = contacts[i].depth * 4.15f;
/* /*
@ -472,6 +510,7 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
*/ */
#endregion #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) public int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount)
{ {
/* String name1 = null; /* String name1 = null;

View File

@ -134,17 +134,17 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public void collision_start(uint localID, LLUUID itemID) 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) 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) 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) public void land_collision_start(uint localID, LLUUID itemID)