/** * * <code>fromRotationMatrix</code> generates a quaternion from a supplied * matrix. This matrix is assumed to be a rotational matrix. * * @param matrix * the matrix that defines the rotation. */ public Quaternion fromRotationMatrix(Matrix3f matrix) { return fromRotationMatrix(matrix.m00, matrix.m01, matrix.m02, matrix.m10, matrix.m11, matrix.m12, matrix.m20, matrix.m21, matrix.m22); }
public Quaternion toRotationQuat(Quaternion q) { return q.fromRotationMatrix(m00, m01, m02, m10, m11, m12, m20, m21, m22); }
/** * <code>apply</code> multiplies this quaternion by a parameter matrix * internally. * * @param matrix * the matrix to apply to this quaternion. */ public void apply(Matrix3f matrix) { float oldX = x, oldY = y, oldZ = z, oldW = w; fromRotationMatrix(matrix); float tempX = x, tempY = y, tempZ = z, tempW = w; x = oldX * tempW + oldY * tempZ - oldZ * tempY + oldW * tempX; y = -oldX * tempZ + oldY * tempW + oldZ * tempX + oldW * tempY; z = oldX * tempY - oldY * tempX + oldZ * tempW + oldW * tempZ; w = -oldX * tempX - oldY * tempY - oldZ * tempZ + oldW * tempW; }
/** * * <code>fromAxes</code> creates a <code>Quaternion</code> that * represents the coordinate system defined by three axes. These axes are * assumed to be orthogonal and no error checking is applied. Thus, the user * must insure that the three axes being provided indeed represents a proper * right handed coordinate system. * * @param xAxis vector representing the x-axis of the coordinate system. * @param yAxis vector representing the y-axis of the coordinate system. * @param zAxis vector representing the z-axis of the coordinate system. */ public Quaternion fromAxes(Vector3f xAxis, Vector3f yAxis, Vector3f zAxis) { return fromRotationMatrix(xAxis.x, yAxis.x, zAxis.x, xAxis.y, yAxis.y, zAxis.y, xAxis.z, yAxis.z, zAxis.z); }
/** * Update this wheel's location and orientation in physics space. */ public void updatePhysicsState() { getWheelLocation(wheelId, wheelIndex, wheelWorldLocation); getWheelRotation(wheelId, wheelIndex, tmp_Matrix); wheelWorldRotation.fromRotationMatrix(tmp_Matrix); }
/** * <code>setLocalRotation</code> sets the local rotation of this node * by using a {@link Matrix3f}. * * @param rotation * the new local rotation. */ public void setLocalRotation(Matrix3f rotation) { localTransform.getRotation().fromRotationMatrix(rotation); setTransformRefresh(); }
public void updatePhysicsState() { Converter.convert(wheelInfo.worldTransform.origin, wheelWorldLocation); Converter.convert(wheelInfo.worldTransform.basis, tmp_Matrix); wheelWorldRotation.fromRotationMatrix(tmp_Matrix); }
public Quaternion toRotationQuat() { Quaternion quat = new Quaternion(); quat.fromRotationMatrix(toRotationMatrix()); return quat; }
public static void convertMatrix4toQuat(Matrix4f in, Quaternion out) { // convert rotation matrix to quat out.fromRotationMatrix(in.m00, in.m01, in.m02, in.m10, in.m11, in.m12, in.m20, in.m21, in.m22); // flip the pitch out.set(-out.getX(), out.getY(), -out.getZ(), out.getW()); }
/** * called from bullet when the transform of the rigidbody changes * @param worldTrans */ public void setWorldTransform(Transform worldTrans) { if (jmeLocationDirty) { return; } motionStateTrans.set(worldTrans); Converter.convert(worldTrans.origin, worldLocation); Converter.convert(worldTrans.basis, worldRotation); worldRotationQuat.fromRotationMatrix(worldRotation); // for (Iterator<PhysicsMotionStateListener> it = listeners.iterator(); it.hasNext();) { // PhysicsMotionStateListener physicsMotionStateListener = it.next(); // physicsMotionStateListener.stateChanged(worldLocation, worldRotation); // } physicsLocationDirty = true; if (vehicle != null) { vehicle.updateWheels(); } }
private void updateInstance(Matrix4f worldMatrix, float[] store, int offset, Matrix3f tempMat3, Quaternion tempQuat) { worldMatrix.toRotationMatrix(tempMat3); tempMat3.invertLocal(); // NOTE: No need to take the transpose in order to encode // into quaternion, the multiplication in the shader is vec * quat // apparently... tempQuat.fromRotationMatrix(tempMat3); // Column-major encoding. The "W" field in each of the encoded // vectors represents the quaternion. store[offset + 0] = worldMatrix.m00; store[offset + 1] = worldMatrix.m10; store[offset + 2] = worldMatrix.m20; store[offset + 3] = tempQuat.getX(); store[offset + 4] = worldMatrix.m01; store[offset + 5] = worldMatrix.m11; store[offset + 6] = worldMatrix.m21; store[offset + 7] = tempQuat.getY(); store[offset + 8] = worldMatrix.m02; store[offset + 9] = worldMatrix.m12; store[offset + 10] = worldMatrix.m22; store[offset + 11] = tempQuat.getZ(); store[offset + 12] = worldMatrix.m03; store[offset + 13] = worldMatrix.m13; store[offset + 14] = worldMatrix.m23; store[offset + 15] = tempQuat.getW(); }
/** * Rotate the GUI to the given direction. * @param dir the direction to rotate to. * @param tpf the time per frame. */ private void rotateScreenTo(Quaternion dir, float tpf) { dir.getRotationColumn(2, look).negateLocal(); dir.getRotationColumn(0, left).negateLocal(); orient.fromAxes(left, dir.getRotationColumn(1, up), look); Quaternion rot = tempq.fromRotationMatrix(orient); if( posMode == VRGUIPositioningMode.AUTO_CAM_ALL_SKIP_PITCH ){ VRUtil.stripToYaw(rot); } if( guiPositioningElastic > 0f && posMode != VRGUIPositioningMode.MANUAL ) { // mix pos & dir with current pos & dir EoldDir.nlerp(rot, tpf * guiPositioningElastic); guiQuadNode.setLocalRotation(EoldDir); } else { guiQuadNode.setLocalRotation(rot); } }
/** * 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(); }
/** * * <code>fromRotationMatrix</code> generates a quaternion from a supplied * matrix. This matrix is assumed to be a rotational matrix. * * @param matrix * the matrix that defines the rotation. */ public Quaternion fromRotationMatrix(Matrix3f matrix) { return fromRotationMatrix(matrix.m00, matrix.m01, matrix.m02, matrix.m10, matrix.m11, matrix.m12, matrix.m20, matrix.m21, matrix.m22); }
public synchronized void updatePhysicsState() { getWheelLocation(wheelId, wheelWorldLocation); getWheelRotation(wheelId, tmp_Matrix); wheelWorldRotation.fromRotationMatrix(tmp_Matrix); }
public void updatePhysicsState() { getWheelLocation(wheelId, wheelIndex, wheelWorldLocation); getWheelRotation(wheelId, wheelIndex, tmp_Matrix); wheelWorldRotation.fromRotationMatrix(tmp_Matrix); }
/** * <code>setLocalRotation</code> sets the local rotation of this node * by using a {@link Matrix3f}. * * @param rotation * the new local rotation. */ public void setLocalRotation(Matrix3f rotation) { localTransform.getRotation().fromRotationMatrix(rotation); setTransformRefresh(); }
public Quaternion toRotationQuat() { Quaternion quat = new Quaternion(); quat.fromRotationMatrix(toRotationMatrix()); return quat; }
public void updatePhysicsState() { Converter.convert(wheelInfo.worldTransform.origin, wheelWorldLocation); Converter.convert(wheelInfo.worldTransform.basis, tmp_Matrix); wheelWorldRotation.fromRotationMatrix(tmp_Matrix); }
public Quaternion toRotationQuat() { Quaternion quat = new Quaternion(); quat.fromRotationMatrix(toRotationMatrix()); return quat; }