aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2011-07-12 22:13:15 +0100
committerJustin Clark-Casey (justincc)2011-07-12 22:13:15 +0100
commit3e456163dd284fa04ab17465041a1a27f7b632b9 (patch)
treebaaa8a470f4afa7637e8919d41e161ec4215ce21 /OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs
parenttemporarily fix the build break with building the OdePlugin tests assembly. (diff)
downloadopensim-SC_OLD-3e456163dd284fa04ab17465041a1a27f7b632b9.zip
opensim-SC_OLD-3e456163dd284fa04ab17465041a1a27f7b632b9.tar.gz
opensim-SC_OLD-3e456163dd284fa04ab17465041a1a27f7b632b9.tar.bz2
opensim-SC_OLD-3e456163dd284fa04ab17465041a1a27f7b632b9.tar.xz
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.
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs92
1 files changed, 75 insertions, 17 deletions
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
45 public class ODERayCastRequestManager 45 public class ODERayCastRequestManager
46 { 46 {
47 /// <summary> 47 /// <summary>
48 /// Pending Raycast Requests 48 /// Pending raycast requests
49 /// </summary> 49 /// </summary>
50 protected List<ODERayCastRequest> m_PendingRequests = new List<ODERayCastRequest>(); 50 protected List<ODERayCastRequest> m_PendingRequests = new List<ODERayCastRequest>();
51 51
52 /// <summary> 52 /// <summary>
53 /// Pending ray requests
54 /// </summary>
55 protected List<ODERayRequest> m_PendingRayRequests = new List<ODERayRequest>();
56
57 /// <summary>
53 /// Scene that created this object. 58 /// Scene that created this object.
54 /// </summary> 59 /// </summary>
55 private OdeScene m_scene; 60 private OdeScene m_scene;
@@ -96,6 +101,29 @@ namespace OpenSim.Region.Physics.OdePlugin
96 } 101 }
97 102
98 /// <summary> 103 /// <summary>
104 /// Queues a raycast
105 /// </summary>
106 /// <param name="position">Origin of Ray</param>
107 /// <param name="direction">Ray normal</param>
108 /// <param name="length">Ray length</param>
109 /// <param name="count"></param>
110 /// <param name="retMethod">Return method to send the results</param>
111 public void QueueRequest(Vector3 position, Vector3 direction, float length, int count, RayCallback retMethod)
112 {
113 lock (m_PendingRequests)
114 {
115 ODERayRequest req = new ODERayRequest();
116 req.callbackMethod = retMethod;
117 req.length = length;
118 req.Normal = direction;
119 req.Origin = position;
120 req.Count = count;
121
122 m_PendingRayRequests.Add(req);
123 }
124 }
125
126 /// <summary>
99 /// Process all queued raycast requests 127 /// Process all queued raycast requests
100 /// </summary> 128 /// </summary>
101 /// <returns>Time in MS the raycasts took to process.</returns> 129 /// <returns>Time in MS the raycasts took to process.</returns>
@@ -112,15 +140,23 @@ namespace OpenSim.Region.Physics.OdePlugin
112 if (reqs[i].callbackMethod != null) // quick optimization here, don't raycast 140 if (reqs[i].callbackMethod != null) // quick optimization here, don't raycast
113 RayCast(reqs[i]); // if there isn't anyone to send results 141 RayCast(reqs[i]); // if there isn't anyone to send results
114 } 142 }
115 /* 143
116 foreach (ODERayCastRequest req in m_PendingRequests) 144 m_PendingRequests.Clear();
145 }
146 }
147
148 lock (m_PendingRayRequests)
149 {
150 if (m_PendingRayRequests.Count > 0)
151 {
152 ODERayRequest[] reqs = m_PendingRayRequests.ToArray();
153 for (int i = 0; i < reqs.Length; i++)
117 { 154 {
118 if (req.callbackMethod != null) // quick optimization here, don't raycast 155 if (reqs[i].callbackMethod != null) // quick optimization here, don't raycast
119 RayCast(req); // if there isn't anyone to send results to 156 RayCast(reqs[i]); // if there isn't anyone to send results
120
121 } 157 }
122 */ 158
123 m_PendingRequests.Clear(); 159 m_PendingRayRequests.Clear();
124 } 160 }
125 } 161 }
126 162
@@ -146,7 +182,6 @@ namespace OpenSim.Region.Physics.OdePlugin
146 // Remove Ray 182 // Remove Ray
147 d.GeomDestroy(ray); 183 d.GeomDestroy(ray);
148 184
149
150 // Define default results 185 // Define default results
151 bool hitYN = false; 186 bool hitYN = false;
152 uint hitConsumerID = 0; 187 uint hitConsumerID = 0;
@@ -177,6 +212,31 @@ namespace OpenSim.Region.Physics.OdePlugin
177 req.callbackMethod(hitYN, closestcontact, hitConsumerID, distance, snormal); 212 req.callbackMethod(hitYN, closestcontact, hitConsumerID, distance, snormal);
178 } 213 }
179 214
215 /// <summary>
216 /// Method that actually initiates the raycast
217 /// </summary>
218 /// <param name="req"></param>
219 private void RayCast(ODERayRequest req)
220 {
221 // Create the ray
222 IntPtr ray = d.CreateRay(m_scene.space, req.length);
223 d.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z);
224
225 // Collide test
226 d.SpaceCollide2(m_scene.space, ray, IntPtr.Zero, nearCallback);
227
228 // Remove Ray
229 d.GeomDestroy(ray);
230
231 // Find closest contact and object.
232 lock (m_contactResults)
233 {
234 // Return results
235 if (req.callbackMethod != null)
236 req.callbackMethod(m_contactResults);
237 }
238 }
239
180 // This is the standard Near. Uses space AABBs to speed up detection. 240 // This is the standard Near. Uses space AABBs to speed up detection.
181 private void near(IntPtr space, IntPtr g1, IntPtr g2) 241 private void near(IntPtr space, IntPtr g1, IntPtr g2)
182 { 242 {
@@ -342,10 +402,7 @@ namespace OpenSim.Region.Physics.OdePlugin
342 m_contactResults.Add(collisionresult); 402 m_contactResults.Add(collisionresult);
343 } 403 }
344 } 404 }
345
346
347 } 405 }
348
349 } 406 }
350 407
351 /// <summary> 408 /// <summary>
@@ -365,11 +422,12 @@ namespace OpenSim.Region.Physics.OdePlugin
365 public RaycastCallback callbackMethod; 422 public RaycastCallback callbackMethod;
366 } 423 }
367 424
368 public struct ContactResult 425 public struct ODERayRequest
369 { 426 {
370 public Vector3 Pos; 427 public Vector3 Origin;
371 public float Depth;
372 public uint ConsumerID;
373 public Vector3 Normal; 428 public Vector3 Normal;
429 public int Count;
430 public float length;
431 public RayCallback callbackMethod;
374 } 432 }
375} 433} \ No newline at end of file