Normand Briere
2019-05-13 f924d3e00db476c06f55f3d5aaef307e17575340
LA.java
....@@ -160,6 +160,7 @@
160160
161161 static cVector xformDir(cVector v, double mat[][])
162162 {
163
+ new Exception().printStackTrace();
163164 System.exit(0);
164165 cVector temp = new cVector();
165166 xformDir(v, mat, temp);
....@@ -306,6 +307,15 @@
306307
307308 }
308309
310
+ // Last row should always be 0 0 0 1
311
+ Grafreed.Assert(Math.abs(src[0][3]) <= 1E-15);
312
+ Grafreed.Assert(Math.abs(src[1][3]) <= 1E-15);
313
+ Grafreed.Assert(Math.abs(src[2][3]) <= 1E-15);
314
+ Grafreed.Assert(Math.abs(src[3][3] - 1) <= 1E-15);
315
+ Grafreed.Assert(Math.abs(dst[0][3]) <= 1E-15);
316
+ Grafreed.Assert(Math.abs(dst[1][3]) <= 1E-15);
317
+ Grafreed.Assert(Math.abs(dst[2][3]) <= 1E-15);
318
+ Grafreed.Assert(Math.abs(dst[3][3] - 1) <= 1E-15);
309319 }
310320
311321 static double toRadians(double degrees)
....@@ -319,16 +329,16 @@
319329 //left = right;
320330 //right = tmp;
321331
322
- for (int i = 0; i < 4; i++)
332
+ for (int j = 0; j < 4; j++)
323333 {
324
- double[] lefti = left[i];
325
- double[] concati = concatTemp[i];
326
- for (int j = 0; j < 4; j++)
334
+ double[] rightj = right[j];
335
+ double[] concat = concatTemp[j];
336
+ for (int i = 0; i < 4; i++)
327337 {
328
- concati[j] = 0;
338
+ concat[i] = 0;
329339 for (int k = 0; k < 4; k++)
330340 {
331
- concati[j] += lefti[k] * right[k][j];
341
+ concat[i] += left[k][i] * rightj[k];
332342 }
333343 }
334344 }
....@@ -345,7 +355,7 @@
345355 //xlateTemp[0][3] = dx;
346356 //xlateTemp[1][3] = dy;
347357 //xlateTemp[2][3] = dz;
348
- matConcat(mat, xlateTemp, mat);
358
+ matConcat(xlateTemp, mat, mat);
349359 }
350360
351361 static void matHomogene(double mat[][], double dx, double dy, double dz)
....@@ -357,7 +367,7 @@
357367 //xlateTemp[0][3] = dx;
358368 //xlateTemp[1][3] = dy;
359369 //xlateTemp[2][3] = dz;
360
- matConcat(mat, xlateTemp, mat);
370
+ matConcat(xlateTemp, mat, mat);
361371 }
362372
363373 static void matTranslateInv(double mat[][], double dx, double dy, double dz)
....@@ -369,7 +379,7 @@
369379 //xlateTemp[0][3] = dx;
370380 //xlateTemp[1][3] = dy;
371381 //xlateTemp[2][3] = dz;
372
- matConcat(xlateTemp, mat, mat);
382
+ matConcat(mat, xlateTemp, mat);
373383 }
374384
375385 static void matScale(double mat[][], double sx, double sy, double sz)
....@@ -378,7 +388,8 @@
378388 xlateTemp[0][0] = sx;
379389 xlateTemp[1][1] = sy;
380390 xlateTemp[2][2] = sz;
381
- matConcat(mat, xlateTemp, mat);
391
+ matConcat(xlateTemp, mat, mat);
392
+ //matConcat(mat, xlateTemp, mat);
382393 }
383394
384395 static void matXRotate(double mat[][], double radians)
....@@ -387,9 +398,9 @@
387398 rotTemp[1][1] = rotTemp[2][2] = (double) Math.cos(radians);
388399 rotTemp[2][1] = -(rotTemp[1][2] = (double) Math.sin(radians));
389400 // if (CameraPane.LOCALTRANSFORM)
390
- // matConcat(rotTemp, mat, mat);
401
+ matConcat(rotTemp, mat, mat);
391402 // else
392
- matConcat(mat, rotTemp, mat);
403
+ // matConcat(mat, rotTemp, mat);
393404 }
394405
395406 static void matYRotate(double mat[][], double radians)
....@@ -398,9 +409,9 @@
398409 rotTemp[0][0] = rotTemp[2][2] = (double) Math.cos(-radians);
399410 rotTemp[2][0] = -(rotTemp[0][2] = (double) Math.sin(-radians));
400411 // if (CameraPane.LOCALTRANSFORM)
401
- // matConcat(rotTemp, mat, mat);
412
+ matConcat(rotTemp, mat, mat);
402413 // else
403
- matConcat(mat, rotTemp, mat);
414
+ // matConcat(mat, rotTemp, mat);
404415 }
405416
406417 static void matZRotate(double mat[][], double radians)
....@@ -409,9 +420,9 @@
409420 rotTemp[0][0] = rotTemp[1][1] = (double) Math.cos(radians);
410421 rotTemp[1][0] = -(rotTemp[0][1] = (double) Math.sin(radians));
411422 // if (CameraPane.LOCALTRANSFORM)
412
- // matConcat(rotTemp, mat, mat);
423
+ matConcat(rotTemp, mat, mat);
413424 // else
414
- matConcat(mat, rotTemp, mat);
425
+ // matConcat(mat, rotTemp, mat);
415426 }
416427
417428 // Project A onto B
....@@ -614,6 +625,7 @@
614625 private static int indxr[] = new int[4];
615626 private static int indxc[] = new int[4];
616627
628
+ static double[][] Identity = new double[4][4];
617629
618630 static int SIZE = 0; // 65536*64;
619631
....@@ -629,6 +641,8 @@
629641 costable[i] = Math.cos(PI2 * i/SIZE);
630642 sintable[i] = Math.sin(PI2 * i*i/SIZE/SIZE);
631643 }
644
+
645
+ LA.matIdentity(Identity);
632646 }
633647
634648 static double cos(double x0)