diff options
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs')
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs | 92 |
1 files changed, 75 insertions, 17 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs b/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs index 15ccddc..9d7aa94 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> |
@@ -119,15 +147,23 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
119 | //Fail silently | 147 | //Fail silently |
120 | } | 148 | } |
121 | } | 149 | } |
122 | /* | 150 | |
123 | 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++) | ||
124 | { | 161 | { |
125 | if (req.callbackMethod != null) // quick optimization here, don't raycast | 162 | if (reqs[i].callbackMethod != null) // quick optimization here, don't raycast |
126 | RayCast(req); // if there isn't anyone to send results to | 163 | RayCast(reqs[i]); // if there isn't anyone to send results |
127 | |||
128 | } | 164 | } |
129 | */ | 165 | |
130 | m_PendingRequests.Clear(); | 166 | m_PendingRayRequests.Clear(); |
131 | } | 167 | } |
132 | } | 168 | } |
133 | 169 | ||
@@ -153,7 +189,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
153 | // Remove Ray | 189 | // Remove Ray |
154 | d.GeomDestroy(ray); | 190 | d.GeomDestroy(ray); |
155 | 191 | ||
156 | |||
157 | // Define default results | 192 | // Define default results |
158 | bool hitYN = false; | 193 | bool hitYN = false; |
159 | uint hitConsumerID = 0; | 194 | uint hitConsumerID = 0; |
@@ -184,6 +219,31 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
184 | req.callbackMethod(hitYN, closestcontact, hitConsumerID, distance, snormal); | 219 | req.callbackMethod(hitYN, closestcontact, hitConsumerID, distance, snormal); |
185 | } | 220 | } |
186 | 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 | |||
187 | // 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. |
188 | private void near(IntPtr space, IntPtr g1, IntPtr g2) | 248 | private void near(IntPtr space, IntPtr g1, IntPtr g2) |
189 | { | 249 | { |
@@ -349,10 +409,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
349 | m_contactResults.Add(collisionresult); | 409 | m_contactResults.Add(collisionresult); |
350 | } | 410 | } |
351 | } | 411 | } |
352 | |||
353 | |||
354 | } | 412 | } |
355 | |||
356 | } | 413 | } |
357 | 414 | ||
358 | /// <summary> | 415 | /// <summary> |
@@ -372,11 +429,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
372 | public RaycastCallback callbackMethod; | 429 | public RaycastCallback callbackMethod; |
373 | } | 430 | } |
374 | 431 | ||
375 | public struct ContactResult | 432 | public struct ODERayRequest |
376 | { | 433 | { |
377 | public Vector3 Pos; | 434 | public Vector3 Origin; |
378 | public float Depth; | ||
379 | public uint ConsumerID; | ||
380 | public Vector3 Normal; | 435 | public Vector3 Normal; |
436 | public int Count; | ||
437 | public float length; | ||
438 | public RayCallback callbackMethod; | ||
381 | } | 439 | } |
382 | } | 440 | } \ No newline at end of file |