4 * A base class for both M3 and M4 to conserve code size.
6 * @author Kenji hiranabe
8 * additions by Bob Hanson hansonr@stolaf.edu 9/30/2012 for unique
9 * constructor and method names for the optimization of compiled
10 * JavaScript using Java2Script.
11 * and for subclassing to M3 and M4
14 public abstract class M34 {
17 * The first element of the first row
22 * The second element of the first row.
27 * third element of the first row.
32 * The first element of the second row.
37 * The second element of the second row.
42 * The third element of the second row.
47 * The first element of the third row.
52 * The second element of the third row.
57 * The third element of the third row.
61 protected void setAA33(A4 a) {
65 double angle = a.angle;
66 // Taken from Rick's which is taken from Wertz. pg. 412
67 // Bug Fixed and changed into right-handed by hiranabe
68 double n = Math.sqrt(x * x + y * y + z * z);
74 double c = Math.cos(angle);
75 double s = Math.sin(angle);
77 m00 = (float) (c + x * x * omc);
78 m11 = (float) (c + y * y * omc);
79 m22 = (float) (c + z * z * omc);
81 double tmp1 = x * y * omc;
83 m01 = (float) (tmp1 - tmp2);
84 m10 = (float) (tmp1 + tmp2);
88 m02 = (float) (tmp1 + tmp2);
89 m20 = (float) (tmp1 - tmp2);
93 m12 = (float) (tmp1 - tmp2);
94 m21 = (float) (tmp1 + tmp2);
97 public void rotate(T3 t) {
103 * Transform the vector vec using this Matrix3f and place the result into
107 * the single precision vector to be transformed
109 * the vector into which the transformed values are placed
111 public void rotate2(T3 t, T3 result) {
113 result.set(m00 * t.x + m01 * t.y + m02 * t.z, m10 * t.x + m11 * t.y + m12
114 * t.z, m20 * t.x + m21 * t.y + m22 * t.z);
119 * Sets the value of this matrix to the double value of the Matrix3f argument.
124 protected void setM33(M34 m1) {
136 protected void clear33() {
137 m00 = m01 = m02 = m10 = m11 = m12 = m20 = m21 = m22 = 0.0f;
140 protected void set33(int row, int col, float v) {
185 protected float get33(int row, int col) {
222 protected void setRow33(int row, float v[]) {
244 public abstract void getRow(int row, float v[]);
246 protected void getRow33(int row, float v[]) {
267 protected void setColumn33(int column, float v[]) {
289 protected void getColumn33(int column, float v[]) {
311 protected void add33(M34 m1) {
323 protected void sub33(M34 m1) {
335 protected void mul33(float x) {
347 protected void transpose33() {
361 protected void setXRot(float angle) {
362 double c = Math.cos(angle);
363 double s = Math.sin(angle);
375 protected void setYRot(float angle) {
376 double c = Math.cos(angle);
377 double s = Math.sin(angle);
389 protected void setZRot(float angle) {
390 double c = Math.cos(angle);
391 double s = Math.sin(angle);
404 * @return 3x3 determinant
406 public float determinant3() {
407 return m00 * (m11 * m22 - m21 * m12) - m01 * (m10 * m22 - m20 * m12) + m02
408 * (m10 * m21 - m20 * m11);
411 protected void err() {
412 throw new ArrayIndexOutOfBoundsException(
413 "matrix column/row out of bounds");