/** * <code>mult</code> multiplies this quaternion by a parameter vector. The * result is returned as a new vector. * * @param v * the vector to multiply this quaternion by. * @return the new vector. */ public Vector3f mult(Vector3f v) { return mult(v, null); }
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(); }
/** * Changes the values of this matrix according to its parent. Very similar to the concept of Node/Spatial transforms. * @param parent The parent matrix. * @return This matrix, after combining. */ public Transform combineWithParent(Transform parent) { //applying parent scale to local scale scale.multLocal(parent.scale); //applying parent rotation to local rotation. parent.rot.mult(rot, rot); //applying parent scale to local translation. translation.multLocal(parent.scale); //applying parent rotation to local translation, then applying parent translation to local translation. //Note that parent.rot.multLocal(translation) doesn't modify "parent.rot" but "translation" parent .rot .multLocal(translation) .addLocal(parent.translation); return this; }
/** * <code>mult</code> multiplies this quaternion by a parameter quaternion. * The result is returned as a new quaternion. It should be noted that * quaternion multiplication is not commutative so q * p != p * q. * * @param q * the quaternion to multiply this quaternion by. * @return the new quaternion. */ public Quaternion mult(Quaternion q) { return mult(q, null); }
/** * 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; }
public Vector3f transformVector(final Vector3f in, Vector3f store){ if (store == null) store = new Vector3f(); // multiply with scale first, then rotate, finally translate (cf. // Eberly) return rot.mult(store.set(in).multLocal(scale), store).addLocal(translation); }
/** * 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); }
public Vector3f transformInverseVector(final Vector3f in, Vector3f store){ if (store == null) store = new Vector3f(); // The author of this code should look above and take the inverse of that // But for some reason, they didn't .. // in.subtract(translation, store).divideLocal(scale); // rot.inverse().mult(store, store); in.subtract(translation, store); rot.inverse().mult(store, store); store.divideLocal(scale); return store; }
/** * 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); }
/** * Place the camera within the scene. * @param eyePos the eye position. * @param obsPosition the observer position. * @param cam the camera to place. */ private void finalizeCamera(Vector3f eyePos, Vector3f obsPosition, Camera cam) { finalRotation.mult(eyePos, finalPosition); finalPosition.addLocal(hmdPos); if( obsPosition != null ) finalPosition.addLocal(obsPosition); finalPosition.y += getHeightAdjustment(); cam.setFrame(finalPosition, finalRotation); }
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); } }
/** * Place the camera within the scene. * @param eyePos the eye position. * @param obsPosition the observer position. * @param cam the camera to place. */ private void finalizeCamera(Vector3f eyePos, Vector3f obsPosition, Camera cam) { finalRotation.mult(eyePos, finalPosition); finalPosition.addLocal(hmdPos); if( obsPosition != null ){ finalPosition.addLocal(obsPosition); } finalPosition.y += getHeightAdjustment(); cam.setFrame(finalPosition, finalRotation); }
/** * Place the camera within the scene. * * @param eyePos the eye position. * @param obsPosition the observer position. * @param cam the camera to place. */ private void finalizeCamera(Vector3f eyePos, Vector3f obsPosition, Camera cam) { finalRotation.mult(eyePos, finalPosition); finalPosition.addLocal(hmdPos); if (obsPosition != null) { finalPosition.addLocal(obsPosition); } finalPosition.y += getHeightAdjustment(); cam.setFrame(finalPosition, finalRotation); }
/** * Place the camera within the scene. * * @param eyePos the eye position. * @param obsPosition the observer position. * @param cam the camera to place. */ private void finalizeCamera(Vector3f eyePos, Vector3f obsPosition, Camera cam) { finalRotation.mult(eyePos, finalPosition); finalPosition.addLocal(hmdPos); if (obsPosition != null) { finalPosition.addLocal(obsPosition); } finalPosition.y += getHeightAdjustment(); cam.setFrame(finalPosition, finalRotation); }
@Override public Vector3f getFinalObserverPosition(int index) { OSVRViewManager vrvm = (OSVRViewManager) environment.getVRViewManager(); if( vrvm == null || isInputDeviceTracking(index) == false ) return null; Object obs = environment.getObserver(); Vector3f pos = getPosition(index); if( obs instanceof Camera ) { ((Camera)obs).getRotation().mult(pos, pos); return pos.addLocal(((Camera)obs).getLocation()); } else { ((Spatial)obs).getWorldRotation().mult(pos, pos); return pos.addLocal(((Spatial)obs).getWorldTranslation()); } }
@Override public Vector3f getFinalObserverPosition(int index) { // Copied from OpenVRInput VREnvironment env = hardware.getEnvironment(); OculusViewManager vrvm = (OculusViewManager) hardware.getEnvironment().getVRViewManager(); Object obs = env.getObserver(); Vector3f pos = getPosition(index); if (obs instanceof Camera) { ((Camera) obs).getRotation().mult(pos, pos); return pos.addLocal(((Camera) obs).getLocation()); } else { ((Spatial) obs).getWorldRotation().mult(pos, pos); return pos.addLocal(((Spatial) obs).getWorldTranslation()); } }
/** * The method updates the geometry according to the poitions of the bones. */ public void updateGeometry() { VertexBuffer vb = this.getBuffer(Type.Position); FloatBuffer posBuf = this.getFloatBuffer(Type.Position); posBuf.clear(); for (int i = 0; i < skeleton.getBoneCount(); ++i) { Bone bone = skeleton.getBone(i); Vector3f head = bone.getModelSpacePosition(); posBuf.put(head.getX()).put(head.getY()).put(head.getZ()); if (boneLengths != null) { Vector3f tail = head.add(bone.getModelSpaceRotation().mult(Vector3f.UNIT_Y.mult(boneLengths.get(i)))); posBuf.put(tail.getX()).put(tail.getY()).put(tail.getZ()); } } posBuf.flip(); vb.updateData(posBuf); this.updateBound(); }
/** * The method updates the geometry according to the positions of the bones. */ public void updateGeometry() { VertexBuffer vb = this.getBuffer(Type.Position); FloatBuffer posBuf = this.getFloatBuffer(Type.Position); posBuf.clear(); for (int i = 0; i < skeleton.getBoneCount(); ++i) { Bone bone = skeleton.getBone(i); Vector3f head = bone.getModelSpacePosition(); posBuf.put(head.getX()).put(head.getY()).put(head.getZ()); if (boneLengths != null) { Vector3f tail = head.add(bone.getModelSpaceRotation().mult(Vector3f.UNIT_Y.mult(boneLengths.get(i)))); posBuf.put(tail.getX()).put(tail.getY()).put(tail.getZ()); } } posBuf.flip(); vb.updateData(posBuf); this.updateBound(); } }
/** * Get the observer final position within the scene. * @return the observer position. * @see #getFinalObserverRotation() */ public Vector3f getFinalObserverPosition() { if( viewmanager == null ) { if( observer == null ) { return getCamera().getLocation(); } else return observer.getWorldTranslation(); } Vector3f pos = VRhardware.getPosition(); if( observer == null ) { dummyCam.getRotation().mult(pos, pos); return pos.addLocal(dummyCam.getLocation()); } else { observer.getWorldRotation().mult(pos, pos); return pos.addLocal(observer.getWorldTranslation()); } }
/** * Forcefully takes over Camera adding functionality and placing it behind the character * @param tpf Tickes Per Frame */ private void camTakeOver(float tpf) { cam.setLocation(player.getLocalTranslation().add(-8, 2, 0)); cam.lookAt(player.getLocalTranslation(), Vector3f.UNIT_Y); Quaternion rot = new Quaternion(); rot.fromAngleNormalAxis(camAngle, Vector3f.UNIT_Z); cam.setRotation(cam.getRotation().mult(rot)); camAngle *= FastMath.pow(.99f, fpsRate * tpf); }