/** * 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()); } }
/** * 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()); } }
@Test public void testNormalize() { final Quaternion quat = new Quaternion(0, 1, 2, 3); final Quaternion quat2 = quat.normalize(null); assertEquals(quat2, quat.normalizeLocal()); assertTrue(Math.abs(1 - quat.magnitude()) <= MathUtils.EPSILON); assertTrue(Math.abs(1 - quat2.magnitude()) <= MathUtils.EPSILON); }
return normalizeLocal();
/** * Modifies this quaternion to equal the rotation required to point the z-axis at 'direction' and the y-axis to * 'up'. * * @param direction * where to 'look' at * @param up * a vector indicating the local up direction. * @return this quaternion for chaining. */ public Quaternion lookAt(final ReadOnlyVector3 direction, final ReadOnlyVector3 up) { final Vector3 xAxis = Vector3.fetchTempInstance(); final Vector3 yAxis = Vector3.fetchTempInstance(); final Vector3 zAxis = Vector3.fetchTempInstance(); direction.normalize(zAxis); up.normalize(xAxis).crossLocal(zAxis); zAxis.cross(xAxis, yAxis); fromAxes(xAxis, yAxis, zAxis); normalizeLocal(); Vector3.releaseTempInstance(xAxis); Vector3.releaseTempInstance(yAxis); Vector3.releaseTempInstance(zAxis); return this; }
/** * Modifies this quaternion to equal the rotation required to point the z-axis at 'direction' and the y-axis to * 'up'. * * @param direction * where to 'look' at * @param up * a vector indicating the local up direction. * @return this quaternion for chaining. */ public Quaternion lookAt(final ReadOnlyVector3 direction, final ReadOnlyVector3 up) { final Vector3 xAxis = Vector3.fetchTempInstance(); final Vector3 yAxis = Vector3.fetchTempInstance(); final Vector3 zAxis = Vector3.fetchTempInstance(); direction.normalize(zAxis); up.normalize(xAxis).crossLocal(zAxis); zAxis.cross(xAxis, yAxis); fromAxes(xAxis, yAxis, zAxis); normalizeLocal(); Vector3.releaseTempInstance(xAxis); Vector3.releaseTempInstance(yAxis); Vector3.releaseTempInstance(zAxis); return this; }
orient.lookAt(endPnt.subtractLocal(stPnt).normalizeLocal(), Vector3.UNIT_Y); final Quaternion q = new Quaternion().fromRotationMatrix(orient); q.normalizeLocal(); SkeletalDebugger.bone.setWorldRotation(q);
orient.lookAt(endPnt.subtractLocal(stPnt).normalizeLocal(), Vector3.UNIT_Y); final Quaternion q = new Quaternion().fromRotationMatrix(orient); q.normalizeLocal(); SkeletalDebugger.bone.setWorldRotation(q);