.. | .. |
---|
88 | 88 | |
---|
89 | 89 | static void vecCopy(cVector a, cVector b) |
---|
90 | 90 | { |
---|
| 91 | + Grafreed.Assert (a != null); |
---|
| 92 | + assert (b != null); |
---|
| 93 | + |
---|
91 | 94 | b.x = a.x; |
---|
92 | 95 | b.y = a.y; |
---|
93 | 96 | b.z = a.z; |
---|
.. | .. |
---|
160 | 163 | |
---|
161 | 164 | static cVector xformDir(cVector v, double mat[][]) |
---|
162 | 165 | { |
---|
| 166 | + new Exception().printStackTrace(); |
---|
163 | 167 | System.exit(0); |
---|
164 | 168 | cVector temp = new cVector(); |
---|
165 | 169 | xformDir(v, mat, temp); |
---|
.. | .. |
---|
306 | 310 | |
---|
307 | 311 | } |
---|
308 | 312 | |
---|
| 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); |
---|
309 | 322 | } |
---|
310 | 323 | |
---|
311 | 324 | static double toRadians(double degrees) |
---|
.. | .. |
---|
319 | 332 | //left = right; |
---|
320 | 333 | //right = tmp; |
---|
321 | 334 | |
---|
322 | | - for (int i = 0; i < 4; i++) |
---|
| 335 | + for (int j = 0; j < 4; j++) |
---|
323 | 336 | { |
---|
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++) |
---|
327 | 340 | { |
---|
328 | | - concati[j] = 0; |
---|
| 341 | + concat[i] = 0; |
---|
329 | 342 | for (int k = 0; k < 4; k++) |
---|
330 | 343 | { |
---|
331 | | - concati[j] += lefti[k] * right[k][j]; |
---|
| 344 | + concat[i] += left[k][i] * rightj[k]; |
---|
332 | 345 | } |
---|
333 | 346 | } |
---|
334 | 347 | } |
---|
.. | .. |
---|
345 | 358 | //xlateTemp[0][3] = dx; |
---|
346 | 359 | //xlateTemp[1][3] = dy; |
---|
347 | 360 | //xlateTemp[2][3] = dz; |
---|
348 | | - matConcat(mat, xlateTemp, mat); |
---|
| 361 | + matConcat(xlateTemp, mat, mat); |
---|
349 | 362 | } |
---|
350 | 363 | |
---|
351 | 364 | static void matHomogene(double mat[][], double dx, double dy, double dz) |
---|
.. | .. |
---|
357 | 370 | //xlateTemp[0][3] = dx; |
---|
358 | 371 | //xlateTemp[1][3] = dy; |
---|
359 | 372 | //xlateTemp[2][3] = dz; |
---|
360 | | - matConcat(mat, xlateTemp, mat); |
---|
| 373 | + matConcat(xlateTemp, mat, mat); |
---|
361 | 374 | } |
---|
362 | 375 | |
---|
363 | 376 | static void matTranslateInv(double mat[][], double dx, double dy, double dz) |
---|
.. | .. |
---|
369 | 382 | //xlateTemp[0][3] = dx; |
---|
370 | 383 | //xlateTemp[1][3] = dy; |
---|
371 | 384 | //xlateTemp[2][3] = dz; |
---|
372 | | - matConcat(xlateTemp, mat, mat); |
---|
| 385 | + matConcat(mat, xlateTemp, mat); |
---|
373 | 386 | } |
---|
374 | 387 | |
---|
375 | 388 | static void matScale(double mat[][], double sx, double sy, double sz) |
---|
.. | .. |
---|
378 | 391 | xlateTemp[0][0] = sx; |
---|
379 | 392 | xlateTemp[1][1] = sy; |
---|
380 | 393 | xlateTemp[2][2] = sz; |
---|
381 | | - matConcat(mat, xlateTemp, mat); |
---|
| 394 | + matConcat(xlateTemp, mat, mat); |
---|
| 395 | + //matConcat(mat, xlateTemp, mat); |
---|
382 | 396 | } |
---|
383 | 397 | |
---|
384 | 398 | static void matXRotate(double mat[][], double radians) |
---|
.. | .. |
---|
387 | 401 | rotTemp[1][1] = rotTemp[2][2] = (double) Math.cos(radians); |
---|
388 | 402 | rotTemp[2][1] = -(rotTemp[1][2] = (double) Math.sin(radians)); |
---|
389 | 403 | // if (CameraPane.LOCALTRANSFORM) |
---|
390 | | - // matConcat(rotTemp, mat, mat); |
---|
| 404 | + matConcat(rotTemp, mat, mat); |
---|
391 | 405 | // else |
---|
392 | | - matConcat(mat, rotTemp, mat); |
---|
| 406 | + // matConcat(mat, rotTemp, mat); |
---|
393 | 407 | } |
---|
394 | 408 | |
---|
395 | 409 | static void matYRotate(double mat[][], double radians) |
---|
.. | .. |
---|
398 | 412 | rotTemp[0][0] = rotTemp[2][2] = (double) Math.cos(-radians); |
---|
399 | 413 | rotTemp[2][0] = -(rotTemp[0][2] = (double) Math.sin(-radians)); |
---|
400 | 414 | // if (CameraPane.LOCALTRANSFORM) |
---|
401 | | - // matConcat(rotTemp, mat, mat); |
---|
| 415 | + matConcat(rotTemp, mat, mat); |
---|
402 | 416 | // else |
---|
403 | | - matConcat(mat, rotTemp, mat); |
---|
| 417 | + // matConcat(mat, rotTemp, mat); |
---|
404 | 418 | } |
---|
405 | 419 | |
---|
406 | 420 | static void matZRotate(double mat[][], double radians) |
---|
.. | .. |
---|
409 | 423 | rotTemp[0][0] = rotTemp[1][1] = (double) Math.cos(radians); |
---|
410 | 424 | rotTemp[1][0] = -(rotTemp[0][1] = (double) Math.sin(radians)); |
---|
411 | 425 | // if (CameraPane.LOCALTRANSFORM) |
---|
412 | | - // matConcat(rotTemp, mat, mat); |
---|
| 426 | + matConcat(rotTemp, mat, mat); |
---|
413 | 427 | // else |
---|
414 | | - matConcat(mat, rotTemp, mat); |
---|
| 428 | + // matConcat(mat, rotTemp, mat); |
---|
415 | 429 | } |
---|
416 | 430 | |
---|
417 | 431 | // Project A onto B |
---|
.. | .. |
---|
614 | 628 | private static int indxr[] = new int[4]; |
---|
615 | 629 | private static int indxc[] = new int[4]; |
---|
616 | 630 | |
---|
| 631 | + static double[][] Identity = new double[4][4]; |
---|
617 | 632 | |
---|
618 | 633 | static int SIZE = 0; // 65536*64; |
---|
619 | 634 | |
---|
.. | .. |
---|
629 | 644 | costable[i] = Math.cos(PI2 * i/SIZE); |
---|
630 | 645 | sintable[i] = Math.sin(PI2 * i*i/SIZE/SIZE); |
---|
631 | 646 | } |
---|
| 647 | + |
---|
| 648 | + LA.matIdentity(Identity); |
---|
632 | 649 | } |
---|
633 | 650 | |
---|
634 | 651 | static double cos(double x0) |
---|