From 962dade15596d0aeff3baba0b0b85c17524766c6 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Tue, 22 Jun 2010 04:04:59 +0200 Subject: [PATCH] Cause collisions with the avatar to be sent to attachments. Currently ignores collision filter. Physics collisions are still dodgy, so we don't get the events we should be getting. --- .../Region/Framework/Scenes/ScenePresence.cs | 140 ++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index a376ab13a1..654e9cee85 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -228,6 +228,7 @@ namespace OpenSim.Region.Framework.Scenes private int m_updateCount = 0; //KF: Update Anims for a while private static readonly int UPDATE_COUNT = 10; // how many frames to update for private const int NumMovementsBetweenRayCast = 5; + private List m_lastColliders = new List(); private bool CameraConstraintActive; //private int m_moveToPositionStateStatus; @@ -3595,6 +3596,145 @@ Console.WriteLine("Scripted Sit ofset {0}", m_pos); } } + List thisHitColliders = new List(); + List endedColliders = new List(); + List startedColliders = new List(); + + foreach (uint localid in coldata.Keys) + { + thisHitColliders.Add(localid); + if (!m_lastColliders.Contains(localid)) + { + startedColliders.Add(localid); + } + //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString()); + } + + // calculate things that ended colliding + foreach (uint localID in m_lastColliders) + { + if (!thisHitColliders.Contains(localID)) + { + endedColliders.Add(localID); + } + } + //add the items that started colliding this time to the last colliders list. + foreach (uint localID in startedColliders) + { + m_lastColliders.Add(localID); + } + // remove things that ended colliding from the last colliders list + foreach (uint localID in endedColliders) + { + m_lastColliders.Remove(localID); + } + + // do event notification + if (startedColliders.Count > 0) + { + ColliderArgs StartCollidingMessage = new ColliderArgs(); + List colliding = new List(); + foreach (uint localId in startedColliders) + { + if (localId == 0) + continue; + + SceneObjectPart obj = Scene.GetSceneObjectPart(localId); + string data = ""; + if (obj != null) + { + DetectedObject detobj = new DetectedObject(); + detobj.keyUUID = obj.UUID; + detobj.nameStr = obj.Name; + detobj.ownerUUID = obj.OwnerID; + detobj.posVector = obj.AbsolutePosition; + detobj.rotQuat = obj.GetWorldRotation(); + detobj.velVector = obj.Velocity; + detobj.colliderType = 0; + detobj.groupUUID = obj.GroupID; + colliding.Add(detobj); + } + } + + if (colliding.Count > 0) + { + StartCollidingMessage.Colliders = colliding; + + foreach (SceneObjectGroup att in Attachments) + Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage); + } + } + + if (endedColliders.Count > 0) + { + ColliderArgs EndCollidingMessage = new ColliderArgs(); + List colliding = new List(); + foreach (uint localId in endedColliders) + { + if (localId == 0) + continue; + + SceneObjectPart obj = Scene.GetSceneObjectPart(localId); + string data = ""; + if (obj != null) + { + DetectedObject detobj = new DetectedObject(); + detobj.keyUUID = obj.UUID; + detobj.nameStr = obj.Name; + detobj.ownerUUID = obj.OwnerID; + detobj.posVector = obj.AbsolutePosition; + detobj.rotQuat = obj.GetWorldRotation(); + detobj.velVector = obj.Velocity; + detobj.colliderType = 0; + detobj.groupUUID = obj.GroupID; + colliding.Add(detobj); + } + } + + if (colliding.Count > 0) + { + EndCollidingMessage.Colliders = colliding; + + foreach (SceneObjectGroup att in Attachments) + Scene.EventManager.TriggerScriptCollidingEnd(att.LocalId, EndCollidingMessage); + } + } + + if (thisHitColliders.Count > 0) + { + ColliderArgs CollidingMessage = new ColliderArgs(); + List colliding = new List(); + foreach (uint localId in thisHitColliders) + { + if (localId == 0) + continue; + + SceneObjectPart obj = Scene.GetSceneObjectPart(localId); + string data = ""; + if (obj != null) + { + DetectedObject detobj = new DetectedObject(); + detobj.keyUUID = obj.UUID; + detobj.nameStr = obj.Name; + detobj.ownerUUID = obj.OwnerID; + detobj.posVector = obj.AbsolutePosition; + detobj.rotQuat = obj.GetWorldRotation(); + detobj.velVector = obj.Velocity; + detobj.colliderType = 0; + detobj.groupUUID = obj.GroupID; + colliding.Add(detobj); + } + } + + if (colliding.Count > 0) + { + CollidingMessage.Colliders = colliding; + + foreach (SceneObjectGroup att in Attachments) + Scene.EventManager.TriggerScriptColliding(att.LocalId, CollidingMessage); + } + } + if (m_invulnerable) return;