@Override public void simpleUpdate(float tpf) { float rayLength = 50f; Vector3f start = cam.getLocation(); Vector3f end = cam.getDirection().scaleAdd(rayLength, start); List<PhysicsRayTestResult> rayTest = bulletAppState.getPhysicsSpace().rayTest(start, end); if (rayTest.size() > 0) { PhysicsRayTestResult get = rayTest.get(0); PhysicsCollisionObject collisionObject = get.getCollisionObject(); // Display the name of the 1st object in place of FPS. fpsText.setText(collisionObject.getUserObject().toString()); } else { // Provide prompt feedback that no collision object was hit. fpsText.setText("MISSING"); } }
@Override public float addSingleResult(LocalRayResult lrr, boolean bln) { PhysicsCollisionObject obj = (PhysicsCollisionObject) lrr.collisionObject.getUserPointer(); results.add(new PhysicsRayTestResult(obj, Converter.convert(lrr.hitNormalLocal), lrr.hitFraction, bln)); return lrr.hitFraction; } }
@Override public int compare(PhysicsRayTestResult r1, PhysicsRayTestResult r2) { float comp = r1.getHitFraction() - r2.getHitFraction(); return comp > 0 ? 1 : -1; } };
/** * 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; }
@Override public float addSingleResult(LocalRayResult lrr, boolean bln) { PhysicsCollisionObject obj = (PhysicsCollisionObject) lrr.collisionObject.getUserPointer(); results.add(new PhysicsRayTestResult(obj, Converter.convert(lrr.hitNormalLocal), lrr.hitFraction, bln)); return lrr.hitFraction; } }
@Override public int compare(PhysicsRayTestResult r1, PhysicsRayTestResult r2) { float comp = r1.getHitFraction() - r2.getHitFraction(); return comp > 0 ? 1 : -1; } };
/** * 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; }
/** * Test whether the character is on the ground, by means of 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; }
/** * Test whether the character is on the ground, by means of 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * Test whether the character is on the ground, by means of 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; }