1 package org.web3d.x3d.sai;
4 public float[][] matrix;
5 public static int SIZE = 3;
9 matrix =
new float[SIZE][SIZE];
10 for (i = 0; i < SIZE; i++) {
11 for (j=0; j<SIZE; j++) {
22 if (init.length < SIZE*SIZE) {
23 throw new ArrayIndexOutOfBoundsException(
"Initialization array passed to Matrix3 of insufficient length");
26 matrix =
new float[SIZE][SIZE];
29 for (i = 0; i < SIZE; i++) {
30 for (j = 0; j < SIZE; j++) {
31 matrix[i][j] = init[count];
37 public void setIdentity() {
40 for (i = 0; i < SIZE; i++) {
41 for (j = 0; j < SIZE; j++) {
51 public void set(
int row,
int column,
float value) {
52 if ((row > SIZE) || (row < 0) || (column > SIZE) || (column < 0)) {
53 throw new ArrayIndexOutOfBoundsException(
"Matrix 3 set passed invalid row or column value");
56 matrix[row][column] = value;
58 public float get(
int row,
int column){
59 if ((row > SIZE) || (row < 0) || (column > SIZE) || (column < 0)) {
60 throw new ArrayIndexOutOfBoundsException(
"Matrix 3 set passed invalid row or column value");
63 return matrix[row][column];
87 rot =
new float[SIZE][SIZE];
88 srot =
new float[SIZE][SIZE];
89 rrot =
new float[SIZE][SIZE];
90 nsrot =
new float[SIZE][SIZE];
91 trans =
new float[SIZE][SIZE];
92 strans =
new float[SIZE][SIZE];
93 rtrans =
new float[SIZE][SIZE];
94 nstrans =
new float[SIZE][SIZE];
95 sc =
new float[SIZE][SIZE];
96 finalscale =
new float[SIZE][SIZE];
98 value =
new float[SIZE];
99 axisr =
new float[SIZE];
101 for (i = 0; i < SIZE; i++) {
102 for (j=0; j < SIZE; j++) {
111 nstrans[i][j] = 1.0F;
113 finalscale[i][j] = 1.0F;
118 nstrans[i][j] = 0.0F;
124 finalscale[i][j] = 0.0F;
129 if (translation != null) {
131 translation.getValue(value);
132 }
catch (Exception e) {
133 System.out.println(e);
136 trans[2][0] = value[0];
137 trans[2][1] = value[1];
142 scale.getValue(value);
143 }
catch (Exception e) {
144 System.out.println(e);
150 if (centre != null) {
152 centre.getValue(value);
153 }
catch (Exception e) {
154 System.out.println(e);
157 strans[3][0] = value[0];
158 strans[3][1] = value[1];
162 if (scaleOrientation!=null) {
164 scaleOrientation.getValue(axisr);
165 }
catch (Exception e) {
166 System.out.println(e);
170 rtrans[2][0] = -1*axisr[0];
171 rtrans[2][1] = -1*axisr[1];
173 rrot[0][0] = (float)(Math.cos(axisr[2]));
174 rrot[0][1] = (float)(Math.sin(axisr[2]));
175 rrot[0][0] = (float)(-1.0*Math.sin(axisr[2]));
176 rrot[0][0] = (float)(Math.cos(axisr[2]));
178 srot = multiply(rtrans, rrot);
180 rtrans[2][0] = axisr[0];
181 rtrans[2][1] = axisr[1];
183 srot = multiply(rot, rtrans);
188 for (i = 0; i < SIZE; i++) {
189 for (j=0; j< SIZE; j++) {
190 nsrot[i][j] *= -1.0F;
191 nstrans[i][j] *= -1.0F;
198 if (rotation != null) {
201 rotation.getValue(axisr);
202 }
catch (Exception e) {
203 System.out.println(e);
206 rtrans[2][0] = -1*axisr[0];
207 rtrans[2][1] = -1*axisr[1];
209 rrot[0][0] = (float)(Math.cos(axisr[2]));
210 rrot[0][1] = (float)(Math.sin(axisr[2]));
211 rrot[0][0] = (float)(-1.0*Math.sin(axisr[2]));
212 rrot[0][0] = (float)(Math.cos(axisr[2]));
214 rot = multiply(rtrans, rrot);
216 rtrans[2][0] = axisr[0];
217 rtrans[2][1] = axisr[1];
219 rot = multiply(rot, rtrans);
223 matrix = multiply(matrix, trans);
224 matrix = multiply(matrix, strans);
225 matrix = multiply(matrix, rot);
226 matrix = multiply(matrix, srot);
227 matrix = multiply(matrix, sc);
228 matrix = multiply(matrix, nsrot);
229 matrix = multiply(matrix, nstrans);
244 translation.setValue(t);
249 s[0] = (float) (Math.sqrt(matrix[0][0]*matrix[0][0] + matrix[1][0]*matrix[1][0] + matrix[2][0]*matrix[2][0] + matrix[3][0]*matrix[3][0]));
250 s[1] = (float) (Math.sqrt(matrix[0][1]*matrix[0][1] + matrix[1][1]*matrix[1][1] + matrix[2][1]*matrix[2][1] + matrix[3][1]*matrix[3][1]));
256 angle = (float)(Math.acos(matrix[0][0]));
262 rotation.setValue(r);
265 public float[][] multiply(
float[][] multp,
float[][] mat) {
270 ans =
new float[SIZE][SIZE];
272 for (i = 0; i < SIZE; i++) {
273 for (j=0; j < SIZE; j++) {
275 for (k = 0; k < SIZE; k++) {
276 sum = sum + multp[i][k]*mat[k][j];
287 float a,b,c,d,e,f,g,h,i;
300 inverse =
new float[9];
302 A = (a*(e*i-f*h) - b*(d*i-f*g) + c*(d*h - e*g));
310 inverse[0] = A*(e*i - f*h);
311 inverse[1] = A*(c*h - b*i);
312 inverse[2] = A*(b*f - c*e);
313 inverse[3] = A*(f*g - d*i);
314 inverse[4] = A*(a*i - c*g);
315 inverse[5] = A*(c*d - a*f);
316 inverse[6] = A*(d*h - e*g);
317 inverse[7] = A*(b*g - a*h);
318 inverse[8] = A*(a*e - b*d);
328 transp =
new float[9];
330 for (i = 0; i < SIZE; i++) {
331 for (j = 0; j < SIZE; j++) {
332 transp[j*SIZE + i] = matrix[i][j];
345 multp =
new float[SIZE][SIZE];
347 for ( i = 0; i < SIZE; i++) {
348 for (j = 0; j < SIZE; j++) {
349 multp[i][j] = mat.get(i, j);
353 ans =
new float[SIZE*SIZE];
355 for (i = 0; i < SIZE; i++) {
356 for (j=0; j < SIZE; j++) {
358 for (k = 0; k < SIZE; k++) {
359 sum = sum + multp[i][k]*matrix[k][j];
361 ans[(i*SIZE)+j] = sum;
375 multp =
new float[SIZE][SIZE];
377 for ( i = 0; i < SIZE; i++) {
378 for (j = 0; j < SIZE; j++) {
379 multp[i][j] = mat.get(i, j);
383 ans =
new float[SIZE*SIZE];
385 for (i = 0; i < SIZE; i++) {
386 for (j=0; j < SIZE; j++) {
388 for (k = 0; k < SIZE; k++) {
389 sum = sum + matrix[i][k]*multp[k][j];
398 public float[] multiplyRowVector(
float[] vec) {
403 ans =
new float[SIZE];
405 for (i = 0; i < SIZE; i++) {
407 for (k = 0; k < SIZE; k++) {
408 sum = sum + vec[k] * matrix[i][k];
416 public float[] multiplyColVector(
float[] vec) {
421 ans =
new float[SIZE*SIZE];
423 for (i = 0; i < SIZE; i++) {
425 for (k = 0; k < SIZE; k++) {
426 sum = sum + matrix[k][i]*vec[k];