/** * Construct a new TransformChannel. * * @param channelName * our name. * @param times * our time offset values. * @param transforms * the transform to set on this channel at each time offset. These are separated into rotation, scale and * translation components. Note that supplying transforms with non-rotational matrices (with built in * shear, scale.) will produce a warning and may not give you the expected result. */ public TransformChannel(final String channelName, final float[] times, final ReadOnlyTransform[] transforms) { super(channelName, times); // Construct our data _rotations = new ReadOnlyQuaternion[transforms.length]; _translations = new ReadOnlyVector3[transforms.length]; _scales = new ReadOnlyVector3[transforms.length]; for (int i = 0; i < transforms.length; i++) { final ReadOnlyTransform transform = transforms[i]; if (!transform.isRotationMatrix()) { TransformChannel.logger.warning("TransformChannel '" + channelName + "' supplied transform with non-rotational matrices. May have unexpected results."); } _rotations[i] = new Quaternion().fromRotationMatrix(transform.getMatrix()).normalizeLocal(); _translations[i] = new Vector3(transform.getTranslation()); _scales[i] = new Vector3(transform.getScale()); } }
/** * Sets the value of this quaternion to the rotation described by the given matrix. * * @param matrix * @return this quaternion for chaining * @throws NullPointerException * if matrix is null. */ public Quaternion fromRotationMatrix(final ReadOnlyMatrix3 matrix) { return fromRotationMatrix(matrix.getM00(), matrix.getM01(), matrix.getM02(), matrix.getM10(), matrix.getM11(), matrix.getM12(), matrix.getM20(), matrix.getM21(), matrix.getM22()); }
/** * Construct a new TransformChannel. * * @param channelName * our name. * @param times * our time offset values. * @param transforms * the transform to set on this channel at each time offset. These are separated into rotation, scale and * translation components. Note that supplying transforms with non-rotational matrices (with built in * shear, scale.) will produce a warning and may not give you the expected result. */ public TransformChannel(final String channelName, final float[] times, final ReadOnlyTransform[] transforms) { super(channelName, times); // Construct our data _rotations = new ReadOnlyQuaternion[transforms.length]; _translations = new ReadOnlyVector3[transforms.length]; _scales = new ReadOnlyVector3[transforms.length]; for (int i = 0; i < transforms.length; i++) { final ReadOnlyTransform transform = transforms[i]; if (!transform.isRotationMatrix()) { TransformChannel.logger.warning("TransformChannel '" + channelName + "' supplied transform with non-rotational matrices. May have unexpected results."); } _rotations[i] = new Quaternion().fromRotationMatrix(transform.getMatrix()).normalizeLocal(); _translations[i] = new Vector3(transform.getTranslation()); _scales[i] = new Vector3(transform.getScale()); } }
/** * Sets the value of this quaternion to the rotation described by the given matrix. * * @param matrix * @return this quaternion for chaining * @throws NullPointerException * if matrix is null. */ public Quaternion fromRotationMatrix(final ReadOnlyMatrix3 matrix) { return fromRotationMatrix(matrix.getM00(), matrix.getM01(), matrix.getM02(), matrix.getM10(), matrix.getM11(), matrix.getM12(), matrix.getM20(), matrix.getM21(), matrix.getM22()); }
/** * Multiplies this quaternion by the supplied matrix. The result is stored locally. * * @param matrix * the matrix to apply to this quaternion. * @return this quaternion for chaining * @throws NullPointerException * if matrix is null. */ public Quaternion multiplyLocal(final ReadOnlyMatrix3 matrix) { final double oldX = getX(), oldY = getY(), oldZ = getZ(), oldW = getW(); fromRotationMatrix(matrix); final double tempX = getX(), tempY = getY(), tempZ = getZ(), tempW = getW(); final double x = oldX * tempW + oldY * tempZ - oldZ * tempY + oldW * tempX; final double y = -oldX * tempZ + oldY * tempW + oldZ * tempX + oldW * tempY; final double z = oldX * tempY - oldY * tempX + oldZ * tempW + oldW * tempZ; final double w = -oldX * tempX - oldY * tempY - oldZ * tempZ + oldW * tempW; return set(x, y, z, w); }
/** * Updates this quaternion to represent a rotation formed by the given three axes. These axes are assumed to be * orthogonal and no error checking is applied. It is the user's job to insure that the three axes being provided * indeed represent 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. * @return this quaternion for chaining */ public Quaternion fromAxes(final ReadOnlyVector3 xAxis, final ReadOnlyVector3 yAxis, final ReadOnlyVector3 zAxis) { return fromRotationMatrix(xAxis.getX(), yAxis.getX(), zAxis.getX(), xAxis.getY(), yAxis.getY(), zAxis.getY(), xAxis.getZ(), yAxis.getZ(), zAxis.getZ()); }
/** * Updates this quaternion to represent a rotation formed by the given three axes. These axes are assumed to be * orthogonal and no error checking is applied. It is the user's job to insure that the three axes being provided * indeed represent 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. * @return this quaternion for chaining */ public Quaternion fromAxes(final ReadOnlyVector3 xAxis, final ReadOnlyVector3 yAxis, final ReadOnlyVector3 zAxis) { return fromRotationMatrix(xAxis.getX(), yAxis.getX(), zAxis.getX(), xAxis.getY(), yAxis.getY(), zAxis.getY(), xAxis.getZ(), yAxis.getZ(), zAxis.getZ()); }
/** * Multiplies this quaternion by the supplied matrix. The result is stored locally. * * @param matrix * the matrix to apply to this quaternion. * @return this quaternion for chaining * @throws NullPointerException * if matrix is null. */ public Quaternion multiplyLocal(final ReadOnlyMatrix3 matrix) { final double oldX = getX(), oldY = getY(), oldZ = getZ(), oldW = getW(); fromRotationMatrix(matrix); final double tempX = getX(), tempY = getY(), tempZ = getZ(), tempW = getW(); final double x = oldX * tempW + oldY * tempZ - oldZ * tempY + oldW * tempX; final double y = -oldX * tempZ + oldY * tempW + oldZ * tempX + oldW * tempY; final double z = oldX * tempY - oldY * tempX + oldZ * tempW + oldW * tempZ; final double w = -oldX * tempX - oldY * tempY - oldZ * tempZ + oldW * tempW; return set(x, y, z, w); }
double a = MathUtils.HALF_PI; final Quaternion quat = new Quaternion(); quat.fromRotationMatrix( // 1, 0, 0, // 0, Math.cos(a), -Math.sin(a), // quat.fromRotationMatrix( // 1, 0, 0, // 0, Math.cos(a), -Math.sin(a), // quat.fromRotationMatrix( // Math.cos(a), 0, Math.sin(a), // 0, 1, 0, // quat.fromRotationMatrix(new Matrix3(// Math.cos(a), -Math.sin(a), 0, // Math.sin(a), Math.cos(a), 0, //
@Test public void testAxes() { final Matrix3 rot = new Matrix3().applyRotationX(MathUtils.QUARTER_PI).applyRotationY(MathUtils.HALF_PI); final Quaternion quat1 = new Quaternion().fromAxes(rot.getColumn(0, null), rot.getColumn(1, null), rot.getColumn(2, null)); final Quaternion quat2 = new Quaternion().fromRotationMatrix(rot); assertEquals(quat2, quat1); final Vector3[] axes = quat1.toAxes(new Vector3[3]); quat1.fromAxes(axes[0], axes[1], axes[2]); assertEquals(quat2, quat1); }
@Test public void testRotations() { final double a = MathUtils.QUARTER_PI; final Quaternion quat = new Quaternion().fromRotationMatrix(new Matrix3(// Math.cos(a), -Math.sin(a), 0, // Math.sin(a), Math.cos(a), 0, //
final Quaternion q = new Quaternion().fromRotationMatrix(orient); q.normalizeLocal(); SkeletalDebugger.bone.setWorldRotation(q);
final Quaternion q = new Quaternion().fromRotationMatrix(orient); q.normalizeLocal(); SkeletalDebugger.bone.setWorldRotation(q);