-/*\r
- Copyright (C) 1997,1998,1999\r
- Kenji Hiranabe, Eiwa System Management, Inc.\r
-\r
- This program is free software.\r
- Implemented by Kenji Hiranabe(hiranabe@esm.co.jp),\r
- conforming to the Java(TM) 3D API specification by Sun Microsystems.\r
-\r
- Permission to use, copy, modify, distribute and sell this software\r
- and its documentation for any purpose is hereby granted without fee,\r
- provided that the above copyright notice appear in all copies and\r
- that both that copyright notice and this permission notice appear\r
- in supporting documentation. Kenji Hiranabe and Eiwa System Management,Inc.\r
- makes no representations about the suitability of this software for any\r
- purpose. It is provided "AS IS" with NO WARRANTY.\r
-*/\r
-package javajs.util;\r
-\r
-import java.io.Serializable;\r
-\r
-import javajs.api.JSONEncodable;\r
-import javajs.util.T3;\r
-\r
-\r
-\r
-/**\r
- * A 4 element axis angle represented by single precision floating point\r
- * x,y,z,angle components. An axis angle is a rotation of angle (radians) about\r
- * the vector (x,y,z).\r
- * \r
- * @version specification 1.1, implementation $Revision: 1.9 $, $Date:\r
- * 2006/07/28 17:01:32 $\r
- * @author Kenji hiranabe\r
- * \r
- * additions by Bob Hanson hansonr@stolaf.edu 9/30/2012\r
- * for unique constructor and method names\r
- * for the optimization of compiled JavaScript using Java2Script\r
- */\r
-public class A4 implements JSONEncodable, Serializable {\r
-\r
- /*\r
- * I assumed that the length of the axis vector is not significant.\r
- */\r
-\r
- /**\r
- * The x coordinate.\r
- */\r
- public float x;\r
-\r
- /**\r
- * The y coordinate.\r
- */\r
- public float y;\r
-\r
- /**\r
- * The z coordinate.\r
- */\r
- public float z;\r
-\r
- /**\r
- * The angle.\r
- */\r
- public float angle;\r
-\r
- /**\r
- * Constructs and initializes a AxisAngle4f to (0,0,1,0).\r
- */\r
- public A4() {\r
- z = 1.0f;\r
- }\r
-\r
- /**\r
- * Constructs and initializes an AxisAngle4f from the specified x, y, z, and\r
- * angle.\r
- * \r
- * @param x\r
- * the x coordinate\r
- * @param y\r
- * the y coordinate\r
- * @param z\r
- * the z coordinate\r
- * @param angle\r
- * the angle.\r
- * @return a\r
- */\r
- public static A4 new4(float x, float y, float z, float angle) {\r
- A4 a = new A4();\r
- a.set4(x, y, z, angle);\r
- return a;\r
- }\r
-\r
- /**\r
- * Constructs and initializes a AxisAngle4f from the specified AxisAngle4f.\r
- * \r
- * @param a1\r
- * the AxisAngle4f containing the initialization x y z angle data\r
- * @return a\r
- */\r
- public static A4 newAA(A4 a1) {\r
- A4 a = new A4();\r
- a.set4(a1.x, a1.y, a1.z, a1.angle);\r
- return a;\r
- }\r
-\r
- /**\r
- * Constructs and initializes an AxisAngle4f from the specified axis and\r
- * angle.\r
- * \r
- * @param axis\r
- * the axis\r
- * @param angle\r
- * the angle\r
- * @return a\r
- */\r
- public static A4 newVA(V3 axis, float angle) {\r
- A4 a = new A4();\r
- a.setVA(axis, angle);\r
- return a;\r
- }\r
-\r
- /**\r
- * Sets the value of this AxisAngle4f to the specified axis and angle.\r
- * \r
- * @param axis\r
- * the axis\r
- * @param angle\r
- * the angle\r
- * @since Java 3D 1.2\r
- */\r
- public final void setVA(V3 axis, float angle) {\r
- x = axis.x;\r
- y = axis.y;\r
- z = axis.z;\r
- this.angle = angle;\r
- }\r
-\r
- /**\r
- * Sets the value of this axis angle to the specified x,y,z,angle.\r
- * \r
- * @param x\r
- * the x coordinate\r
- * @param y\r
- * the y coordinate\r
- * @param z\r
- * the z coordinate\r
- * @param angle\r
- * the angle\r
- */\r
- public final void set4(float x, float y, float z, float angle) {\r
- this.x = x;\r
- this.y = y;\r
- this.z = z;\r
- this.angle = angle;\r
- }\r
-\r
- /**\r
- * Sets the value of this axis angle to the value of axis angle t1.\r
- * \r
- * @param a\r
- * the axis angle to be copied\r
- */\r
- public final void setAA(A4 a) {\r
- x = a.x;\r
- y = a.y;\r
- z = a.z;\r
- angle = a.angle;\r
- }\r
-\r
-\r
- /**\r
- * Sets the value of this axis-angle to the rotational component of the passed\r
- * matrix.\r
- * \r
- * @param m1\r
- * the matrix3f\r
- */\r
- public final void setM(M3 m1) {\r
- setFromMat(m1.m00, m1.m01, m1.m02, m1.m10, m1.m11, m1.m12, m1.m20, m1.m21,\r
- m1.m22);\r
- }\r
-\r
- // helper method\r
- private void setFromMat(double m00, double m01, double m02, double m10,\r
- double m11, double m12, double m20, double m21,\r
- double m22) {\r
- // assuming M is normalized.\r
-\r
- double cos = (m00 + m11 + m22 - 1.0) * 0.5;\r
- x = (float) (m21 - m12);\r
- y = (float) (m02 - m20);\r
- z = (float) (m10 - m01);\r
- double sin = 0.5 * Math.sqrt(x * x + y * y + z * z);\r
- if (sin == 0 && cos == 1) {\r
- x = y = 0;\r
- z = 1;\r
- angle = 0;\r
- } else {\r
- angle = (float) Math.atan2(sin, cos);\r
- }\r
-\r
- // no need to normalize\r
- // x /= n;\r
- // y /= n;\r
- // z /= n;\r
- }\r
-\r
- /**\r
- * Returns a hash number based on the data values in this object. Two\r
- * different AxisAngle4f objects with identical data values (ie, returns true\r
- * for equals(AxisAngle4f) ) will return the same hash number. Two vectors\r
- * with different data members may return the same hash value, although this\r
- * is not likely.\r
- */\r
- @Override\r
- public int hashCode() {\r
- return T3.floatToIntBits0(x) ^ T3.floatToIntBits0(y)\r
- ^ T3.floatToIntBits0(z) ^ T3.floatToIntBits0(angle);\r
- }\r
-\r
- /**\r
- * Returns true if the Object o is of type AxisAngle4f and all of the data\r
- * members of o1 are equal to the corresponding data members in this\r
- * AxisAngle4f.\r
- * \r
- * @param o\r
- * the object with which the comparison is made.\r
- * @return T/F\r
- */\r
- @Override\r
- public boolean equals(Object o) {\r
- if (!(o instanceof A4))\r
- return false;\r
- A4 a1 = (A4) o;\r
- return x == a1.x && y == a1.y && z == a1.z && angle == a1.angle;\r
- }\r
-\r
- /**\r
- * Returns a string that contains the values of this AxisAngle4f. The form is\r
- * (x,y,z,angle).\r
- * \r
- * @return the String representation\r
- */\r
- @Override\r
- public String toString() {\r
- return "(" + x + ", " + y + ", " + z + ", " + angle + ")";\r
- }\r
-\r
- @Override\r
- public String toJSON() {\r
- return "[" + x + "," + y + "," + z + "," + (float) (angle * 180.0 / Math.PI) + "]";\r
- }\r
-}\r
+/*
+ Copyright (C) 1997,1998,1999
+ Kenji Hiranabe, Eiwa System Management, Inc.
+
+ This program is free software.
+ Implemented by Kenji Hiranabe(hiranabe@esm.co.jp),
+ conforming to the Java(TM) 3D API specification by Sun Microsystems.
+
+ Permission to use, copy, modify, distribute and sell this software
+ and its documentation for any purpose is hereby granted without fee,
+ provided that the above copyright notice appear in all copies and
+ that both that copyright notice and this permission notice appear
+ in supporting documentation. Kenji Hiranabe and Eiwa System Management,Inc.
+ makes no representations about the suitability of this software for any
+ purpose. It is provided "AS IS" with NO WARRANTY.
+*/
+package javajs.util;
+
+import java.io.Serializable;
+
+import javajs.api.JSONEncodable;
+import javajs.util.T3;
+
+
+
+/**
+ * A 4 element axis angle represented by single precision floating point
+ * x,y,z,angle components. An axis angle is a rotation of angle (radians) about
+ * the vector (x,y,z).
+ *
+ * @version specification 1.1, implementation $Revision: 1.9 $, $Date:
+ * 2006/07/28 17:01:32 $
+ * @author Kenji hiranabe
+ *
+ * additions by Bob Hanson hansonr@stolaf.edu 9/30/2012
+ * for unique constructor and method names
+ * for the optimization of compiled JavaScript using Java2Script
+ */
+public class A4 implements JSONEncodable, Serializable {
+
+ /*
+ * I assumed that the length of the axis vector is not significant.
+ */
+
+ /**
+ * The x coordinate.
+ */
+ public float x;
+
+ /**
+ * The y coordinate.
+ */
+ public float y;
+
+ /**
+ * The z coordinate.
+ */
+ public float z;
+
+ /**
+ * The angle.
+ */
+ public float angle;
+
+ /**
+ * Constructs and initializes a AxisAngle4f to (0,0,1,0).
+ */
+ public A4() {
+ z = 1.0f;
+ }
+
+ /**
+ * Constructs and initializes an AxisAngle4f from the specified x, y, z, and
+ * angle.
+ *
+ * @param x
+ * the x coordinate
+ * @param y
+ * the y coordinate
+ * @param z
+ * the z coordinate
+ * @param angle
+ * the angle.
+ * @return a
+ */
+ public static A4 new4(float x, float y, float z, float angle) {
+ A4 a = new A4();
+ a.set4(x, y, z, angle);
+ return a;
+ }
+
+ /**
+ * Constructs and initializes a AxisAngle4f from the specified AxisAngle4f.
+ *
+ * @param a1
+ * the AxisAngle4f containing the initialization x y z angle data
+ * @return a
+ */
+ public static A4 newAA(A4 a1) {
+ A4 a = new A4();
+ a.set4(a1.x, a1.y, a1.z, a1.angle);
+ return a;
+ }
+
+ /**
+ * Constructs and initializes an AxisAngle4f from the specified axis and
+ * angle.
+ *
+ * @param axis
+ * the axis
+ * @param angle
+ * the angle
+ * @return a
+ */
+ public static A4 newVA(V3 axis, float angle) {
+ A4 a = new A4();
+ a.setVA(axis, angle);
+ return a;
+ }
+
+ /**
+ * Sets the value of this AxisAngle4f to the specified axis and angle.
+ *
+ * @param axis
+ * the axis
+ * @param angle
+ * the angle
+ * @since Java 3D 1.2
+ */
+ public final void setVA(V3 axis, float angle) {
+ x = axis.x;
+ y = axis.y;
+ z = axis.z;
+ this.angle = angle;
+ }
+
+ /**
+ * Sets the value of this axis angle to the specified x,y,z,angle.
+ *
+ * @param x
+ * the x coordinate
+ * @param y
+ * the y coordinate
+ * @param z
+ * the z coordinate
+ * @param angle
+ * the angle
+ */
+ public final void set4(float x, float y, float z, float angle) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ this.angle = angle;
+ }
+
+ /**
+ * Sets the value of this axis angle to the value of axis angle t1.
+ *
+ * @param a
+ * the axis angle to be copied
+ */
+ public final void setAA(A4 a) {
+ x = a.x;
+ y = a.y;
+ z = a.z;
+ angle = a.angle;
+ }
+
+
+ /**
+ * Sets the value of this axis-angle to the rotational component of the passed
+ * matrix.
+ *
+ * @param m1
+ * the matrix3f
+ */
+ public final void setM(M3 m1) {
+ setFromMat(m1.m00, m1.m01, m1.m02, m1.m10, m1.m11, m1.m12, m1.m20, m1.m21,
+ m1.m22);
+ }
+
+ // helper method
+ private void setFromMat(double m00, double m01, double m02, double m10,
+ double m11, double m12, double m20, double m21,
+ double m22) {
+ // assuming M is normalized.
+
+ double cos = (m00 + m11 + m22 - 1.0) * 0.5;
+ x = (float) (m21 - m12);
+ y = (float) (m02 - m20);
+ z = (float) (m10 - m01);
+ double sin = 0.5 * Math.sqrt(x * x + y * y + z * z);
+ if (sin == 0 && cos == 1) {
+ x = y = 0;
+ z = 1;
+ angle = 0;
+ } else {
+ angle = (float) Math.atan2(sin, cos);
+ }
+
+ // no need to normalize
+ // x /= n;
+ // y /= n;
+ // z /= n;
+ }
+
+ /**
+ * Returns a hash number based on the data values in this object. Two
+ * different AxisAngle4f objects with identical data values (ie, returns true
+ * for equals(AxisAngle4f) ) will return the same hash number. Two vectors
+ * with different data members may return the same hash value, although this
+ * is not likely.
+ */
+ @Override
+ public int hashCode() {
+ return T3.floatToIntBits0(x) ^ T3.floatToIntBits0(y)
+ ^ T3.floatToIntBits0(z) ^ T3.floatToIntBits0(angle);
+ }
+
+ /**
+ * Returns true if the Object o is of type AxisAngle4f and all of the data
+ * members of o1 are equal to the corresponding data members in this
+ * AxisAngle4f.
+ *
+ * @param o
+ * the object with which the comparison is made.
+ * @return T/F
+ */
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof A4))
+ return false;
+ A4 a1 = (A4) o;
+ return x == a1.x && y == a1.y && z == a1.z && angle == a1.angle;
+ }
+
+ /**
+ * Returns a string that contains the values of this AxisAngle4f. The form is
+ * (x,y,z,angle).
+ *
+ * @return the String representation
+ */
+ @Override
+ public String toString() {
+ return "(" + x + ", " + y + ", " + z + ", " + angle + ")";
+ }
+
+ @Override
+ public String toJSON() {
+ return "[" + x + "," + y + "," + z + "," + (float) (angle * 180.0 / Math.PI) + "]";
+ }
+}