diff options
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs')
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs | 110 |
1 files changed, 88 insertions, 22 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs b/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs index ba77dae..7e3ec63 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> |
@@ -109,18 +137,33 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
109 | ODERayCastRequest[] reqs = m_PendingRequests.ToArray(); | 137 | ODERayCastRequest[] reqs = m_PendingRequests.ToArray(); |
110 | for (int i = 0; i < reqs.Length; i++) | 138 | for (int i = 0; i < reqs.Length; i++) |
111 | { | 139 | { |
112 | if (reqs[i].callbackMethod != null) // quick optimization here, don't raycast | 140 | try |
113 | RayCast(reqs[i]); // if there isn't anyone to send results | 141 | { |
142 | if (reqs[i].callbackMethod != null) // quick optimization here, don't raycast | ||
143 | RayCast(reqs[i]); // if there isn't anyone to send results | ||
144 | } | ||
145 | catch | ||
146 | { | ||
147 | //Fail silently | ||
148 | } | ||
114 | } | 149 | } |
115 | /* | 150 | |
116 | foreach (ODERayCastRequest req in m_PendingRequests) | 151 | m_PendingRequests.Clear(); |
152 | } | ||
153 | } | ||
154 | |||
155 | lock (m_PendingRayRequests) | ||
156 | { | ||
157 | if (m_PendingRayRequests.Count > 0) | ||
158 | { | ||
159 | ODERayRequest[] reqs = m_PendingRayRequests.ToArray(); | ||
160 | for (int i = 0; i < reqs.Length; i++) | ||
117 | { | 161 | { |
118 | if (req.callbackMethod != null) // quick optimization here, don't raycast | 162 | if (reqs[i].callbackMethod != null) // quick optimization here, don't raycast |
119 | RayCast(req); // if there isn't anyone to send results to | 163 | RayCast(reqs[i]); // if there isn't anyone to send results |
120 | |||
121 | } | 164 | } |
122 | */ | 165 | |
123 | m_PendingRequests.Clear(); | 166 | m_PendingRayRequests.Clear(); |
124 | } | 167 | } |
125 | } | 168 | } |
126 | 169 | ||
@@ -146,7 +189,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
146 | // Remove Ray | 189 | // Remove Ray |
147 | d.GeomDestroy(ray); | 190 | d.GeomDestroy(ray); |
148 | 191 | ||
149 | |||
150 | // Define default results | 192 | // Define default results |
151 | bool hitYN = false; | 193 | bool hitYN = false; |
152 | uint hitConsumerID = 0; | 194 | uint hitConsumerID = 0; |
@@ -177,6 +219,31 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
177 | req.callbackMethod(hitYN, closestcontact, hitConsumerID, distance, snormal); | 219 | req.callbackMethod(hitYN, closestcontact, hitConsumerID, distance, snormal); |
178 | } | 220 | } |
179 | 221 | ||
222 | /// <summary> | ||
223 | /// Method that actually initiates the raycast | ||
224 | /// </summary> | ||
225 | /// <param name="req"></param> | ||
226 | private void RayCast(ODERayRequest req) | ||
227 | { | ||
228 | // Create the ray | ||
229 | IntPtr ray = d.CreateRay(m_scene.space, req.length); | ||
230 | d.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z); | ||
231 | |||
232 | // Collide test | ||
233 | d.SpaceCollide2(m_scene.space, ray, IntPtr.Zero, nearCallback); | ||
234 | |||
235 | // Remove Ray | ||
236 | d.GeomDestroy(ray); | ||
237 | |||
238 | // Find closest contact and object. | ||
239 | lock (m_contactResults) | ||
240 | { | ||
241 | // Return results | ||
242 | if (req.callbackMethod != null) | ||
243 | req.callbackMethod(m_contactResults); | ||
244 | } | ||
245 | } | ||
246 | |||
180 | // This is the standard Near. Uses space AABBs to speed up detection. | 247 | // This is the standard Near. Uses space AABBs to speed up detection. |
181 | private void near(IntPtr space, IntPtr g1, IntPtr g2) | 248 | private void near(IntPtr space, IntPtr g1, IntPtr g2) |
182 | { | 249 | { |
@@ -311,12 +378,13 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
311 | // Loop over contacts, build results. | 378 | // Loop over contacts, build results. |
312 | for (int i = 0; i < count; i++) | 379 | for (int i = 0; i < count; i++) |
313 | { | 380 | { |
314 | if (p1 != null) { | 381 | if (p1 != null) |
382 | { | ||
315 | if (p1 is OdePrim) | 383 | if (p1 is OdePrim) |
316 | { | 384 | { |
317 | ContactResult collisionresult = new ContactResult(); | 385 | ContactResult collisionresult = new ContactResult(); |
318 | 386 | ||
319 | collisionresult.ConsumerID = ((OdePrim)p1).m_localID; | 387 | collisionresult.ConsumerID = p1.LocalID; |
320 | collisionresult.Pos = new Vector3(contacts[i].pos.X, contacts[i].pos.Y, contacts[i].pos.Z); | 388 | collisionresult.Pos = new Vector3(contacts[i].pos.X, contacts[i].pos.Y, contacts[i].pos.Z); |
321 | collisionresult.Depth = contacts[i].depth; | 389 | collisionresult.Depth = contacts[i].depth; |
322 | collisionresult.Normal = new Vector3(contacts[i].normal.X, contacts[i].normal.Y, | 390 | collisionresult.Normal = new Vector3(contacts[i].normal.X, contacts[i].normal.Y, |
@@ -332,7 +400,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
332 | { | 400 | { |
333 | ContactResult collisionresult = new ContactResult(); | 401 | ContactResult collisionresult = new ContactResult(); |
334 | 402 | ||
335 | collisionresult.ConsumerID = ((OdePrim)p2).m_localID; | 403 | collisionresult.ConsumerID = p2.LocalID; |
336 | collisionresult.Pos = new Vector3(contacts[i].pos.X, contacts[i].pos.Y, contacts[i].pos.Z); | 404 | collisionresult.Pos = new Vector3(contacts[i].pos.X, contacts[i].pos.Y, contacts[i].pos.Z); |
337 | collisionresult.Depth = contacts[i].depth; | 405 | collisionresult.Depth = contacts[i].depth; |
338 | collisionresult.Normal = new Vector3(contacts[i].normal.X, contacts[i].normal.Y, | 406 | collisionresult.Normal = new Vector3(contacts[i].normal.X, contacts[i].normal.Y, |
@@ -342,10 +410,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
342 | m_contactResults.Add(collisionresult); | 410 | m_contactResults.Add(collisionresult); |
343 | } | 411 | } |
344 | } | 412 | } |
345 | |||
346 | |||
347 | } | 413 | } |
348 | |||
349 | } | 414 | } |
350 | 415 | ||
351 | /// <summary> | 416 | /// <summary> |
@@ -365,11 +430,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
365 | public RaycastCallback callbackMethod; | 430 | public RaycastCallback callbackMethod; |
366 | } | 431 | } |
367 | 432 | ||
368 | public struct ContactResult | 433 | public struct ODERayRequest |
369 | { | 434 | { |
370 | public Vector3 Pos; | 435 | public Vector3 Origin; |
371 | public float Depth; | ||
372 | public uint ConsumerID; | ||
373 | public Vector3 Normal; | 436 | public Vector3 Normal; |
437 | public int Count; | ||
438 | public float length; | ||
439 | public RayCallback callbackMethod; | ||
374 | } | 440 | } |
375 | } | 441 | } \ No newline at end of file |