@Override public void simpleUpdate(float tpf) { cam.lookAt(carNode.getWorldTranslation(), Vector3f.UNIT_Y); } }
@Override public void simpleUpdate(float tpf) { if (timeToNextPrint > 0f) { timeToNextPrint -= tpf; return; } if (numFalling > 0) { Vector3f fallingLocation = falling[0].getWorldTranslation(); System.out.printf(" falling[0] location(x=%f, z=%f)", fallingLocation.x, fallingLocation.z); /* * If an object is falling vertically, its X- and Z-coordinates * should not change. */ } if (numPendulums > 0) { Vector3f bobLocation = bobs[0].getWorldTranslation(); Vector3f pivotLocation = pivots[0].getWorldTranslation(); float distance = bobLocation.distance(pivotLocation); System.out.printf(" bob[0] distance=%f", distance); /* * If the hinge is working properly, the distance from the * pivot to the bob should remain roughly constant. */ } System.out.println(); timeToNextPrint = 1f; } }
@Override public void update(float tpf) { if (spatial == null) { throw new IllegalArgumentException("The spatial to follow is null, please use the setTarget method"); } target.setLocalTranslation(spatial.getWorldTranslation()); camNode.lookAt(target.getWorldTranslation(), upVector); target.updateLogicalState(tpf); target.updateGeometricState(); }
@Override public BoundingVolume getWorldBound() { this.updateModelBound(); Node parent = this.getParent(); if (parent != null) { BoundingVolume bv = boundingBox.clone(); bv.setCenter(parent.getWorldTranslation()); return bv; } else { return boundingBox; } }
@Override public void simpleUpdate(float tpf) { float move = tpf * 1; boolean colliding = false; List<PhysicsSweepTestResult> sweepTest = bulletAppState.getPhysicsSpace().sweepTest(capsuleCollisionShape, new Transform(capsule.getWorldTranslation()), new Transform(capsule.getWorldTranslation().add(dist, 0, 0))); for (PhysicsSweepTestResult result : sweepTest) { if (result.getCollisionObject().getCollisionShape() != capsuleCollisionShape) { PhysicsCollisionObject collisionObject = result.getCollisionObject(); fpsText.setText("Almost colliding with " + collisionObject.getUserObject().toString()); colliding = true; } } if (!colliding) { // if the sweep is clear then move the spatial capsule.move(move, 0, 0); } } }
/** * Fetches the world matrix transformation of the given node. * @param node * the node * @return the node's world transformation matrix */ private Matrix4f getWorldMatrix(Node node) { Matrix4f result = new Matrix4f(); result.setTranslation(node.getWorldTranslation()); result.setRotationQuaternion(node.getWorldRotation()); result.setScale(node.getWorldScale()); return result; }
public void onAction(String name, boolean isPressed, float tpf) { if (name.equals("stop") && isPressed) { ikControl.setEnabled(!ikControl.isEnabled()); ikControl.setIKMode(); } if (name.equals("one") && isPressed) { //ragdoll.setKinematicMode(); targetPoint = model.getWorldTranslation().add(new Vector3f(0,2,4)); targetNode.setLocalTranslation(targetPoint); ikControl.setIKTarget(ikControl.getBone("Hand.L"), targetPoint, 2); ikControl.setIKMode(); } if (name.equals("two") && isPressed) { //ragdoll.setKinematicMode(); targetPoint = model.getWorldTranslation().add(new Vector3f(-3,3,0)); targetNode.setLocalTranslation(targetPoint); ikControl.setIKTarget(ikControl.getBone("Hand.R"), targetPoint, 3); ikControl.setIKMode(); } } }, "one", "two");
private void checkPlanetGravity() { Vector3f planetDist = planet.getWorldTranslation().subtract(characterNode.getWorldTranslation()); if (planetDist.length() < 24) { physicsCharacter.setGravity(planetDist.normalizeLocal().multLocal(9.81f)); } else { physicsCharacter.setGravity(normalGravity); } }
@Override protected void updateWorldBound(){ super.updateWorldBound(); // for a node, the world bound is a combination of all its children // bounds BoundingVolume resultBound = null; for (Spatial child : children.getArray()) { // child bound is assumed to be updated assert (child.refreshFlags & RF_BOUND) == 0; if (resultBound != null) { // merge current world bound with child world bound resultBound.mergeLocal(child.getWorldBound()); } else { // set world bound to first non-null child world bound if (child.getWorldBound() != null) { resultBound = child.getWorldBound().clone(this.worldBound); } } } if (resultBound == null) { resultBound = new BoundingBox(getWorldTranslation(), 0f, 0f, 0f); } this.worldBound = resultBound; }
public void update(float tpf) { if (enabled && spatial != null) { Quaternion localRotationQuat = spatial.getLocalRotation(); Vector3f localLocation = spatial.getLocalTranslation(); if (!applyLocal && spatial.getParent() != null) { getPhysicsLocation(localLocation); localLocation.subtractLocal(spatial.getParent().getWorldTranslation()); localLocation.divideLocal(spatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); spatial.setLocalTranslation(localLocation); if (useViewDirection) { localRotationQuat.lookAt(viewDirection, Vector3f.UNIT_Y); spatial.setLocalRotation(localRotationQuat); } } else { spatial.setLocalTranslation(getPhysicsLocation()); localRotationQuat.lookAt(viewDirection, Vector3f.UNIT_Y); spatial.setLocalRotation(localRotationQuat); } } }
public void update(float tpf) { if (enabled && spatial != null) { Quaternion localRotationQuat = spatial.getLocalRotation(); Vector3f localLocation = spatial.getLocalTranslation(); if (!applyLocal && spatial.getParent() != null) { getPhysicsLocation(localLocation); localLocation.subtractLocal(spatial.getParent().getWorldTranslation()); localLocation.divideLocal(spatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); spatial.setLocalTranslation(localLocation); if (useViewDirection) { localRotationQuat.lookAt(viewDirection, Vector3f.UNIT_Y); spatial.setLocalRotation(localRotationQuat); } } else { spatial.setLocalTranslation(getPhysicsLocation()); localRotationQuat.lookAt(viewDirection, Vector3f.UNIT_Y); spatial.setLocalRotation(localRotationQuat); } } }
/** * applies the current transform to the given jme Node if the location has been updated on the physics side * @param spatial */ public boolean applyTransform(Spatial spatial) { if (!physicsLocationDirty) { return false; } if (!applyPhysicsLocal && spatial.getParent() != null) { localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation()); localLocation.divideLocal(spatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); localRotationQuat.set(worldRotationQuat); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat); spatial.setLocalTranslation(localLocation); spatial.setLocalRotation(localRotationQuat); } else { spatial.setLocalTranslation(worldLocation); spatial.setLocalRotation(worldRotationQuat); } physicsLocationDirty = false; return true; }
public void applyWheelTransform() { if (wheelSpatial == null) { return; } Quaternion localRotationQuat = wheelSpatial.getLocalRotation(); Vector3f localLocation = wheelSpatial.getLocalTranslation(); if (!applyLocal && wheelSpatial.getParent() != null) { localLocation.set(wheelWorldLocation).subtractLocal(wheelSpatial.getParent().getWorldTranslation()); localLocation.divideLocal(wheelSpatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); localRotationQuat.set(wheelWorldRotation); tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat); wheelSpatial.setLocalTranslation(localLocation); wheelSpatial.setLocalRotation(localRotationQuat); } else { wheelSpatial.setLocalTranslation(wheelWorldLocation); wheelSpatial.setLocalRotation(wheelWorldRotation); } }
localLocation.subtractLocal(spatial.getParent().getWorldTranslation()); localLocation.divideLocal(spatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
/** * Apply this wheel's physics location and orientation to its associated * spatial, if any. */ public void applyWheelTransform() { if (wheelSpatial == null) { return; } Quaternion localRotationQuat = wheelSpatial.getLocalRotation(); Vector3f localLocation = wheelSpatial.getLocalTranslation(); if (!applyLocal && wheelSpatial.getParent() != null) { localLocation.set(wheelWorldLocation).subtractLocal(wheelSpatial.getParent().getWorldTranslation()); localLocation.divideLocal(wheelSpatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); localRotationQuat.set(wheelWorldRotation); tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat); wheelSpatial.setLocalTranslation(localLocation); wheelSpatial.setLocalRotation(localRotationQuat); } else { wheelSpatial.setLocalTranslation(wheelWorldLocation); wheelSpatial.setLocalRotation(wheelWorldRotation); } }
/** * Apply a physics transform to the spatial. * * @param worldLocation location vector (in physics-space coordinates, not * null, unaffected) * @param worldRotation orientation (in physics-space coordinates, not null, * unaffected) */ protected void applyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation) { if (enabled && spatial != null) { Vector3f localLocation = spatial.getLocalTranslation(); Quaternion localRotationQuat = spatial.getLocalRotation(); if (!applyLocal && spatial.getParent() != null) { localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation()); localLocation.divideLocal(spatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); localRotationQuat.set(worldRotation); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat); spatial.setLocalTranslation(localLocation); spatial.setLocalRotation(localRotationQuat); } else { spatial.setLocalTranslation(worldLocation); spatial.setLocalRotation(worldRotation); } } }
/** * Apply the specified location and orientation to the specified spatial. * * @param worldLocation location vector (in physics-space coordinates, not * null, unaffected) * @param worldRotation orientation (in physics-space coordinates, not null, * unaffected) * @param spatial where to apply (may be null) */ protected void applyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation, Spatial spatial) { if (spatial != null) { Vector3f localLocation = spatial.getLocalTranslation(); Quaternion localRotationQuat = spatial.getLocalRotation(); if (spatial.getParent() != null) { localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation()); localLocation.divideLocal(spatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); localRotationQuat.set(worldRotation); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat); spatial.setLocalTranslation(localLocation); spatial.setLocalRotation(localRotationQuat); } else { spatial.setLocalTranslation(worldLocation); spatial.setLocalRotation(worldRotation); } } } }
/** * Apply a physics transform to the spatial. * * @param worldLocation location vector (in physics-space coordinates, not * null, unaffected) * @param worldRotation orientation (in physics-space coordinates, not null, * unaffected) */ protected void applyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation) { if (enabled && spatial != null) { Vector3f localLocation = spatial.getLocalTranslation(); Quaternion localRotationQuat = spatial.getLocalRotation(); if (!applyLocal && spatial.getParent() != null) { localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation()); localLocation.divideLocal(spatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); localRotationQuat.set(worldRotation); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat); spatial.setLocalTranslation(localLocation); spatial.setLocalRotation(localRotationQuat); } else { spatial.setLocalTranslation(worldLocation); spatial.setLocalRotation(worldRotation); } } }
/** * Apply the specified location and orientation to the specified spatial. * * @param worldLocation location vector (in physics-space coordinates, not * null, unaffected) * @param worldRotation orientation (in physics-space coordinates, not null, * unaffected) * @param spatial where to apply (may be null) */ protected void applyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation, Spatial spatial) { if (spatial != null) { Vector3f localLocation = spatial.getLocalTranslation(); Quaternion localRotationQuat = spatial.getLocalRotation(); if (spatial.getParent() != null) { localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation()); localLocation.divideLocal(spatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); localRotationQuat.set(worldRotation); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat); spatial.setLocalTranslation(localLocation); spatial.setLocalRotation(localRotationQuat); } else { spatial.setLocalTranslation(worldLocation); spatial.setLocalRotation(worldRotation); } } } }
fpsText.setText("Touch da ground = " + physicsCharacter.isOnGround()); if (!lockView) { cam.lookAt(characterNode.getWorldTranslation().add(new Vector3f(0, 2, 0)), Vector3f.UNIT_Y);