/** * Converts the euler angles from {@link #getVector3Value(long)} to * a quaternion rotation. * @param time Time at which to get the euler angles. * @return The rotation at time */ public Quaternion getQuaternionValue(long time) { Vector3f eulerAngles = getVector3Value(time); System.out.println("\tT: " + time + ". Rotation: " + eulerAngles.x + ", " + eulerAngles.y + ", " + eulerAngles.z); Quaternion q = new Quaternion(); q.fromAngles(eulerAngles.x * FastMath.DEG_TO_RAD, eulerAngles.y * FastMath.DEG_TO_RAD, eulerAngles.z * FastMath.DEG_TO_RAD); return q; }
@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(); }
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); } }
/** * Stores this rotation value into the given Quaternion. If quat is null, a new Quaternion is created to * hold the value. The value, once stored, is returned. * @param quat The store location for this matrix's rotation. * @return The value of this matrix's rotation. */ public Quaternion getRotation(Quaternion quat) { if (quat==null) quat=new Quaternion(); quat.set(rot); return quat; }
/** * Creates a quad with the water material applied to it. * @param width * @param height * @return */ public Geometry createWaterGeometry(float width, float height) { Quad quad = new Quad(width, height); Geometry geom = new Geometry("WaterGeometry", quad); geom.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X)); geom.setMaterial(material); return geom; }
/** * <code>subtract</code> subtracts the values of the parameter quaternion * from those of this quaternion. The result is returned as a new * quaternion. * * @param q * the quaternion to subtract from this. * @return the new quaternion. */ public Quaternion subtract(Quaternion q) { return new Quaternion(x - q.x, y - q.y, z - q.z, w - q.w); }
Vector3f modelForwardDir = characterNode.getWorldRotation().mult(Vector3f.UNIT_Z); Vector3f modelLeftDir = characterNode.getWorldRotation().mult(Vector3f.UNIT_X); Quaternion rotateL = new Quaternion().fromAngleAxis(FastMath.PI * tpf, Vector3f.UNIT_Y); rotateL.multLocal(viewDirection); } else if (rightRotate) { Quaternion rotateR = new Quaternion().fromAngleAxis(-FastMath.PI * tpf, Vector3f.UNIT_Y); rotateR.multLocal(viewDirection);
/** * 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); }
float z = parseFloat(attribs.getValue("z")); float w = parseFloat(attribs.getValue("w")); return new Quaternion(x, y, z, w); } else if (attribs.getValue("qx") != null) { float z = parseFloat(attribs.getValue("qz")); float w = parseFloat(attribs.getValue("qw")); return new Quaternion(x, y, z, w); } else if (attribs.getValue("angle") != null) { float axisY = parseFloat(attribs.getValue("axisY")); float axisZ = parseFloat(attribs.getValue("axisZ")); Quaternion q = new Quaternion(); q.fromAngleAxis(angle, new Vector3f(axisX, axisY, axisZ)); return q; } else { float angleY = parseFloat(attribs.getValue("angleY")); float angleZ = parseFloat(attribs.getValue("angleZ")); Quaternion q = new Quaternion(); q.fromAngles(angleX, angleY, angleZ); return q;
@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)); }
Quaternion localRotation = new Quaternion(); Vector3f localScale = new Vector3f(Vector3f.UNIT_XYZ); Quaternion preRotation = new Quaternion(); double y = (Double) e2.properties.get(5); double z = (Double) e2.properties.get(6); localRotation.fromAngles((float) x * FastMath.DEG_TO_RAD, (float) y * FastMath.DEG_TO_RAD, (float) z * FastMath.DEG_TO_RAD); } else if (propName.equals("Lcl Scaling")) { double x = (Double) e2.properties.get(4); double y = (Double) e2.properties.get(5); double z = (Double) e2.properties.get(6); preRotation.set(FbxNodeUtil.quatFromBoneAngles((float) x * FastMath.DEG_TO_RAD, (float) y * FastMath.DEG_TO_RAD, (float) z * FastMath.DEG_TO_RAD)); } else if (propName.equals("InheritType")) { int inheritType = (Integer) e2.properties.get(4);
/** * FIXME: This seems to have singularity type issues with angle == 0, possibly others such as PI. * @param store * A Quaternion to store our result in. If null, a new one is * created. * @return The store quaternion (or a new Quaternion, if store is null) that * describes a rotation that would point you in the exact opposite * direction of this Quaternion. */ public Quaternion opposite(Quaternion store) { if (store == null) { store = new Quaternion(); } Vector3f axis = new Vector3f(); float angle = toAngleAxis(axis); store.fromAngleAxis(FastMath.PI + angle, axis); return store; }
/** * 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); }
/** * 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(); }
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); } }
ownerAngles = ownerRotation.toAngles(ownerAngles); targetAngles = targetTransform.getRotation().toAngles(targetAngles); Quaternion startRotation = ownerRotation.clone(); Quaternion offset = Quaternion.IDENTITY; if ((flag & ROTLIKE_OFFSET) != 0) {// we add the original rotation to ownerRotation.fromAngles(ownerAngles).multLocal(offset);
/** * <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); }
tmpRot1.fromAngleAxis(rot, vectorAxis); tmpRot2[posOrNeg] = link.bone.getLocalRotation().mult(tmpRot1); tmpRot2[posOrNeg].normalizeLocal(); link.bone.getLocalRotation().normalizeLocal();