/** * normalize normalizes the camera vectors. */ public void normalize() { this.rotation.normalizeLocal(); onFrameChange(); }
/** * Sets the values of this quaternion to the nlerp from itself to q2 by blend. * @param q2 * @param blend */ public void nlerp(Quaternion q2, float blend) { float dot = dot(q2); float blendI = 1.0f - blend; if (dot < 0.0f) { x = blendI * x - blend * q2.x; y = blendI * y - blend * q2.y; z = blendI * z - blend * q2.z; w = blendI * w - blend * q2.w; } else { x = blendI * x + blend * q2.x; y = blendI * y + blend * q2.y; z = blendI * z + blend * q2.z; w = blendI * w + blend * q2.w; } normalizeLocal(); }
/** * Copy the values from a LibOVR quaternion into a jMonkeyEngine quaternion. * * @param from The quaternion to copy from. * @param to The quaternion to copy to. * @return The {@code to} argument. */ public static Quaternion quatO2J(OVRQuatf from, Quaternion to) { // jME and LibOVR do their coordinate spaces differently for rotations, so flip Y and W (thanks, jMonkeyVR). to.set( from.x(), -from.y(), from.z(), -from.w() ); to.normalizeLocal(); return to; }
store.z = (scale0 * q1.z) + (scale1 * q2.z); store.w = (scale0 * q1.w) + (scale1 * q2.w); store.normalizeLocal();
public static Quaternion quatFromBoneAngles(float xAngle, float yAngle, float zAngle) { float angle; float sinY, sinZ, sinX, cosY, cosZ, cosX; angle = zAngle * 0.5f; sinZ = FastMath.sin(angle); cosZ = FastMath.cos(angle); angle = yAngle * 0.5f; sinY = FastMath.sin(angle); cosY = FastMath.cos(angle); angle = xAngle * 0.5f; sinX = FastMath.sin(angle); cosX = FastMath.cos(angle); float cosYXcosZ = cosY * cosZ; float sinYXsinZ = sinY * sinZ; float cosYXsinZ = cosY * sinZ; float sinYXcosZ = sinY * cosZ; // For some reason bone space is differ, this is modified formulas float w = (cosYXcosZ * cosX + sinYXsinZ * sinX); float x = (cosYXcosZ * sinX - sinYXsinZ * cosX); float y = (sinYXcosZ * cosX + cosYXsinZ * sinX); float z = (cosYXsinZ * cosX - sinYXcosZ * sinX); return new Quaternion(x, y, z, w).normalizeLocal(); } }
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(); }
z = (cosYXsinZ * cosX - sinYXcosZ * sinX); normalizeLocal(); return this;
Quaternion q3 = vars.quat2; q2.set(q).multLocal(link.initalWorldRotation).normalizeLocal(); q3.set(targetModel.getWorldRotation()).inverseLocal().mult(q2, q2); q2.normalizeLocal(); link.startBlendingPos.set(position); link.startBlendingRot.set(q2);
Quaternion q3 = vars.quat2; q2.set(q).multLocal(link.initalWorldRotation).normalizeLocal(); q3.set(targetModel.getWorldRotation()).inverseLocal().mult(q2, q2); q2.normalizeLocal(); link.startBlendingPos.set(position); link.startBlendingRot.set(q2);
/** * 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); }
/** * 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(); }
Quaternion rot=vars.quat1; rot = rot.set(parent.getWorldRotation()).inverseLocal().multLocal(getLocalRotation()); rot.normalizeLocal(); setLocalRotation(rot);
/** * This method calculates local transformation for the object. Parentage is * taken under consideration. * * @param objectStructure * the object's structure * @return objects transformation relative to its parent */ public Transform getTransformation(Structure objectStructure, BlenderContext blenderContext) { TempVars tempVars = TempVars.get(); Matrix4f parentInv = tempVars.tempMat4; Pointer pParent = (Pointer) objectStructure.getFieldValue("parent"); if (pParent.isNotNull()) { Structure parentObjectStructure = (Structure) blenderContext.getLoadedFeature(pParent.getOldMemoryAddress(), LoadedDataType.STRUCTURE); this.getMatrix(parentObjectStructure, "obmat", fixUpAxis, parentInv).invertLocal(); } else { parentInv.loadIdentity(); } Matrix4f globalMatrix = this.getMatrix(objectStructure, "obmat", fixUpAxis, tempVars.tempMat42); Matrix4f localMatrix = parentInv.multLocal(globalMatrix); this.getSizeSignums(objectStructure, tempVars.vect1); localMatrix.toTranslationVector(tempVars.vect2); localMatrix.toRotationQuat(tempVars.quat1); localMatrix.toScaleVector(tempVars.vect3); Transform t = new Transform(tempVars.vect2, tempVars.quat1.normalizeLocal(), tempVars.vect3.multLocal(tempVars.vect1)); tempVars.release(); return t; }
Quaternion rotation = boneLocalMatrix.toRotationQuat().normalizeLocal(); Vector3f scale = boneLocalMatrix.toScaleVector();
this.rotation.normalizeLocal(); vars.release();