Search in sources :

Example 1 with PhysicsRayTestResult

use of com.jme3.bullet.collision.PhysicsRayTestResult in project jmonkeyengine by jMonkeyEngine.

the class TestPhysicsRayCast method simpleUpdate.

@Override
public void simpleUpdate(float tpf) {
    List<PhysicsRayTestResult> rayTest = bulletAppState.getPhysicsSpace().rayTest(cam.getLocation(), cam.getLocation().add(cam.getDirection()));
    if (rayTest.size() > 0) {
        PhysicsRayTestResult get = rayTest.get(0);
        PhysicsCollisionObject collisionObject = get.getCollisionObject();
        //do stuff
        fpsText.setText(collisionObject.getUserObject().toString());
    }
}
Also used : PhysicsRayTestResult(com.jme3.bullet.collision.PhysicsRayTestResult) PhysicsCollisionObject(com.jme3.bullet.collision.PhysicsCollisionObject)

Example 2 with PhysicsRayTestResult

use of com.jme3.bullet.collision.PhysicsRayTestResult in project jmonkeyengine by jMonkeyEngine.

the class BetterCharacterControl method checkCanUnDuck.

/**
     * This checks if the character can go from ducked to unducked state by
     * doing a ray test.
     */
protected boolean checkCanUnDuck() {
    TempVars vars = TempVars.get();
    Vector3f location = vars.vect1;
    Vector3f rayVector = vars.vect2;
    location.set(localUp).multLocal(FastMath.ZERO_TOLERANCE).addLocal(this.location);
    rayVector.set(localUp).multLocal(height + FastMath.ZERO_TOLERANCE).addLocal(location);
    List<PhysicsRayTestResult> results = space.rayTest(location, rayVector);
    vars.release();
    for (PhysicsRayTestResult physicsRayTestResult : results) {
        if (!physicsRayTestResult.getCollisionObject().equals(rigidBody)) {
            return false;
        }
    }
    return true;
}
Also used : PhysicsRayTestResult(com.jme3.bullet.collision.PhysicsRayTestResult) Vector3f(com.jme3.math.Vector3f) TempVars(com.jme3.util.TempVars)

Example 3 with PhysicsRayTestResult

use of com.jme3.bullet.collision.PhysicsRayTestResult in project jmonkeyengine by jMonkeyEngine.

the class BetterCharacterControl method checkOnGround.

/**
     * This checks if the character is on the ground by doing a ray test.
     */
protected void checkOnGround() {
    TempVars vars = TempVars.get();
    Vector3f location = vars.vect1;
    Vector3f rayVector = vars.vect2;
    float height = getFinalHeight();
    location.set(localUp).multLocal(height).addLocal(this.location);
    rayVector.set(localUp).multLocal(-height - 0.1f).addLocal(location);
    List<PhysicsRayTestResult> results = space.rayTest(location, rayVector);
    vars.release();
    for (PhysicsRayTestResult physicsRayTestResult : results) {
        if (!physicsRayTestResult.getCollisionObject().equals(rigidBody)) {
            onGround = true;
            return;
        }
    }
    onGround = false;
}
Also used : PhysicsRayTestResult(com.jme3.bullet.collision.PhysicsRayTestResult) Vector3f(com.jme3.math.Vector3f) TempVars(com.jme3.util.TempVars)

Aggregations

PhysicsRayTestResult (com.jme3.bullet.collision.PhysicsRayTestResult)3 Vector3f (com.jme3.math.Vector3f)2 TempVars (com.jme3.util.TempVars)2 PhysicsCollisionObject (com.jme3.bullet.collision.PhysicsCollisionObject)1