Search in sources :

Example 1 with ClosestRayResultCallback

use of com.bulletphysics.collision.dispatch.CollisionWorld.ClosestRayResultCallback in project bdx by GoranM.

the class DefaultVehicleRaycaster method castRay.

public Object castRay(Vector3f from, Vector3f to, VehicleRaycasterResult result) {
    //RayResultCallback& resultCallback;
    ClosestRayResultCallback rayCallback = new ClosestRayResultCallback(from, to);
    dynamicsWorld.rayTest(from, to, rayCallback);
    if (rayCallback.hasHit()) {
        RigidBody body = RigidBody.upcast(rayCallback.collisionObject);
        if (body != null && body.hasContactResponse()) {
            result.hitPointInWorld.set(rayCallback.hitPointWorld);
            result.hitNormalInWorld.set(rayCallback.hitNormalWorld);
            result.hitNormalInWorld.normalize();
            result.distFraction = rayCallback.closestHitFraction;
            return body;
        }
    }
    return null;
}
Also used : RigidBody(com.bulletphysics.dynamics.RigidBody) ClosestRayResultCallback(com.bulletphysics.collision.dispatch.CollisionWorld.ClosestRayResultCallback)

Aggregations

ClosestRayResultCallback (com.bulletphysics.collision.dispatch.CollisionWorld.ClosestRayResultCallback)1 RigidBody (com.bulletphysics.dynamics.RigidBody)1