Example #1
0
		public object CastRay(Vector3 from, Vector3 to, out VehicleRaycasterResult result)
		{
			CollisionWorld.ClosestRayResultCallback rayCallback = new CollisionWorld.ClosestRayResultCallback(from, to);
			_dynamicsWorld.RayTest(from, to, rayCallback);

			result = new VehicleRaycasterResult();

			if (!rayCallback.HasHit) return 0;
			RigidBody body = RigidBody.Upcast(rayCallback.CollisionObject);
			if (body == null) return 0;

			result.HitPointInWorld = rayCallback.HitPointWorld;
			result.HitNormalInWorld = rayCallback.HitNormalWorld;
			result.HitNormalInWorld.Normalize();
			result.DistFraction = rayCallback.ClosestHitFraction;
			return body;
		}
Example #2
0
        public object CastRay(Vector3 from, Vector3 to, out VehicleRaycasterResult result)
        {
            CollisionWorld.ClosestRayResultCallback rayCallback = new CollisionWorld.ClosestRayResultCallback(from, to);
            _dynamicsWorld.RayTest(from, to, rayCallback);

            result = new VehicleRaycasterResult();

            if (!rayCallback.HasHit)
            {
                return(0);
            }
            RigidBody body = RigidBody.Upcast(rayCallback.CollisionObject);

            if (body == null)
            {
                return(0);
            }

            result.HitPointInWorld  = rayCallback.HitPointWorld;
            result.HitNormalInWorld = rayCallback.HitNormalWorld;
            result.HitNormalInWorld.Normalize();
            result.DistFraction = rayCallback.ClosestHitFraction;
            return(body);
        }