Quaternion rotation = new Quaternion(); rotation.fromAngleNormalAxis(angle, Vector3f.UNIT_Y); floor.setLocalRotation(rotation); sky.setLocalRotation(rotation);
Quaternion q = new Quaternion(); q.lookAt(direction, upVector); spatial.setLocalRotation(q); break; case LookAt: q2.lookAt(direction, upVector); q2.multLocal(rotation); spatial.setLocalRotation(q2); spatial.setLocalRotation(rotation);
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); } }
spatial.setLocalRotation(localRotationQuat); } else { spatial.setLocalTranslation(localLocation); spatial.setLocalRotation(localRotationQuat);
/** * 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 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); } } }
private void buildPlayer() { spaceCraft = assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml"); CollisionShape colShape = CollisionShapeFactory.createDynamicMeshShape(spaceCraft); spaceCraft.setShadowMode(ShadowMode.CastAndReceive); spaceCraft.setLocalTranslation(new Vector3f(-140, 50, -23)); spaceCraft.setLocalRotation(new Quaternion(new float[]{0, 0.01f, 0})); hoverControl = new PhysicsHoverControl(colShape, 500); spaceCraft.addControl(hoverControl); rootNode.attachChild(spaceCraft); getPhysicsSpace().add(hoverControl); hoverControl.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02); ChaseCamera chaseCam = new ChaseCamera(cam, inputManager); spaceCraft.addControl(chaseCam); flyCam.setEnabled(false); }
/** * Rotate the billboard so it points directly opposite the direction the * camera's facing * * @param camera * Camera */ private void rotateScreenAligned(Camera camera) { // coopt diff for our in direction: look.set(camera.getDirection()).negateLocal(); // coopt loc for our left direction: left.set(camera.getLeft()).negateLocal(); orient.fromAxes(left, camera.getUp(), look); Node parent = spatial.getParent(); Quaternion rot=new Quaternion().fromRotationMatrix(orient); if ( parent != null ) { rot = parent.getWorldRotation().inverse().multLocal(rot); rot.normalizeLocal(); } spatial.setLocalRotation(rot); fixRefreshFlags(); }
rot = rot.set(parent.getWorldRotation()).inverseLocal().multLocal(getLocalRotation()); rot.normalizeLocal(); setLocalRotation(rot);
@Override protected void controlUpdate(float tpf) { if (spatial != null && camera != null) { switch (controlDir) { case SpatialToCamera: camera.setLocation(spatial.getWorldTranslation()); camera.setRotation(spatial.getWorldRotation()); break; case CameraToSpatial: // set the localtransform, so that the worldtransform would be equal to the camera's transform. // Location: TempVars vars = TempVars.get(); Vector3f vecDiff = vars.vect1.set(camera.getLocation()).subtractLocal(spatial.getWorldTranslation()); spatial.setLocalTranslation(vecDiff.addLocal(spatial.getLocalTranslation())); // Rotation: Quaternion worldDiff = vars.quat1.set(camera.getRotation()).subtractLocal(spatial.getWorldRotation()); spatial.setLocalRotation(worldDiff.addLocal(spatial.getLocalRotation())); vars.release(); break; } } }
spatial.setLocalRotation(orient); fixRefreshFlags();
targetModel.setLocalRotation(modelRotation);
targetModel.setLocalRotation(modelRotation);
public void makeMissile() { Vector3f pos = spaceCraft.getWorldTranslation().clone(); Quaternion rot = spaceCraft.getWorldRotation(); Vector3f dir = rot.getRotationColumn(2); Spatial missile = assetManager.loadModel("Models/SpaceCraft/Rocket.mesh.xml"); missile.scale(0.5f); missile.rotate(0, FastMath.PI, 0); missile.updateGeometricState(); BoundingBox box = (BoundingBox) missile.getWorldBound(); final Vector3f extent = box.getExtent(null); BoxCollisionShape boxShape = new BoxCollisionShape(extent); missile.setName("Missile"); missile.rotate(rot); missile.setLocalTranslation(pos.addLocal(0, extent.y * 4.5f, 0)); missile.setLocalRotation(hoverControl.getPhysicsRotation()); missile.setShadowMode(ShadowMode.Cast); RigidBodyControl control = new BombControl(assetManager, boxShape, 20); control.setLinearVelocity(dir.mult(100)); control.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_03); missile.addControl(control); rootNode.attachChild(missile); getPhysicsSpace().add(missile); }