static void TestRayCast(CollisionObject testObject) { Vector3 rayFromWorld = testObject.WorldTransform.Origin + new Vector3(0, 0, -2); Vector3 rayToWorld = testObject.WorldTransform.Origin + new Vector3(0, 0, 2); var rayCallback = new CustomRayCallback(ref rayFromWorld, ref rayToWorld); world.RayTestRef(ref rayFromWorld, ref rayToWorld, rayCallback); if (rayCallback.CollisionObject != testObject) { Console.WriteLine("Raycast FAILED!"); } AddToDisposeQueue(rayCallback); }
private void PickBody() { Vector3 rayFrom = _demo.FreeLook.Eye; Vector3 rayTo = _demo.GetCameraRayTo(); DiscreteDynamicsWorld world = _demo.Simulation.World; using (var rayCallback = new ClosestRayResultCallback(ref rayFrom, ref rayTo)) { world.RayTestRef(ref rayFrom, ref rayTo, rayCallback); if (rayCallback.HasHit) { Vector3 pickPosition = rayCallback.HitPointWorld; var body = rayCallback.CollisionObject as RigidBody; if (body != null) { PickRigidBody(body, ref pickPosition); } else { var collider = rayCallback.CollisionObject as MultiBodyLinkCollider; if (collider != null) { PickMultiBody(collider, ref pickPosition); } } _oldPickingDist = (pickPosition - rayFrom).Length; } } }
public bool PointRaycast(PhysicsObject me, Vector3 origin, Vector3 direction, float maxDist, out Vector3 contactPoint, out PhysicsObject didHit) { contactPoint = Vector3.Zero; didHit = null; ClosestRayResultCallback cb; var from = origin.Cast(); var to = (origin + direction * maxDist).Cast(); if (me != null) { cb = new KinematicClosestNotMeRayResultCallback(me.RigidBody); cb.RayFromWorld = from; cb.RayToWorld = to; } else { cb = new ClosestRayResultCallback(ref from, ref to); } using (cb) { btWorld.RayTestRef(ref from, ref to, cb); if (cb.HasHit) { didHit = cb.CollisionObject.UserObject as PhysicsObject; contactPoint = cb.HitPointWorld.Cast(); return(true); } return(false); } }