aboutsummaryrefslogtreecommitdiff
path: root/engine/src/core/com/jme3/math/Transform.java
diff options
context:
space:
mode:
authorScott Barta <sbarta@google.com>2012-03-09 13:52:20 -0800
committerScott Barta <sbarta@google.com>2012-03-09 14:13:24 -0800
commita6b44658eb1c55295f132a36233a11aa2bd8f9cf (patch)
tree4006b29d319de8635ca7cc2384782618f6c80ee7 /engine/src/core/com/jme3/math/Transform.java
parent59b2e6871c65f58fdad78cd7229c292f6a177578 (diff)
downloadjmonkeyengine-jb-mr1.1-dev.tar.gz
New drop of the jmonkeyengine libraryHEADandroid-wear-n-preview-3android-wear-n-preview-2android-wear-n-preview-1android-sdk-support_r11android-sdk-4.4.2_r1.0.1android-sdk-4.4.2_r1android-n-preview-5android-n-preview-4android-n-preview-3android-n-preview-2android-n-preview-1android-n-mr2-preview-2android-n-mr2-preview-1android-n-mr1-preview-2android-n-mr1-preview-1android-n-iot-release-smart-display-r2android-n-iot-release-smart-displayandroid-n-iot-release-polk-at1android-n-iot-release-lg-thinq-wk7android-n-iot-release-ihome-igv1android-n-iot-preview-4android-l-preview_r2android-cts-6.0_r9android-cts-6.0_r8android-cts-6.0_r7android-cts-6.0_r6android-cts-6.0_r5android-cts-6.0_r4android-cts-6.0_r32android-cts-6.0_r31android-cts-6.0_r30android-cts-6.0_r3android-cts-6.0_r29android-cts-6.0_r28android-cts-6.0_r27android-cts-6.0_r26android-cts-6.0_r25android-cts-6.0_r24android-cts-6.0_r23android-cts-6.0_r22android-cts-6.0_r21android-cts-6.0_r20android-cts-6.0_r2android-cts-6.0_r19android-cts-6.0_r18android-cts-6.0_r17android-cts-6.0_r16android-cts-6.0_r15android-cts-6.0_r14android-cts-6.0_r13android-cts-6.0_r12android-cts-6.0_r1android-cts-4.4_r4android-cts-4.4_r1android-cts-4.2_r2android-cts-4.2_r1android-cts-4.1_r4android-cts-4.1_r2android-cts-4.1_r1android-7.1.2_r9android-7.1.2_r8android-7.1.2_r6android-7.1.2_r5android-7.1.2_r4android-7.1.2_r39android-7.1.2_r38android-7.1.2_r37android-7.1.2_r36android-7.1.2_r33android-7.1.2_r32android-7.1.2_r30android-7.1.2_r3android-7.1.2_r29android-7.1.2_r28android-7.1.2_r27android-7.1.2_r25android-7.1.2_r24android-7.1.2_r23android-7.1.2_r2android-7.1.2_r19android-7.1.2_r18android-7.1.2_r17android-7.1.2_r16android-7.1.2_r15android-7.1.2_r14android-7.1.2_r13android-7.1.2_r12android-7.1.2_r11android-7.1.2_r10android-7.1.2_r1android-6.0.1_r9android-6.0.1_r81android-6.0.1_r80android-6.0.1_r8android-6.0.1_r79android-6.0.1_r78android-6.0.1_r77android-6.0.1_r74android-6.0.1_r73android-6.0.1_r72android-6.0.1_r70android-6.0.1_r7android-6.0.1_r69android-6.0.1_r68android-6.0.1_r67android-6.0.1_r66android-6.0.1_r65android-6.0.1_r63android-6.0.1_r62android-6.0.1_r61android-6.0.1_r60android-6.0.1_r59android-6.0.1_r58android-6.0.1_r57android-6.0.1_r56android-6.0.1_r55android-6.0.1_r54android-6.0.1_r53android-6.0.1_r52android-6.0.1_r51android-6.0.1_r50android-6.0.1_r5android-6.0.1_r49android-6.0.1_r48android-6.0.1_r47android-6.0.1_r46android-6.0.1_r45android-6.0.1_r43android-6.0.1_r42android-6.0.1_r41android-6.0.1_r40android-6.0.1_r4android-6.0.1_r33android-6.0.1_r32android-6.0.1_r31android-6.0.1_r30android-6.0.1_r3android-6.0.1_r28android-6.0.1_r27android-6.0.1_r26android-6.0.1_r25android-6.0.1_r24android-6.0.1_r22android-6.0.1_r21android-6.0.1_r20android-6.0.1_r18android-6.0.1_r17android-6.0.1_r16android-6.0.1_r13android-6.0.1_r12android-6.0.1_r11android-6.0.1_r10android-6.0.1_r1android-6.0.0_r7android-6.0.0_r6android-6.0.0_r5android-6.0.0_r41android-6.0.0_r4android-6.0.0_r3android-6.0.0_r26android-6.0.0_r25android-6.0.0_r24android-6.0.0_r23android-6.0.0_r2android-6.0.0_r13android-6.0.0_r12android-6.0.0_r11android-6.0.0_r1android-4.4w_r1android-4.4_r1.2.0.1android-4.4_r1.2android-4.4_r1.1.0.1android-4.4_r1.1android-4.4_r1.0.1android-4.4_r1android-4.4_r0.9android-4.4_r0.8android-4.4_r0.7android-4.4.4_r2.0.1android-4.4.4_r2android-4.4.4_r1.0.1android-4.4.4_r1android-4.4.3_r1.1.0.1android-4.4.3_r1.1android-4.4.3_r1.0.1android-4.4.3_r1android-4.4.2_r2.0.1android-4.4.2_r2android-4.4.2_r1.0.1android-4.4.2_r1android-4.4.1_r1.0.1android-4.4.1_r1android-4.3_r3.1android-4.3_r3android-4.3_r2.3android-4.3_r2.2android-4.3_r2.1android-4.3_r2android-4.3_r1.1android-4.3_r1android-4.3_r0.9.1android-4.3_r0.9android-4.3.1_r1android-4.2_r1android-4.2.2_r1.2android-4.2.2_r1.1android-4.2.2_r1android-4.2.1_r1.2android-4.2.1_r1.1android-4.2.1_r1android-4.1.2_r2.1android-4.1.2_r2android-4.1.2_r1android-4.1.1_r6.1android-4.1.1_r6android-4.1.1_r5android-4.1.1_r4android-4.1.1_r3android-4.1.1_r2android-4.1.1_r1.1android-4.1.1_r1tools_r22.2tools_r22tools_r21nougat-mr2.3-releasenougat-mr2.2-releasenougat-mr2.1-releasenougat-mr2-security-releasenougat-mr2-releasenougat-mr2-pixel-releasenougat-mr2-devnougat-iot-releasen-iot-preview-4mastermarshmallow-releasemarshmallow-mr3-releasemarshmallow-mr2-releasemarshmallow-mr1-releasemarshmallow-mr1-devmarshmallow-dr1.6-releasemarshmallow-dr1.5-releasemarshmallow-dr1.5-devmarshmallow-dr-releasemarshmallow-dr-dragon-releasemarshmallow-dr-devmarshmallow-devmarshmallow-cts-releasemainl-previewkitkat-wearkitkat-releasekitkat-mr2.2-releasekitkat-mr2.1-releasekitkat-mr2-releasekitkat-mr1.1-releasekitkat-mr1-releasekitkat-devkitkat-cts-releasekitkat-cts-devjb-releasejb-mr2.0.0-releasejb-mr2.0-releasejb-mr2-releasejb-mr2-devjb-mr1.1-releasejb-mr1.1-dev-plus-aospjb-mr1.1-devjb-mr1-releasejb-mr1-dev-plus-aospjb-mr1-devjb-mr0-releasejb-devidea133-weekly-releaseidea133
A new drop of the jmonkeyengine library sources, based on a 2012-03-05 snapshot. Fixes a few unnecessary memory allocations in the main rendering loop. Change-Id: I51ac0942fe87204df102cfdce746b59a5cb5ff85
Diffstat (limited to 'engine/src/core/com/jme3/math/Transform.java')
-rw-r--r--engine/src/core/com/jme3/math/Transform.java636
1 files changed, 318 insertions, 318 deletions
diff --git a/engine/src/core/com/jme3/math/Transform.java b/engine/src/core/com/jme3/math/Transform.java
index 7ccd847..3573d8c 100644
--- a/engine/src/core/com/jme3/math/Transform.java
+++ b/engine/src/core/com/jme3/math/Transform.java
@@ -1,318 +1,318 @@
-/*
- * Copyright (c) 2009-2010 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-package com.jme3.math;
-
-import com.jme3.export.*;
-import java.io.IOException;
-
-/**
- * Started Date: Jul 16, 2004<br><br>
- * Represents a translation, rotation and scale in one object.
- *
- * @author Jack Lindamood
- * @author Joshua Slack
- */
-public final class Transform implements Savable, Cloneable, java.io.Serializable {
-
- static final long serialVersionUID = 1;
-
- public static final Transform IDENTITY = new Transform();
-
- private Quaternion rot = new Quaternion();
- private Vector3f translation = new Vector3f();
- private Vector3f scale = new Vector3f(1,1,1);
-
- public Transform(Vector3f translation, Quaternion rot){
- this.translation.set(translation);
- this.rot.set(rot);
- }
-
- public Transform(Vector3f translation, Quaternion rot, Vector3f scale){
- this(translation, rot);
- this.scale.set(scale);
- }
-
- public Transform(Vector3f translation){
- this(translation, Quaternion.IDENTITY);
- }
-
- public Transform(Quaternion rot){
- this(Vector3f.ZERO, rot);
- }
-
- public Transform(){
- this(Vector3f.ZERO, Quaternion.IDENTITY);
- }
-
- /**
- * Sets this rotation to the given Quaternion value.
- * @param rot The new rotation for this matrix.
- * @return this
- */
- public Transform setRotation(Quaternion rot) {
- this.rot.set(rot);
- return this;
- }
-
- /**
- * Sets this translation to the given value.
- * @param trans The new translation for this matrix.
- * @return this
- */
- public Transform setTranslation(Vector3f trans) {
- this.translation.set(trans);
- return this;
- }
-
- /**
- * Return the translation vector in this matrix.
- * @return translation vector.
- */
- public Vector3f getTranslation() {
- return translation;
- }
-
- /**
- * Sets this scale to the given value.
- * @param scale The new scale for this matrix.
- * @return this
- */
- public Transform setScale(Vector3f scale) {
- this.scale.set(scale);
- return this;
- }
-
- /**
- * Sets this scale to the given value.
- * @param scale The new scale for this matrix.
- * @return this
- */
- public Transform setScale(float scale) {
- this.scale.set(scale, scale, scale);
- return this;
- }
-
- /**
- * Return the scale vector in this matrix.
- * @return scale vector.
- */
- public Vector3f getScale() {
- return scale;
- }
-
- /**
- * Stores this translation value into the given vector3f. If trans is null, a new vector3f is created to
- * hold the value. The value, once stored, is returned.
- * @param trans The store location for this matrix's translation.
- * @return The value of this matrix's translation.
- */
- public Vector3f getTranslation(Vector3f trans) {
- if (trans==null) trans=new Vector3f();
- trans.set(this.translation);
- return trans;
- }
-
- /**
- * 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;
- }
-
- /**
- * Return the rotation quaternion in this matrix.
- * @return rotation quaternion.
- */
- public Quaternion getRotation() {
- return rot;
- }
-
- /**
- * Stores this scale value into the given vector3f. If scale is null, a new vector3f is created to
- * hold the value. The value, once stored, is returned.
- * @param scale The store location for this matrix's scale.
- * @return The value of this matrix's scale.
- */
- public Vector3f getScale(Vector3f scale) {
- if (scale==null) scale=new Vector3f();
- scale.set(this.scale);
- return scale;
- }
-
- /**
- * Sets this matrix to the interpolation between the first matrix and the second by delta amount.
- * @param t1 The begining transform.
- * @param t2 The ending transform.
- * @param delta An amount between 0 and 1 representing how far to interpolate from t1 to t2.
- */
- public void interpolateTransforms(Transform t1, Transform t2, float delta) {
- this.rot.slerp(t1.rot,t2.rot,delta);
- this.translation.interpolate(t1.translation,t2.translation,delta);
- this.scale.interpolate(t1.scale,t2.scale,delta);
- }
-
- /**
- * Changes the values of this matrix acording to it's parent. Very similar to the concept of Node/Spatial transforms.
- * @param parent The parent matrix.
- * @return This matrix, after combining.
- */
- public Transform combineWithParent(Transform parent) {
- scale.multLocal(parent.scale);
-// rot.multLocal(parent.rot);
- parent.rot.mult(rot, rot);
-
- // This here, is evil code
-// parent
-// .rot
-// .multLocal(translation)
-// .multLocal(parent.scale)
-// .addLocal(parent.translation);
-
- translation.multLocal(parent.scale);
- parent
- .rot
- .multLocal(translation)
- .addLocal(parent.translation);
- return this;
- }
-
- /**
- * Sets this matrix's translation to the given x,y,z values.
- * @param x This matrix's new x translation.
- * @param y This matrix's new y translation.
- * @param z This matrix's new z translation.
- * @return this
- */
- public Transform setTranslation(float x,float y, float z) {
- translation.set(x,y,z);
- return this;
- }
-
- /**
- * Sets this matrix's scale to the given x,y,z values.
- * @param x This matrix's new x scale.
- * @param y This matrix's new y scale.
- * @param z This matrix's new z scale.
- * @return this
- */
- public Transform setScale(float x, float y, float z) {
- scale.set(x,y,z);
- return this;
- }
-
- public Vector3f transformVector(final Vector3f in, Vector3f store){
- if (store == null)
- store = new Vector3f();
-
- // multiply with scale first, then rotate, finally translate (cf.
- // Eberly)
- return rot.mult(store.set(in).multLocal(scale), store).addLocal(translation);
- }
-
- public Vector3f transformInverseVector(final Vector3f in, Vector3f store){
- if (store == null)
- store = new Vector3f();
-
- // The author of this code should look above and take the inverse of that
- // But for some reason, they didnt ..
-// in.subtract(translation, store).divideLocal(scale);
-// rot.inverse().mult(store, store);
-
- in.subtract(translation, store);
- rot.inverse().mult(store, store);
- store.divideLocal(scale);
-
- return store;
- }
-
- /**
- * Loads the identity. Equal to translation=1,1,1 scale=0,0,0 rot=0,0,0,1.
- */
- public void loadIdentity() {
- translation.set(0,0,0);
- scale.set(1,1,1);
- rot.set(0,0,0,1);
- }
-
- @Override
- public String toString(){
- return getClass().getSimpleName() + "[ " + translation.x + ", " + translation.y + ", " + translation.z + "]\n"
- + "[ " + rot.x + ", " + rot.y + ", " + rot.z + ", " + rot.w + "]\n"
- + "[ " + scale.x + " , " + scale.y + ", " + scale.z + "]";
- }
-
- /**
- * Sets this matrix to be equal to the given matrix.
- * @param matrixQuat The matrix to be equal to.
- * @return this
- */
- public Transform set(Transform matrixQuat) {
- this.translation.set(matrixQuat.translation);
- this.rot.set(matrixQuat.rot);
- this.scale.set(matrixQuat.scale);
- return this;
- }
-
- public void write(JmeExporter e) throws IOException {
- OutputCapsule capsule = e.getCapsule(this);
- capsule.write(rot, "rot", new Quaternion());
- capsule.write(translation, "translation", Vector3f.ZERO);
- capsule.write(scale, "scale", Vector3f.UNIT_XYZ);
- }
-
- public void read(JmeImporter e) throws IOException {
- InputCapsule capsule = e.getCapsule(this);
-
- rot = (Quaternion)capsule.readSavable("rot", new Quaternion());
- translation = (Vector3f)capsule.readSavable("translation", Vector3f.ZERO);
- scale = (Vector3f)capsule.readSavable("scale", Vector3f.UNIT_XYZ);
- }
-
- @Override
- public Transform clone() {
- try {
- Transform tq = (Transform) super.clone();
- tq.rot = rot.clone();
- tq.scale = scale.clone();
- tq.translation = translation.clone();
- return tq;
- } catch (CloneNotSupportedException e) {
- throw new AssertionError();
- }
- }
-}
+/*
+ * Copyright (c) 2009-2010 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package com.jme3.math;
+
+import com.jme3.export.*;
+import java.io.IOException;
+
+/**
+ * Started Date: Jul 16, 2004<br><br>
+ * Represents a translation, rotation and scale in one object.
+ *
+ * @author Jack Lindamood
+ * @author Joshua Slack
+ */
+public final class Transform implements Savable, Cloneable, java.io.Serializable {
+
+ static final long serialVersionUID = 1;
+
+ public static final Transform IDENTITY = new Transform();
+
+ private Quaternion rot = new Quaternion();
+ private Vector3f translation = new Vector3f();
+ private Vector3f scale = new Vector3f(1,1,1);
+
+ public Transform(Vector3f translation, Quaternion rot){
+ this.translation.set(translation);
+ this.rot.set(rot);
+ }
+
+ public Transform(Vector3f translation, Quaternion rot, Vector3f scale){
+ this(translation, rot);
+ this.scale.set(scale);
+ }
+
+ public Transform(Vector3f translation){
+ this(translation, Quaternion.IDENTITY);
+ }
+
+ public Transform(Quaternion rot){
+ this(Vector3f.ZERO, rot);
+ }
+
+ public Transform(){
+ this(Vector3f.ZERO, Quaternion.IDENTITY);
+ }
+
+ /**
+ * Sets this rotation to the given Quaternion value.
+ * @param rot The new rotation for this matrix.
+ * @return this
+ */
+ public Transform setRotation(Quaternion rot) {
+ this.rot.set(rot);
+ return this;
+ }
+
+ /**
+ * Sets this translation to the given value.
+ * @param trans The new translation for this matrix.
+ * @return this
+ */
+ public Transform setTranslation(Vector3f trans) {
+ this.translation.set(trans);
+ return this;
+ }
+
+ /**
+ * Return the translation vector in this matrix.
+ * @return translation vector.
+ */
+ public Vector3f getTranslation() {
+ return translation;
+ }
+
+ /**
+ * Sets this scale to the given value.
+ * @param scale The new scale for this matrix.
+ * @return this
+ */
+ public Transform setScale(Vector3f scale) {
+ this.scale.set(scale);
+ return this;
+ }
+
+ /**
+ * Sets this scale to the given value.
+ * @param scale The new scale for this matrix.
+ * @return this
+ */
+ public Transform setScale(float scale) {
+ this.scale.set(scale, scale, scale);
+ return this;
+ }
+
+ /**
+ * Return the scale vector in this matrix.
+ * @return scale vector.
+ */
+ public Vector3f getScale() {
+ return scale;
+ }
+
+ /**
+ * Stores this translation value into the given vector3f. If trans is null, a new vector3f is created to
+ * hold the value. The value, once stored, is returned.
+ * @param trans The store location for this matrix's translation.
+ * @return The value of this matrix's translation.
+ */
+ public Vector3f getTranslation(Vector3f trans) {
+ if (trans==null) trans=new Vector3f();
+ trans.set(this.translation);
+ return trans;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Return the rotation quaternion in this matrix.
+ * @return rotation quaternion.
+ */
+ public Quaternion getRotation() {
+ return rot;
+ }
+
+ /**
+ * Stores this scale value into the given vector3f. If scale is null, a new vector3f is created to
+ * hold the value. The value, once stored, is returned.
+ * @param scale The store location for this matrix's scale.
+ * @return The value of this matrix's scale.
+ */
+ public Vector3f getScale(Vector3f scale) {
+ if (scale==null) scale=new Vector3f();
+ scale.set(this.scale);
+ return scale;
+ }
+
+ /**
+ * Sets this matrix to the interpolation between the first matrix and the second by delta amount.
+ * @param t1 The begining transform.
+ * @param t2 The ending transform.
+ * @param delta An amount between 0 and 1 representing how far to interpolate from t1 to t2.
+ */
+ public void interpolateTransforms(Transform t1, Transform t2, float delta) {
+ this.rot.slerp(t1.rot,t2.rot,delta);
+ this.translation.interpolate(t1.translation,t2.translation,delta);
+ this.scale.interpolate(t1.scale,t2.scale,delta);
+ }
+
+ /**
+ * Changes the values of this matrix acording to it's parent. Very similar to the concept of Node/Spatial transforms.
+ * @param parent The parent matrix.
+ * @return This matrix, after combining.
+ */
+ public Transform combineWithParent(Transform parent) {
+ scale.multLocal(parent.scale);
+// rot.multLocal(parent.rot);
+ parent.rot.mult(rot, rot);
+
+ // This here, is evil code
+// parent
+// .rot
+// .multLocal(translation)
+// .multLocal(parent.scale)
+// .addLocal(parent.translation);
+
+ translation.multLocal(parent.scale);
+ parent
+ .rot
+ .multLocal(translation)
+ .addLocal(parent.translation);
+ return this;
+ }
+
+ /**
+ * Sets this matrix's translation to the given x,y,z values.
+ * @param x This matrix's new x translation.
+ * @param y This matrix's new y translation.
+ * @param z This matrix's new z translation.
+ * @return this
+ */
+ public Transform setTranslation(float x,float y, float z) {
+ translation.set(x,y,z);
+ return this;
+ }
+
+ /**
+ * Sets this matrix's scale to the given x,y,z values.
+ * @param x This matrix's new x scale.
+ * @param y This matrix's new y scale.
+ * @param z This matrix's new z scale.
+ * @return this
+ */
+ public Transform setScale(float x, float y, float z) {
+ scale.set(x,y,z);
+ return this;
+ }
+
+ public Vector3f transformVector(final Vector3f in, Vector3f store){
+ if (store == null)
+ store = new Vector3f();
+
+ // multiply with scale first, then rotate, finally translate (cf.
+ // Eberly)
+ return rot.mult(store.set(in).multLocal(scale), store).addLocal(translation);
+ }
+
+ public Vector3f transformInverseVector(final Vector3f in, Vector3f store){
+ if (store == null)
+ store = new Vector3f();
+
+ // The author of this code should look above and take the inverse of that
+ // But for some reason, they didnt ..
+// in.subtract(translation, store).divideLocal(scale);
+// rot.inverse().mult(store, store);
+
+ in.subtract(translation, store);
+ rot.inverse().mult(store, store);
+ store.divideLocal(scale);
+
+ return store;
+ }
+
+ /**
+ * Loads the identity. Equal to translation=0,0,0 scale=1,1,1 rot=0,0,0,1.
+ */
+ public void loadIdentity() {
+ translation.set(0,0,0);
+ scale.set(1,1,1);
+ rot.set(0,0,0,1);
+ }
+
+ @Override
+ public String toString(){
+ return getClass().getSimpleName() + "[ " + translation.x + ", " + translation.y + ", " + translation.z + "]\n"
+ + "[ " + rot.x + ", " + rot.y + ", " + rot.z + ", " + rot.w + "]\n"
+ + "[ " + scale.x + " , " + scale.y + ", " + scale.z + "]";
+ }
+
+ /**
+ * Sets this matrix to be equal to the given matrix.
+ * @param matrixQuat The matrix to be equal to.
+ * @return this
+ */
+ public Transform set(Transform matrixQuat) {
+ this.translation.set(matrixQuat.translation);
+ this.rot.set(matrixQuat.rot);
+ this.scale.set(matrixQuat.scale);
+ return this;
+ }
+
+ public void write(JmeExporter e) throws IOException {
+ OutputCapsule capsule = e.getCapsule(this);
+ capsule.write(rot, "rot", new Quaternion());
+ capsule.write(translation, "translation", Vector3f.ZERO);
+ capsule.write(scale, "scale", Vector3f.UNIT_XYZ);
+ }
+
+ public void read(JmeImporter e) throws IOException {
+ InputCapsule capsule = e.getCapsule(this);
+
+ rot = (Quaternion)capsule.readSavable("rot", new Quaternion());
+ translation = (Vector3f)capsule.readSavable("translation", Vector3f.ZERO);
+ scale = (Vector3f)capsule.readSavable("scale", Vector3f.UNIT_XYZ);
+ }
+
+ @Override
+ public Transform clone() {
+ try {
+ Transform tq = (Transform) super.clone();
+ tq.rot = rot.clone();
+ tq.scale = scale.clone();
+ tq.translation = translation.clone();
+ return tq;
+ } catch (CloneNotSupportedException e) {
+ throw new AssertionError();
+ }
+ }
+}