Przeglądaj źródła

Feature: added scale retreive methods to Matrix4f.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10534 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
Kae..pl 12 lat temu
rodzic
commit
f8c256d127
1 zmienionych plików z 26 dodań i 3 usunięć
  1. 26 3
      engine/src/core/com/jme3/math/Matrix4f.java

+ 26 - 3
engine/src/core/com/jme3/math/Matrix4f.java

@@ -1744,7 +1744,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
 
     public Matrix3f toRotationMatrix() {
         return new Matrix3f(m00, m01, m02, m10, m11, m12, m20, m21, m22);
-
     }
 
     public void toRotationMatrix(Matrix3f mat) {
@@ -1757,8 +1756,32 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
         mat.m20 = m20;
         mat.m21 = m21;
         mat.m22 = m22;
-
-    }
+	}
+
+	/**
+	 * Retreives the scale vector from the matrix.
+	 * 
+	 * @return the scale vector
+	 */
+	public Vector3f toScaleVector() {
+		Vector3f result = new Vector3f();
+		this.toScaleVector(result);
+		return result;
+	}
+
+	/**
+	 * Retreives the scale vector from the matrix and stores it into a given
+	 * vector.
+	 * 
+	 * @param the
+	 *            vector where the scale will be stored
+	 */
+	public void toScaleVector(Vector3f vector) {
+		float scaleX = (float) Math.sqrt(m00 * m00 + m10 * m10 + m20 * m20);
+		float scaleY = (float) Math.sqrt(m01 * m01 + m11 * m11 + m21 * m21);
+		float scaleZ = (float) Math.sqrt(m02 * m02 + m12 * m12 + m22 * m22);
+		vector.set(scaleX, scaleY, scaleZ);
+	}
 
     public void setScale(float x, float y, float z) {
         m00 *= x;