2 Copyright (C) 1997,1998,1999
\r
3 Kenji Hiranabe, Eiwa System Management, Inc.
\r
5 This program is free software.
\r
6 Implemented by Kenji Hiranabe(hiranabe@esm.co.jp),
\r
7 conforming to the Java(TM) 3D API specification by Sun Microsystems.
\r
9 Permission to use, copy, modify, distribute and sell this software
\r
10 and its documentation for any purpose is hereby granted without fee,
\r
11 provided that the above copyright notice appear in all copies and
\r
12 that both that copyright notice and this permission notice appear
\r
13 in supporting documentation. Kenji Hiranabe and Eiwa System Management,Inc.
\r
14 makes no representations about the suitability of this software for any
\r
15 purpose. It is provided "AS IS" with NO WARRANTY.
\r
17 package javajs.util;
\r
19 import java.io.Serializable;
\r
21 import javajs.api.JSONEncodable;
\r
22 import javajs.util.T3;
\r
27 * A 4 element axis angle represented by single precision floating point
\r
28 * x,y,z,angle components. An axis angle is a rotation of angle (radians) about
\r
29 * the vector (x,y,z).
\r
31 * @version specification 1.1, implementation $Revision: 1.9 $, $Date:
\r
32 * 2006/07/28 17:01:32 $
\r
33 * @author Kenji hiranabe
\r
35 * additions by Bob Hanson hansonr@stolaf.edu 9/30/2012
\r
36 * for unique constructor and method names
\r
37 * for the optimization of compiled JavaScript using Java2Script
\r
39 public class A4 implements JSONEncodable, Serializable {
\r
42 * I assumed that the length of the axis vector is not significant.
\r
66 * Constructs and initializes a AxisAngle4f to (0,0,1,0).
\r
73 * Constructs and initializes an AxisAngle4f from the specified x, y, z, and
\r
86 public static A4 new4(float x, float y, float z, float angle) {
\r
88 a.set4(x, y, z, angle);
\r
93 * Constructs and initializes a AxisAngle4f from the specified AxisAngle4f.
\r
96 * the AxisAngle4f containing the initialization x y z angle data
\r
99 public static A4 newAA(A4 a1) {
\r
101 a.set4(a1.x, a1.y, a1.z, a1.angle);
\r
106 * Constructs and initializes an AxisAngle4f from the specified axis and
\r
115 public static A4 newVA(V3 axis, float angle) {
\r
117 a.setVA(axis, angle);
\r
122 * Sets the value of this AxisAngle4f to the specified axis and angle.
\r
128 * @since Java 3D 1.2
\r
130 public final void setVA(V3 axis, float angle) {
\r
134 this.angle = angle;
\r
138 * Sets the value of this axis angle to the specified x,y,z,angle.
\r
149 public final void set4(float x, float y, float z, float angle) {
\r
153 this.angle = angle;
\r
157 * Sets the value of this axis angle to the value of axis angle t1.
\r
160 * the axis angle to be copied
\r
162 public final void setAA(A4 a) {
\r
171 * Sets the value of this axis-angle to the rotational component of the passed
\r
177 public final void setM(M3 m1) {
\r
178 setFromMat(m1.m00, m1.m01, m1.m02, m1.m10, m1.m11, m1.m12, m1.m20, m1.m21,
\r
183 private void setFromMat(double m00, double m01, double m02, double m10,
\r
184 double m11, double m12, double m20, double m21,
\r
186 // assuming M is normalized.
\r
188 double cos = (m00 + m11 + m22 - 1.0) * 0.5;
\r
189 x = (float) (m21 - m12);
\r
190 y = (float) (m02 - m20);
\r
191 z = (float) (m10 - m01);
\r
192 double sin = 0.5 * Math.sqrt(x * x + y * y + z * z);
\r
193 if (sin == 0 && cos == 1) {
\r
198 angle = (float) Math.atan2(sin, cos);
\r
201 // no need to normalize
\r
208 * Returns a hash number based on the data values in this object. Two
\r
209 * different AxisAngle4f objects with identical data values (ie, returns true
\r
210 * for equals(AxisAngle4f) ) will return the same hash number. Two vectors
\r
211 * with different data members may return the same hash value, although this
\r
215 public int hashCode() {
\r
216 return T3.floatToIntBits0(x) ^ T3.floatToIntBits0(y)
\r
217 ^ T3.floatToIntBits0(z) ^ T3.floatToIntBits0(angle);
\r
221 * Returns true if the Object o is of type AxisAngle4f and all of the data
\r
222 * members of o1 are equal to the corresponding data members in this
\r
226 * the object with which the comparison is made.
\r
230 public boolean equals(Object o) {
\r
231 if (!(o instanceof A4))
\r
234 return x == a1.x && y == a1.y && z == a1.z && angle == a1.angle;
\r
238 * Returns a string that contains the values of this AxisAngle4f. The form is
\r
241 * @return the String representation
\r
244 public String toString() {
\r
245 return "(" + x + ", " + y + ", " + z + ", " + angle + ")";
\r
249 public String toJSON() {
\r
250 return "[" + x + "," + y + "," + z + "," + (float) (angle * 180.0 / Math.PI) + "]";
\r