aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs13
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs90
-rwxr-xr-xOpenSim/Region/PhysicsModules/BulletS/BSAPIUnman.cs22
-rwxr-xr-xOpenSim/Region/PhysicsModules/BulletS/BSAPIXNA.cs8
-rw-r--r--OpenSim/Region/PhysicsModules/BulletS/BSApiTemplate.cs7
-rwxr-xr-xOpenSim/Region/PhysicsModules/BulletS/BSLinksetCompound.cs1
-rwxr-xr-xOpenSim/Region/PhysicsModules/BulletS/BSParam.cs5
-rw-r--r--OpenSim/Region/PhysicsModules/BulletS/BSScene.cs92
-rwxr-xr-xOpenSim/Region/PhysicsModules/BulletS/BSShapeCollection.cs2
-rwxr-xr-xOpenSim/Region/PhysicsModules/BulletS/Tests/Raycast.cs115
10 files changed, 305 insertions, 50 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
index 6dd3885..c44c741 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
@@ -5589,6 +5589,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5589 velocity = presence.Velocity; 5589 velocity = presence.Velocity;
5590 acceleration = Vector3.Zero; 5590 acceleration = Vector3.Zero;
5591 rotation = presence.Rotation; 5591 rotation = presence.Rotation;
5592 // tpvs can only see rotations around Z in some cases
5593 if(!presence.Flying && !presence.IsSatOnObject)
5594 {
5595 rotation.X = 0f;
5596 rotation.Y = 0f;
5597 rotation.Normalize();
5598 }
5592 angularVelocity = presence.AngularVelocity; 5599 angularVelocity = presence.AngularVelocity;
5593 5600
5594// m_log.DebugFormat( 5601// m_log.DebugFormat(
@@ -5718,6 +5725,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5718 5725
5719 Vector3 velocity = new Vector3(0, 0, 0); 5726 Vector3 velocity = new Vector3(0, 0, 0);
5720 Vector3 acceleration = new Vector3(0, 0, 0); 5727 Vector3 acceleration = new Vector3(0, 0, 0);
5728 // tpvs can only see rotations around Z in some cases
5729 if(!data.Flying && !data.IsSatOnObject)
5730 {
5731 rotation.X = 0f;
5732 rotation.Y = 0f;
5733 }
5721 rotation.Normalize(); 5734 rotation.Normalize();
5722 5735
5723 data.CollisionPlane.ToBytes(objectData, 0); 5736 data.CollisionPlane.ToBytes(objectData, 0);
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index f9c7031..9cceb06 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -290,8 +290,6 @@ namespace OpenSim.Region.Framework.Scenes
290 private Vector3 m_lastSize = new Vector3(0.45f,0.6f,1.9f); 290 private Vector3 m_lastSize = new Vector3(0.45f,0.6f,1.9f);
291 private bool SentInitialData = false; 291 private bool SentInitialData = false;
292 292
293 private bool m_followCamAuto = false;
294
295 private int m_userFlags; 293 private int m_userFlags;
296 public int UserFlags 294 public int UserFlags
297 { 295 {
@@ -344,6 +342,11 @@ namespace OpenSim.Region.Framework.Scenes
344 private Vector3 m_lastChildAgentUpdatePosition; 342 private Vector3 m_lastChildAgentUpdatePosition;
345// private Vector3 m_lastChildAgentUpdateCamPosition; 343// private Vector3 m_lastChildAgentUpdateCamPosition;
346 344
345 private Vector3 m_lastCameraRayCastCam;
346 private Vector3 m_lastCameraRayCastPos;
347
348 private float m_FOV = 1.04f;
349
347 private const int LAND_VELOCITYMAG_MAX = 12; 350 private const int LAND_VELOCITYMAG_MAX = 12;
348 351
349 private const float FLY_ROLL_MAX_RADIANS = 1.1f; 352 private const float FLY_ROLL_MAX_RADIANS = 1.1f;
@@ -374,9 +377,6 @@ namespace OpenSim.Region.Framework.Scenes
374 /// </summary> 377 /// </summary>
375 public bool LandAtTarget { get; private set; } 378 public bool LandAtTarget { get; private set; }
376 379
377 private int m_movementUpdateCount;
378 private const int NumMovementsBetweenRayCast = 5;
379
380 private bool CameraConstraintActive; 380 private bool CameraConstraintActive;
381 381
382 private object m_collisionEventLock = new Object(); 382 private object m_collisionEventLock = new Object();
@@ -1159,6 +1159,7 @@ namespace OpenSim.Region.Framework.Scenes
1159 ControllingClient.OnForceReleaseControls += HandleForceReleaseControls; 1159 ControllingClient.OnForceReleaseControls += HandleForceReleaseControls;
1160 ControllingClient.OnAutoPilotGo += MoveToTarget; 1160 ControllingClient.OnAutoPilotGo += MoveToTarget;
1161 ControllingClient.OnUpdateThrottles += RaiseUpdateThrottles; 1161 ControllingClient.OnUpdateThrottles += RaiseUpdateThrottles;
1162// ControllingClient.OnAgentFOV += HandleAgentFOV;
1162 1163
1163 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange); 1164 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange);
1164 // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement); 1165 // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement);
@@ -1178,6 +1179,7 @@ namespace OpenSim.Region.Framework.Scenes
1178 ControllingClient.OnForceReleaseControls -= HandleForceReleaseControls; 1179 ControllingClient.OnForceReleaseControls -= HandleForceReleaseControls;
1179 ControllingClient.OnAutoPilotGo -= MoveToTarget; 1180 ControllingClient.OnAutoPilotGo -= MoveToTarget;
1180 ControllingClient.OnUpdateThrottles -= RaiseUpdateThrottles; 1181 ControllingClient.OnUpdateThrottles -= RaiseUpdateThrottles;
1182// ControllingClient.OnAgentFOV += HandleAgentFOV;
1181 } 1183 }
1182 1184
1183 private void SetDirectionVectors() 1185 private void SetDirectionVectors()
@@ -2352,34 +2354,41 @@ namespace OpenSim.Region.Framework.Scenes
2352 2354
2353 private void checkCameraCollision() 2355 private void checkCameraCollision()
2354 { 2356 {
2355 if(!m_scene.PhysicsScene.SupportsRayCast()) 2357 if(m_doingCamRayCast || !m_scene.PhysicsScene.SupportsRayCast())
2356 return; 2358 return;
2357 2359
2358 ++m_movementUpdateCount; 2360 if(m_mouseLook || ParentID != 0)
2359 if (m_movementUpdateCount < 1) 2361 {
2360 m_movementUpdateCount = 1; 2362 if (CameraConstraintActive)
2363 {
2364 Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -10000f); // not right...
2365 UpdateCameraCollisionPlane(plane);
2366 CameraConstraintActive = false;
2367 }
2368 return;
2369 }
2370
2371 Vector3 posAdjusted = AbsolutePosition;
2372 posAdjusted.Z += 1.0f; // viewer current camera focus point
2361 2373
2362 if (m_doingCamRayCast || m_movementUpdateCount % NumMovementsBetweenRayCast != 0) 2374 if(posAdjusted.ApproxEquals(m_lastCameraRayCastPos, 0.2f) &&
2375 CameraPosition.ApproxEquals(m_lastCameraRayCastCam, 0.2f))
2363 return; 2376 return;
2364 2377
2365 if (m_followCamAuto && !m_mouseLook) 2378 m_lastCameraRayCastCam = CameraPosition;
2366 { 2379 m_lastCameraRayCastPos = posAdjusted;
2367 Vector3 posAdjusted = AbsolutePosition;
2368// posAdjusted.Z += 0.5f * Appearance.AvatarSize.Z - 0.5f;
2369 // not good for tiny or huge avatars
2370 posAdjusted.Z += 1.0f; // viewer current camera focus point
2371 Vector3 tocam = CameraPosition - posAdjusted;
2372 2380
2373 float distTocamlen = tocam.LengthSquared(); 2381 Vector3 tocam = CameraPosition - posAdjusted;
2374 if (distTocamlen > 0.01f && distTocamlen < 400)
2375 {
2376 distTocamlen = (float)Math.Sqrt(distTocamlen);
2377 tocam *= (1.0f / distTocamlen);
2378 2382
2379 m_doingCamRayCast = true; 2383 float distTocamlen = tocam.LengthSquared();
2380 m_scene.PhysicsScene.RaycastWorld(posAdjusted, tocam, distTocamlen + 1.0f, RayCastCameraCallback); 2384 if (distTocamlen > 0.01f && distTocamlen < 400)
2381 return; 2385 {
2382 } 2386 distTocamlen = (float)Math.Sqrt(distTocamlen);
2387 tocam *= (1.0f / distTocamlen);
2388
2389 m_doingCamRayCast = true;
2390 m_scene.PhysicsScene.RaycastWorld(posAdjusted, tocam, distTocamlen + 1.0f, RayCastCameraCallback);
2391 return;
2383 } 2392 }
2384 2393
2385 if (CameraConstraintActive) 2394 if (CameraConstraintActive)
@@ -2401,9 +2410,6 @@ namespace OpenSim.Region.Framework.Scenes
2401 2410
2402 public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal) 2411 public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal)
2403 { 2412 {
2404// const float POSITION_TOLERANCE = 0.02f;
2405// const float ROTATION_TOLERANCE = 0.02f;
2406
2407 if (hitYN && localid != LocalId) 2413 if (hitYN && localid != LocalId)
2408 { 2414 {
2409 if (localid != 0) 2415 if (localid != 0)
@@ -2441,8 +2447,6 @@ namespace OpenSim.Region.Framework.Scenes
2441 UpdateCameraCollisionPlane(plane); 2447 UpdateCameraCollisionPlane(plane);
2442 } 2448 }
2443 } 2449 }
2444// else if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) ||
2445// !Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE))
2446 else if(CameraConstraintActive) 2450 else if(CameraConstraintActive)
2447 { 2451 {
2448 Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -9000f); // not right... 2452 Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -9000f); // not right...
@@ -2538,7 +2542,7 @@ namespace OpenSim.Region.Framework.Scenes
2538 2542
2539 // Raycast from the avatar's head to the camera to see if there's anything blocking the view 2543 // Raycast from the avatar's head to the camera to see if there's anything blocking the view
2540 // this exclude checks may not be complete 2544 // this exclude checks may not be complete
2541 if(agentData.NeedsCameraCollision && ParentID == 0) // condition parentID may be wrong 2545 if(agentData.NeedsCameraCollision) // condition parentID may be wrong
2542 checkCameraCollision(); 2546 checkCameraCollision();
2543 2547
2544 uint flagsForScripts = (uint)flags; 2548 uint flagsForScripts = (uint)flags;
@@ -2807,6 +2811,10 @@ namespace OpenSim.Region.Framework.Scenes
2807// m_scene.EventManager.TriggerOnClientMovement(this); 2811// m_scene.EventManager.TriggerOnClientMovement(this);
2808 } 2812 }
2809 2813
2814 private void HandleAgentFOV(IClientAPI remoteClient, float _fov)
2815 {
2816 m_FOV = _fov;
2817 }
2810 2818
2811 /// <summary> 2819 /// <summary>
2812 /// This is the event handler for client cameras. If a client is moving, or moving the camera, this event is triggering. 2820 /// This is the event handler for client cameras. If a client is moving, or moving the camera, this event is triggering.
@@ -2843,24 +2851,6 @@ namespace OpenSim.Region.Framework.Scenes
2843 Quaternion camRot = Util.Axes2Rot(CameraAtAxis, CameraLeftAxis, CameraUpAxis); 2851 Quaternion camRot = Util.Axes2Rot(CameraAtAxis, CameraLeftAxis, CameraUpAxis);
2844 CameraRotation = camRot; 2852 CameraRotation = camRot;
2845 2853
2846 // Check if Client has camera in 'follow cam' or 'build' mode.
2847// Vector3 camdif = (Vector3.One * Rotation - Vector3.One * CameraRotation);
2848 m_followCamAuto = false;
2849 if(!m_mouseLook)
2850 {
2851 if((CameraUpAxis.Z > 0.959f && CameraUpAxis.Z < 0.99f))
2852 {
2853 Vector3 camdif = new Vector3(1f, 0f, 0f) * Rotation;
2854 float ftmp = camdif.X - CameraAtAxis.X;
2855 if(Math.Abs(ftmp) < 0.1f)
2856 {
2857 ftmp = camdif.Y - CameraAtAxis.Y;
2858 if(Math.Abs(ftmp) < 0.1f)
2859 m_followCamAuto = true;
2860 }
2861 }
2862 }
2863
2864 if(agentData.NeedsCameraCollision) 2854 if(agentData.NeedsCameraCollision)
2865 checkCameraCollision(); 2855 checkCameraCollision();
2866 2856
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSAPIUnman.cs b/OpenSim/Region/PhysicsModules/BulletS/BSAPIUnman.cs
index 42db7fe..840e453 100755
--- a/OpenSim/Region/PhysicsModules/BulletS/BSAPIUnman.cs
+++ b/OpenSim/Region/PhysicsModules/BulletS/BSAPIUnman.cs
@@ -1405,6 +1405,19 @@ public override float GetMargin(BulletShape shape)
1405} 1405}
1406 1406
1407// ===================================================================================== 1407// =====================================================================================
1408// Raycast
1409public override SweepHit ConvexSweepTest2(BulletWorld world, BulletBody sweepObject, Vector3 from, Vector3 to, float margin) {
1410 BulletWorldUnman worldu = world as BulletWorldUnman;
1411 BulletBodyUnman bodyu = sweepObject as BulletBodyUnman;
1412 return BSAPICPP.ConvexSweepTest2(worldu.ptr, bodyu.ptr, from, to, margin);
1413}
1414
1415public override RaycastHit RayTest2(BulletWorld world, Vector3 from, Vector3 to, uint filterGroup, uint filterMask) {
1416 BulletWorldUnman worldu = world as BulletWorldUnman;
1417 return BSAPICPP.RayTest2(worldu.ptr, from, to, filterGroup, filterMask);
1418}
1419
1420// =====================================================================================
1408// Debugging 1421// Debugging
1409public override void DumpRigidBody(BulletWorld world, BulletBody collisionObject) 1422public override void DumpRigidBody(BulletWorld world, BulletBody collisionObject)
1410{ 1423{
@@ -2084,6 +2097,15 @@ public static extern void SetMargin2(IntPtr shape, float val);
2084[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 2097[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
2085public static extern float GetMargin2(IntPtr shape); 2098public static extern float GetMargin2(IntPtr shape);
2086 2099
2100
2101// =====================================================================================
2102// Raycast
2103[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
2104public static extern SweepHit ConvexSweepTest2(IntPtr sim, IntPtr obj, Vector3 from, Vector3 to, float margin);
2105
2106[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
2107public static extern RaycastHit RayTest2(IntPtr sim, Vector3 from, Vector3 to, uint filterGroup, uint filterMask);
2108
2087// ===================================================================================== 2109// =====================================================================================
2088// Debugging 2110// Debugging
2089[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 2111[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSAPIXNA.cs b/OpenSim/Region/PhysicsModules/BulletS/BSAPIXNA.cs
index 37017b0..7d58728 100755
--- a/OpenSim/Region/PhysicsModules/BulletS/BSAPIXNA.cs
+++ b/OpenSim/Region/PhysicsModules/BulletS/BSAPIXNA.cs
@@ -2459,6 +2459,14 @@ private sealed class BulletConstraintXNA : BulletConstraint
2459 } 2459 }
2460 return false; 2460 return false;
2461 } 2461 }
2462
2463 public override SweepHit ConvexSweepTest2(BulletWorld world, BulletBody obj, Vector3 from, Vector3 to, float margin) {
2464 return new SweepHit();
2465 }
2466
2467 public override RaycastHit RayTest2(BulletWorld world, Vector3 from, Vector3 to, uint filterGroup, uint filterMask) {
2468 return new RaycastHit();
2469 }
2462} 2470}
2463 2471
2464 2472
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSApiTemplate.cs b/OpenSim/Region/PhysicsModules/BulletS/BSApiTemplate.cs
index 816189f..afb0ba2 100644
--- a/OpenSim/Region/PhysicsModules/BulletS/BSApiTemplate.cs
+++ b/OpenSim/Region/PhysicsModules/BulletS/BSApiTemplate.cs
@@ -128,6 +128,7 @@ public struct RaycastHit
128 public UInt32 ID; 128 public UInt32 ID;
129 public float Fraction; 129 public float Fraction;
130 public Vector3 Normal; 130 public Vector3 Normal;
131 public Vector3 Point;
131} 132}
132[StructLayout(LayoutKind.Sequential)] 133[StructLayout(LayoutKind.Sequential)]
133public struct CollisionDesc 134public struct CollisionDesc
@@ -742,6 +743,12 @@ public abstract void SetMargin(BulletShape shape, float val);
742public abstract float GetMargin(BulletShape shape); 743public abstract float GetMargin(BulletShape shape);
743 744
744// ===================================================================================== 745// =====================================================================================
746// Raycast
747public abstract SweepHit ConvexSweepTest2(BulletWorld world, BulletBody obj, Vector3 from, Vector3 to, float margin);
748
749public abstract RaycastHit RayTest2(BulletWorld world, Vector3 from, Vector3 to, uint filterGroup, uint filterMask);
750
751// =====================================================================================
745// Debugging 752// Debugging
746public virtual void DumpRigidBody(BulletWorld sim, BulletBody collisionObject) { } 753public virtual void DumpRigidBody(BulletWorld sim, BulletBody collisionObject) { }
747 754
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSLinksetCompound.cs b/OpenSim/Region/PhysicsModules/BulletS/BSLinksetCompound.cs
index 953ddee..dc390b2 100755
--- a/OpenSim/Region/PhysicsModules/BulletS/BSLinksetCompound.cs
+++ b/OpenSim/Region/PhysicsModules/BulletS/BSLinksetCompound.cs
@@ -450,6 +450,7 @@ public sealed class BSLinksetCompound : BSLinkset
450 m_physicsScene.PE.AddObjectToWorld(m_physicsScene.World, LinksetRoot.PhysBody); 450 m_physicsScene.PE.AddObjectToWorld(m_physicsScene.World, LinksetRoot.PhysBody);
451 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addBody,body={1},shape={2}", 451 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addBody,body={1},shape={2}",
452 LinksetRoot.LocalID, LinksetRoot.PhysBody, linksetShape); 452 LinksetRoot.LocalID, LinksetRoot.PhysBody, linksetShape);
453 m_physicsScene.PE.ResetBroadphasePool(m_physicsScene.World); // DEBUG DEBUG
453 454
454 // With all of the linkset packed into the root prim, it has the mass of everyone. 455 // With all of the linkset packed into the root prim, it has the mass of everyone.
455 LinksetMass = ComputeLinksetMass(); 456 LinksetMass = ComputeLinksetMass();
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSParam.cs b/OpenSim/Region/PhysicsModules/BulletS/BSParam.cs
index 352c03e..0792f5d 100755
--- a/OpenSim/Region/PhysicsModules/BulletS/BSParam.cs
+++ b/OpenSim/Region/PhysicsModules/BulletS/BSParam.cs
@@ -230,6 +230,8 @@ public static class BSParam
230 public static float LinkConstraintCFM { get; private set; } 230 public static float LinkConstraintCFM { get; private set; }
231 public static float LinkConstraintSolverIterations { get; private set; } 231 public static float LinkConstraintSolverIterations { get; private set; }
232 232
233 public static bool UseBulletRaycast { get; private set; }
234
233 public static float PID_D { get; private set; } // derivative 235 public static float PID_D { get; private set; } // derivative
234 public static float PID_P { get; private set; } // proportional 236 public static float PID_P { get; private set; } // proportional
235 237
@@ -823,6 +825,9 @@ public static class BSParam
823 new ParameterDefn<float>("LinkConstraintSolverIterations", "Number of solver iterations when computing constraint. (0 = Bullet default)", 825 new ParameterDefn<float>("LinkConstraintSolverIterations", "Number of solver iterations when computing constraint. (0 = Bullet default)",
824 40 ), 826 40 ),
825 827
828 new ParameterDefn<bool>("UseBulletRaycast", "If 'true', use the raycast function of the Bullet physics engine",
829 true ),
830
826 new ParameterDefn<float>("DebugNumber", "A console setable number sometimes used for debugging", 831 new ParameterDefn<float>("DebugNumber", "A console setable number sometimes used for debugging",
827 1.0f ), 832 1.0f ),
828 833
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSScene.cs b/OpenSim/Region/PhysicsModules/BulletS/BSScene.cs
index bcc3b4a..52aea87 100644
--- a/OpenSim/Region/PhysicsModules/BulletS/BSScene.cs
+++ b/OpenSim/Region/PhysicsModules/BulletS/BSScene.cs
@@ -969,6 +969,98 @@ namespace OpenSim.Region.PhysicsModule.BulletS
969 969
970 #endregion // Terrain 970 #endregion // Terrain
971 971
972 #region Raycast
973
974 public override bool SupportsRayCast()
975 {
976 return BSParam.UseBulletRaycast;
977 }
978
979 public override bool SupportsRaycastWorldFiltered()
980 {
981 return BSParam.UseBulletRaycast;
982 }
983
984
985 /// <summary>
986 /// Queue a raycast against the physics scene.
987 /// The provided callback method will be called when the raycast is complete
988 ///
989 /// Many physics engines don't support collision testing at the same time as
990 /// manipulating the physics scene, so we queue the request up and callback
991 /// a custom method when the raycast is complete.
992 /// This allows physics engines that give an immediate result to callback immediately
993 /// and ones that don't, to callback when it gets a result back.
994 /// public delegate void RayCallback(List<ContactResult> list);
995 ///
996 /// ODE for example will not allow you to change the scene while collision testing or
997 /// it asserts, 'opteration not valid for locked space'. This includes adding a ray to the scene.
998 ///
999 /// This is named RayCastWorld to not conflict with modrex's Raycast method.
1000 /// </summary>
1001 /// <param name="position">Origin of the ray</param>
1002 /// <param name="direction">Direction of the ray</param>
1003 /// <param name="length">Length of ray in meters</param>
1004 /// <param name="retMethod">Method to call when the raycast is complete</param>
1005 public override void RaycastWorld(Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
1006 {
1007 if (retMethod != null)
1008 {
1009 if (BSParam.UseBulletRaycast)
1010 {
1011 Vector3 posFrom = position;
1012 Vector3 posTo = Vector3.Normalize(direction) * length + position;
1013
1014 TaintedObject(DetailLogZero, "BSScene.RaycastWorld1", delegate ()
1015 {
1016 RaycastHit hitInfo = PE.RayTest2(World, posFrom, posTo, 0xffff, 0xffff);
1017 retMethod(true, hitInfo.Point, hitInfo.ID, hitInfo.Fraction, hitInfo.Normal);
1018 });
1019 }
1020 else
1021 {
1022 retMethod(false, Vector3.Zero, 0, 999999999999f, Vector3.Zero);
1023 }
1024 }
1025 }
1026
1027 public override void RaycastWorld(Vector3 position, Vector3 direction, float length, int count, RayCallback retMethod)
1028 {
1029 if (retMethod != null)
1030 {
1031 if (BSParam.UseBulletRaycast)
1032 {
1033 List<ContactResult> hitInfo = RaycastWorld(position, direction, length, count);
1034 retMethod(hitInfo);
1035 }
1036 else
1037 {
1038 retMethod(new List<ContactResult>());
1039 }
1040 }
1041 }
1042
1043 public override List<ContactResult> RaycastWorld(Vector3 position, Vector3 direction, float length, int Count)
1044 {
1045 List<ContactResult> ret = new List<ContactResult>();
1046 if (BSParam.UseBulletRaycast)
1047 {
1048 }
1049 return ret;
1050 }
1051
1052 public override object RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter)
1053 {
1054 object ret = null;
1055 if (BSParam.UseBulletRaycast)
1056 {
1057 }
1058 return ret;
1059 }
1060
1061 #endregion Raycast
1062
1063
972 public override Dictionary<uint, float> GetTopColliders() 1064 public override Dictionary<uint, float> GetTopColliders()
973 { 1065 {
974 Dictionary<uint, float> topColliders; 1066 Dictionary<uint, float> topColliders;
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSShapeCollection.cs b/OpenSim/Region/PhysicsModules/BulletS/BSShapeCollection.cs
index 8d8fc95..cda33e4 100755
--- a/OpenSim/Region/PhysicsModules/BulletS/BSShapeCollection.cs
+++ b/OpenSim/Region/PhysicsModules/BulletS/BSShapeCollection.cs
@@ -229,6 +229,8 @@ public sealed class BSShapeCollection : IDisposable
229 ret = CreateGeomMeshOrHull(prim, shapeCallback); 229 ret = CreateGeomMeshOrHull(prim, shapeCallback);
230 } 230 }
231 231
232 m_physicsScene.PE.ResetBroadphasePool(m_physicsScene.World); // DEBUG DEBUG
233
232 return ret; 234 return ret;
233 } 235 }
234 236
diff --git a/OpenSim/Region/PhysicsModules/BulletS/Tests/Raycast.cs b/OpenSim/Region/PhysicsModules/BulletS/Tests/Raycast.cs
new file mode 100755
index 0000000..046df56
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/BulletS/Tests/Raycast.cs
@@ -0,0 +1,115 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Linq;
31using System.Text;
32
33using NUnit.Framework;
34using log4net;
35
36using OpenSim.Framework;
37using OpenSim.Region.PhysicsModule.BulletS;
38using OpenSim.Region.PhysicsModules.SharedBase;
39using OpenSim.Tests.Common;
40
41using OpenMetaverse;
42
43namespace OpenSim.Region.PhysicsModule.BulletS.Tests
44{
45 [TestFixture]
46 public class BulletSimRaycast : OpenSimTestCase
47 {
48 // Documentation on attributes: http://www.nunit.org/index.php?p=attributes&r=2.6.1
49 // Documentation on assertions: http://www.nunit.org/index.php?p=assertions&r=2.6.1
50
51 BSScene PhysicsScene { get; set; }
52 BSPrim TargetSphere { get; set; }
53 Vector3 TargetSpherePosition { get; set; }
54 float simulationTimeStep = 0.089f;
55
56 [TestFixtureSetUp]
57 public void Init()
58 {
59 Dictionary<string, string> engineParams = new Dictionary<string, string>();
60 engineParams.Add("UseBulletRaycast", "true");
61 PhysicsScene = BulletSimTestsUtil.CreateBasicPhysicsEngine(engineParams);
62
63 PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateSphere();
64 Vector3 pos = new Vector3(100.0f, 100.0f, 50f);
65 pos.Z = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos) + 2f;
66 TargetSpherePosition = pos;
67 Vector3 size = new Vector3(10f, 10f, 10f);
68 pbs.Scale = size;
69 Quaternion rot = Quaternion.Identity;
70 bool isPhys = false;
71 uint localID = 123;
72
73 PhysicsScene.AddPrimShape("TargetSphere", pbs, pos, size, rot, isPhys, localID);
74 TargetSphere = (BSPrim)PhysicsScene.PhysObjects[localID];
75 // The actual prim shape creation happens at taint time
76 PhysicsScene.ProcessTaints();
77
78 }
79
80 [TestFixtureTearDown]
81 public void TearDown()
82 {
83 if (PhysicsScene != null)
84 {
85 // The Dispose() will also free any physical objects in the scene
86 PhysicsScene.Dispose();
87 PhysicsScene = null;
88 }
89 }
90
91 // There is a 10x10x10 sphere at <100,100,50>
92 // Shoot rays around the sphere and verify it hits and doesn't hit
93 // TestCase parameters are <x,y,z> of start and <x,y,z> of end and expected result
94 [TestCase(20f, 20f, 50f, 50f, 50f, 50f, true)] // in front to sphere
95 [TestCase(20f, 20f, 100f, 50f, 50f, 50f, true)] // from above to sphere
96 [TestCase(50f, 50f, 50f, 150f, 150f, 50f, true)] // through sphere
97 [TestCase(50f, 50f, 65f, 150f, 150f, 65f, false)] // pass over sphere
98 public void RaycastAroundObject(float fromX, float fromY, float fromZ, float toX, float toY, float toZ, bool expected) {
99 Vector3 fromPos = new Vector3(fromX, fromY, fromZ);
100 Vector3 toPos = new Vector3(toX, toY, toZ);
101 Vector3 direction = toPos - fromPos;
102 float len = Vector3.Distance(fromPos, toPos);
103
104 List<ContactResult> results = PhysicsScene.RaycastWorld(fromPos, direction, len, 1);
105
106 if (expected) {
107 Assert.True(results.Count > 0);
108 }
109 else
110 {
111 Assert.False(results.Count > 0);
112 }
113 }
114 }
115} \ No newline at end of file