From 3e456163dd284fa04ab17465041a1a27f7b632b9 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Tue, 12 Jul 2011 22:13:15 +0100
Subject: Port implementation of llCastRay() from Aurora.
I haven't been able to test this since the viewer won't parse the llCastRay() function. Maybe some activation cap is missing. Could wait until it is activated by default in the viewer.
---
.../Physics/OdePlugin/ODERayCastRequestManager.cs | 92 ++++++++++++++++++----
1 file changed, 75 insertions(+), 17 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs')
diff --git a/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs b/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs
index ba77dae..6c2bdde 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs
@@ -45,11 +45,16 @@ namespace OpenSim.Region.Physics.OdePlugin
public class ODERayCastRequestManager
{
///
- /// Pending Raycast Requests
+ /// Pending raycast requests
///
protected List m_PendingRequests = new List();
///
+ /// Pending ray requests
+ ///
+ protected List m_PendingRayRequests = new List();
+
+ ///
/// Scene that created this object.
///
private OdeScene m_scene;
@@ -96,6 +101,29 @@ namespace OpenSim.Region.Physics.OdePlugin
}
///
+ /// Queues a raycast
+ ///
+ /// Origin of Ray
+ /// Ray normal
+ /// Ray length
+ ///
+ /// Return method to send the results
+ public void QueueRequest(Vector3 position, Vector3 direction, float length, int count, RayCallback retMethod)
+ {
+ lock (m_PendingRequests)
+ {
+ ODERayRequest req = new ODERayRequest();
+ req.callbackMethod = retMethod;
+ req.length = length;
+ req.Normal = direction;
+ req.Origin = position;
+ req.Count = count;
+
+ m_PendingRayRequests.Add(req);
+ }
+ }
+
+ ///
/// Process all queued raycast requests
///
/// Time in MS the raycasts took to process.
@@ -112,15 +140,23 @@ namespace OpenSim.Region.Physics.OdePlugin
if (reqs[i].callbackMethod != null) // quick optimization here, don't raycast
RayCast(reqs[i]); // if there isn't anyone to send results
}
- /*
- foreach (ODERayCastRequest req in m_PendingRequests)
+
+ m_PendingRequests.Clear();
+ }
+ }
+
+ lock (m_PendingRayRequests)
+ {
+ if (m_PendingRayRequests.Count > 0)
+ {
+ ODERayRequest[] reqs = m_PendingRayRequests.ToArray();
+ for (int i = 0; i < reqs.Length; i++)
{
- if (req.callbackMethod != null) // quick optimization here, don't raycast
- RayCast(req); // if there isn't anyone to send results to
-
+ if (reqs[i].callbackMethod != null) // quick optimization here, don't raycast
+ RayCast(reqs[i]); // if there isn't anyone to send results
}
- */
- m_PendingRequests.Clear();
+
+ m_PendingRayRequests.Clear();
}
}
@@ -146,7 +182,6 @@ namespace OpenSim.Region.Physics.OdePlugin
// Remove Ray
d.GeomDestroy(ray);
-
// Define default results
bool hitYN = false;
uint hitConsumerID = 0;
@@ -177,6 +212,31 @@ namespace OpenSim.Region.Physics.OdePlugin
req.callbackMethod(hitYN, closestcontact, hitConsumerID, distance, snormal);
}
+ ///
+ /// Method that actually initiates the raycast
+ ///
+ ///
+ private void RayCast(ODERayRequest req)
+ {
+ // Create the ray
+ IntPtr ray = d.CreateRay(m_scene.space, req.length);
+ d.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z);
+
+ // Collide test
+ d.SpaceCollide2(m_scene.space, ray, IntPtr.Zero, nearCallback);
+
+ // Remove Ray
+ d.GeomDestroy(ray);
+
+ // Find closest contact and object.
+ lock (m_contactResults)
+ {
+ // Return results
+ if (req.callbackMethod != null)
+ req.callbackMethod(m_contactResults);
+ }
+ }
+
// This is the standard Near. Uses space AABBs to speed up detection.
private void near(IntPtr space, IntPtr g1, IntPtr g2)
{
@@ -342,10 +402,7 @@ namespace OpenSim.Region.Physics.OdePlugin
m_contactResults.Add(collisionresult);
}
}
-
-
}
-
}
///
@@ -365,11 +422,12 @@ namespace OpenSim.Region.Physics.OdePlugin
public RaycastCallback callbackMethod;
}
- public struct ContactResult
+ public struct ODERayRequest
{
- public Vector3 Pos;
- public float Depth;
- public uint ConsumerID;
+ public Vector3 Origin;
public Vector3 Normal;
+ public int Count;
+ public float length;
+ public RayCallback callbackMethod;
}
-}
+}
\ No newline at end of file
--
cgit v1.1