/** * Updates the local X-Z view direction and the corresponding rotation * quaternion for the spatial. */ protected void updateLocalViewDirection() { //update local rotation quaternion to use for view rotation localForwardRotation.multLocal(rotatedViewDirection.set(viewDirection)); calculateNewForward(rotation, rotatedViewDirection, localUp); }
/** * Updates the local X-Z view direction and the corresponding rotation * quaternion for the spatial. */ protected void updateLocalViewDirection() { //update local rotation quaternion to use for view rotation localForwardRotation.multLocal(rotatedViewDirection.set(viewDirection)); calculateNewForward(rotation, rotatedViewDirection, localUp); }
/** * Rotates the spatial by the given rotation. * * @return The spatial on which this method is called, e.g <code>this</code>. */ public Spatial rotate(Quaternion rot) { this.localTransform.getRotation().multLocal(rot); setTransformRefresh(); return this; }
private static Quaternion toQuat(float ax1v, Vector3f ax1, float ax2v, Vector3f ax2, float ax3v, Vector3f ax3) { // TODO It has some potential in optimization Quaternion q1 = new Quaternion().fromAngleNormalAxis(ax1v, ax1); Quaternion q2 = new Quaternion().fromAngleNormalAxis(ax2v, ax2); Quaternion q3 = new Quaternion().fromAngleNormalAxis(ax3v, ax3); return q1.multLocal(q2).multLocal(q3); } }
/** * Rotate the physics object to the specified orientation. * <p> * We don't set the actual physics rotation but the view rotation here. It * might actually be altered by the calculateNewForward method. * * @param quat desired orientation (not null, unaffected) */ @Override protected void setPhysicsRotation(Quaternion quat) { rotation.set(quat); rotation.multLocal(rotatedViewDirection.set(viewDirection)); updateLocalViewDirection(); }
/** * Rotate the physics object to the specified orientation. * <p> * We don't set the actual physics rotation but the view rotation here. It * might actually be altered by the calculateNewForward method. * * @param quat desired orientation (not null, unaffected) */ @Override protected void setPhysicsRotation(Quaternion quat) { rotation.set(quat); rotation.multLocal(rotatedViewDirection.set(viewDirection)); updateLocalViewDirection(); }
@Override public void simpleUpdate(float tpf){ // Rotate around X axis Quaternion rotate = new Quaternion(); rotate.fromAngleAxis(tpf, Vector3f.UNIT_X); // Combine rotation with previous rotation.multLocal(rotate); // Set new rotation into bone bone.setUserTransforms(Vector3f.ZERO, rotation, Vector3f.UNIT_XYZ); // After changing skeleton transforms, must update world data skeleton.updateWorldVectors(); }
private static Quaternion spline(Quaternion qnm1, Quaternion qn, Quaternion qnp1, Quaternion store, Quaternion tmp) { Quaternion invQn = new Quaternion(-qn.x, -qn.y, -qn.z, qn.w); log(invQn.mult(qnp1), tmp); log(invQn.mult(qnm1), store); store.addLocal(tmp).multLocal(-1f / 4f); exp(store, tmp); store.set(qn).multLocal(tmp); return store.normalizeLocal(); //return qn * (((qni * qnm1).log() + (qni * qnp1).log()) / -4).exp(); }
/** * * Sets the transforms of this bone in local space (relative to the parent bone) * * @param translation the translation in local space * @param rotation the rotation in local space * @param scale the scale in local space */ public void setUserTransforms(Vector3f translation, Quaternion rotation, Vector3f scale) { if (!userControl) { throw new IllegalStateException("You must call setUserControl(true) in order to setUserTransform to work"); } localPos.set(bindPos); localRot.set(bindRot); localScale.set(bindScale); localPos.addLocal(translation); localRot.multLocal(rotation); localScale.multLocal(scale); }
/** * Sets the local animation transform of this bone. * Bone is assumed to be in bind pose when this is called. */ void setAnimTransforms(Vector3f translation, Quaternion rotation, Vector3f scale) { if (userControl) { return; } // localPos.addLocal(translation); // localRot.multLocal(rotation); //localRot = localRot.mult(rotation); localPos.set(bindPos).addLocal(translation); localRot.set(bindRot).multLocal(rotation); if (scale != null) { localScale.set(bindScale).multLocal(scale); } }
/** * Returns the local transform of this bone combined with the given position and rotation * @param position a position * @param rotation a rotation */ public Transform getCombinedTransform(Vector3f position, Quaternion rotation) { if(tmpTransform == null){ tmpTransform = new Transform(); } rotation.mult(localPos, tmpTransform.getTranslation()).addLocal(position); tmpTransform.setRotation(rotation).getRotation().multLocal(localRot); return tmpTransform; }
/** * rotate the camera around the target */ protected void rotateCamera() { verticalRotation = FastMath.clamp(verticalRotation, minVerticalRotation, maxVerticalRotation); TempVars vars = TempVars.get(); Quaternion rot = vars.quat1; Quaternion rot2 = vars.quat2; rot.fromAngleNormalAxis(verticalRotation, leftVector); rot2.fromAngleNormalAxis(horizontalRotation, upVector); rot2.multLocal(rot); target.setLocalRotation(rot2); vars.release(); }
@Override public void simpleUpdate(float tpf) { if(forward){ model.move(model.getLocalRotation().multLocal(new Vector3f(0,0,1)).multLocal(tpf)); }else if(backward){ model.move(model.getLocalRotation().multLocal(new Vector3f(0,0,1)).multLocal(-tpf)); }else if(leftRotate){ model.rotate(0, tpf, 0); }else if(rightRotate){ model.rotate(0, -tpf, 0); } fpsText.setText(cam.getLocation() + "/" + cam.getRotation()); }
@Override public Quaternion getFinalObserverRotation(int index) { OSVRViewManager vrvm = (OSVRViewManager)environment.getVRViewManager(); if( vrvm == null || isInputDeviceTracking(index) == false ) return null; Object obs = environment.getObserver(); if( obs instanceof Camera ) { tempq.set(((Camera)obs).getRotation()); } else { tempq.set(((Spatial)obs).getWorldRotation()); } return tempq.multLocal(getOrientation(index)); }
/** * Get the observer final rotation within the scene. * @return the observer final rotation within the scene. * @see #getFinalObserverPosition() */ public Quaternion getFinalObserverRotation() { if( viewmanager == null ) { if( observer == null ) { return getCamera().getRotation(); } else return observer.getWorldRotation(); } if( observer == null ) { tempq.set(dummyCam.getRotation()); } else { tempq.set(observer.getWorldRotation()); } return tempq.multLocal(VRhardware.getOrientation()); }
@Override public Quaternion getFinalObserverRotation(int index) { // Copied from OpenVRInput VREnvironment env = hardware.getEnvironment(); OculusViewManager vrvm = (OculusViewManager) hardware.getEnvironment().getVRViewManager(); Object obs = env.getObserver(); Quaternion tempq = new Quaternion(); // TODO move to class scope? if (obs instanceof Camera) { tempq.set(((Camera) obs).getRotation()); } else { tempq.set(((Spatial) obs).getWorldRotation()); } return tempq.multLocal(getOrientation(index)); }
/** * Alter the transforms of a rigidBody to match the transforms of a bone. * This is used to make the ragdoll follow animated motion in Kinematic mode * * @param link the bone link connecting the bone and the rigidBody * @param position temporary storage used in calculations (not null) * @param tmpRot1 temporary storage used in calculations (not null) */ protected void matchPhysicObjectToBone(PhysicsBoneLink link, Vector3f position, Quaternion tmpRot1) { //computing position from rotation and scale targetModel.getWorldTransform().transformVector(link.bone.getModelSpacePosition(), position); //computing rotation tmpRot1.set(link.bone.getModelSpaceRotation()).multLocal(link.bone.getModelBindInverseRotation()); targetModel.getWorldRotation().mult(tmpRot1, tmpRot1); tmpRot1.normalizeLocal(); //updating physics location/rotation of the physics bone link.rigidBody.setPhysicsLocation(position); link.rigidBody.setPhysicsRotation(tmpRot1); }
/** * Alter the transforms of a rigidBody to match the transforms of a bone. * This is used to make the ragdoll follow animated motion in Kinematic mode * * @param link the bone link connecting the bone and the rigidBody * @param position temporary storage used in calculations (not null) * @param tmpRot1 temporary storage used in calculations (not null) */ protected void matchPhysicObjectToBone(PhysicsBoneLink link, Vector3f position, Quaternion tmpRot1) { //computing position from rotation and scale targetModel.getWorldTransform().transformVector(link.bone.getModelSpacePosition(), position); //computing rotation tmpRot1.set(link.bone.getModelSpaceRotation()).multLocal(link.bone.getModelBindInverseRotation()); targetModel.getWorldRotation().mult(tmpRot1, tmpRot1); tmpRot1.normalizeLocal(); //updating physics location/rotation of the physics bone link.rigidBody.setPhysicsLocation(position); link.rigidBody.setPhysicsRotation(tmpRot1); }
private void spatialToLight(Light light) { final Vector3f worldTranslation = spatial.getWorldTranslation(); if (light instanceof PointLight) { ((PointLight) light).setPosition(worldTranslation); return; } final TempVars vars = TempVars.get(); final Vector3f vec = vars.vect1; if (light instanceof DirectionalLight) { ((DirectionalLight) light).setDirection(vec.set(worldTranslation).multLocal(-1.0f)); } if (light instanceof SpotLight) { final SpotLight spotLight = (SpotLight) light; spotLight.setPosition(worldTranslation); spotLight.setDirection(spatial.getWorldRotation().multLocal(vec.set(Vector3f.UNIT_Y).multLocal(-1))); } vars.release(); }
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); } }