Normand Briere
2019-10-06 ce660a4b6ba367bd162dd2cff26d02c80a34c912
LA.java
....@@ -88,6 +88,9 @@
8888
8989 static void vecCopy(cVector a, cVector b)
9090 {
91
+ Grafreed.Assert (a != null);
92
+ assert (b != null);
93
+
9194 b.x = a.x;
9295 b.y = a.y;
9396 b.z = a.z;
....@@ -160,6 +163,7 @@
160163
161164 static cVector xformDir(cVector v, double mat[][])
162165 {
166
+ new Exception().printStackTrace();
163167 System.exit(0);
164168 cVector temp = new cVector();
165169 xformDir(v, mat, temp);
....@@ -306,6 +310,15 @@
306310
307311 }
308312
313
+ // Last row should always be 0 0 0 1
314
+ Grafreed.Assert(Math.abs(src[0][3]) <= 1E-15);
315
+ Grafreed.Assert(Math.abs(src[1][3]) <= 1E-15);
316
+ Grafreed.Assert(Math.abs(src[2][3]) <= 1E-15);
317
+ Grafreed.Assert(Math.abs(src[3][3] - 1) <= 1E-15);
318
+ Grafreed.Assert(Math.abs(dst[0][3]) <= 1E-15);
319
+ Grafreed.Assert(Math.abs(dst[1][3]) <= 1E-15);
320
+ Grafreed.Assert(Math.abs(dst[2][3]) <= 1E-15);
321
+ Grafreed.Assert(Math.abs(dst[3][3] - 1) <= 1E-15);
309322 }
310323
311324 static double toRadians(double degrees)
....@@ -319,16 +332,16 @@
319332 //left = right;
320333 //right = tmp;
321334
322
- for (int i = 0; i < 4; i++)
335
+ for (int j = 0; j < 4; j++)
323336 {
324
- double[] lefti = left[i];
325
- double[] concati = concatTemp[i];
326
- for (int j = 0; j < 4; j++)
337
+ double[] rightj = right[j];
338
+ double[] concat = concatTemp[j];
339
+ for (int i = 0; i < 4; i++)
327340 {
328
- concati[j] = 0;
341
+ concat[i] = 0;
329342 for (int k = 0; k < 4; k++)
330343 {
331
- concati[j] += lefti[k] * right[k][j];
344
+ concat[i] += left[k][i] * rightj[k];
332345 }
333346 }
334347 }
....@@ -345,7 +358,7 @@
345358 //xlateTemp[0][3] = dx;
346359 //xlateTemp[1][3] = dy;
347360 //xlateTemp[2][3] = dz;
348
- matConcat(mat, xlateTemp, mat);
361
+ matConcat(xlateTemp, mat, mat);
349362 }
350363
351364 static void matHomogene(double mat[][], double dx, double dy, double dz)
....@@ -357,7 +370,7 @@
357370 //xlateTemp[0][3] = dx;
358371 //xlateTemp[1][3] = dy;
359372 //xlateTemp[2][3] = dz;
360
- matConcat(mat, xlateTemp, mat);
373
+ matConcat(xlateTemp, mat, mat);
361374 }
362375
363376 static void matTranslateInv(double mat[][], double dx, double dy, double dz)
....@@ -369,7 +382,7 @@
369382 //xlateTemp[0][3] = dx;
370383 //xlateTemp[1][3] = dy;
371384 //xlateTemp[2][3] = dz;
372
- matConcat(xlateTemp, mat, mat);
385
+ matConcat(mat, xlateTemp, mat);
373386 }
374387
375388 static void matScale(double mat[][], double sx, double sy, double sz)
....@@ -378,7 +391,8 @@
378391 xlateTemp[0][0] = sx;
379392 xlateTemp[1][1] = sy;
380393 xlateTemp[2][2] = sz;
381
- matConcat(mat, xlateTemp, mat);
394
+ matConcat(xlateTemp, mat, mat);
395
+ //matConcat(mat, xlateTemp, mat);
382396 }
383397
384398 static void matXRotate(double mat[][], double radians)
....@@ -387,9 +401,9 @@
387401 rotTemp[1][1] = rotTemp[2][2] = (double) Math.cos(radians);
388402 rotTemp[2][1] = -(rotTemp[1][2] = (double) Math.sin(radians));
389403 // if (CameraPane.LOCALTRANSFORM)
390
- // matConcat(rotTemp, mat, mat);
404
+ matConcat(rotTemp, mat, mat);
391405 // else
392
- matConcat(mat, rotTemp, mat);
406
+ // matConcat(mat, rotTemp, mat);
393407 }
394408
395409 static void matYRotate(double mat[][], double radians)
....@@ -398,9 +412,9 @@
398412 rotTemp[0][0] = rotTemp[2][2] = (double) Math.cos(-radians);
399413 rotTemp[2][0] = -(rotTemp[0][2] = (double) Math.sin(-radians));
400414 // if (CameraPane.LOCALTRANSFORM)
401
- // matConcat(rotTemp, mat, mat);
415
+ matConcat(rotTemp, mat, mat);
402416 // else
403
- matConcat(mat, rotTemp, mat);
417
+ // matConcat(mat, rotTemp, mat);
404418 }
405419
406420 static void matZRotate(double mat[][], double radians)
....@@ -409,9 +423,9 @@
409423 rotTemp[0][0] = rotTemp[1][1] = (double) Math.cos(radians);
410424 rotTemp[1][0] = -(rotTemp[0][1] = (double) Math.sin(radians));
411425 // if (CameraPane.LOCALTRANSFORM)
412
- // matConcat(rotTemp, mat, mat);
426
+ matConcat(rotTemp, mat, mat);
413427 // else
414
- matConcat(mat, rotTemp, mat);
428
+ // matConcat(mat, rotTemp, mat);
415429 }
416430
417431 // Project A onto B
....@@ -614,6 +628,7 @@
614628 private static int indxr[] = new int[4];
615629 private static int indxc[] = new int[4];
616630
631
+ static double[][] Identity = new double[4][4];
617632
618633 static int SIZE = 0; // 65536*64;
619634
....@@ -629,6 +644,8 @@
629644 costable[i] = Math.cos(PI2 * i/SIZE);
630645 sintable[i] = Math.sin(PI2 * i*i/SIZE/SIZE);
631646 }
647
+
648
+ LA.matIdentity(Identity);
632649 }
633650
634651 static double cos(double x0)