test.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <math.h>
  5. #include "c3dlas.h"
  6. void checklinelineline() {
  7. Ray3 r1 = {
  8. .o = { 0, 0, 3},
  9. .d = { 0, 2, 0},
  10. };
  11. Ray3 r2 = {
  12. .o = { 0, 0, 1},
  13. .d = { 0, 2, 0},
  14. };
  15. Vector3 o1[] = {
  16. {99,99,99},
  17. {99,99,99},
  18. };
  19. int ret;
  20. ret = shortestLineFromRayToRay3p(&r1, &r2, o1);
  21. printf("%s\n", c3dlas_EnumString(ret));
  22. printf(" out: % .1f,% .1f,% .1f - % .1f,% .1f,% .1f\n", o1[0].x, o1[0].y, o1[0].z, o1[1].x, o1[1].y, o1[1].z);
  23. }
  24. void checklinePlaneClip() {
  25. Plane pl = {
  26. {0,0,1}, 1,
  27. };
  28. Vector3 line[] = {
  29. {0,0, -3},
  30. {0,0, -4},
  31. };
  32. Vector3 o1[] = {
  33. {99,99,99},
  34. {99,99,99},
  35. };
  36. Vector3 o2[] = {
  37. {99,99,99},
  38. {99,99,99},
  39. };
  40. int ret, i1, i2;
  41. ret = linePlaneClip3p(line, line+1, &pl, o1, o2, &i1, &i2);
  42. printf("%s\n", c3dlas_EnumString(ret));
  43. printf(" above1 %d: % .1f,% .1f,% .1f - % .1f,% .1f,% .1f\n", i1, o1[0].x, o1[0].y, o1[0].z, o1[1].x, o1[1].y, o1[1].z);
  44. printf(" below1 %d: % .1f,% .1f,% .1f - % .1f,% .1f,% .1f\n", i2, o2[0].x, o2[0].y, o2[0].z, o2[1].x, o2[1].y, o2[1].z);
  45. }
  46. void checkTriPlaneClip() {
  47. Plane pl = {
  48. {0,0,1}, 1,
  49. };
  50. Vector3 tri1[] = { // intersecting
  51. { 0,0, 5},
  52. {-3,0,-3}, // l,h
  53. { 3,0,-3},
  54. };
  55. Vector3 tri11[] = { // intersecting
  56. {-3,0, 3}, // l,h
  57. { 3,0, 3},
  58. { 0,0,-5},
  59. };
  60. Vector3 tri2[] = { // entirely above
  61. {3,4,2},
  62. {3,5,3},
  63. {3,6,7},
  64. };
  65. Vector3 tri3[] = {
  66. {-2,0, 1},
  67. { 3,0, 2},
  68. { 3,0,-2},
  69. };
  70. Vector3 l[] = {
  71. {3, 3, -4},
  72. {4, 4, 5},
  73. {4, 4, -9},
  74. };
  75. Vector3 o1[] = {
  76. {999,999,999},{999,999,999},{999,999,999},
  77. {999,999,999},{999,999,999},{999,999,999},
  78. {888,888,888},{888,888,888},{888,888,888}
  79. };
  80. Vector3 o2[] = {
  81. {999,999,999},{999,999,999},{999,999,999},
  82. {999,999,999},{999,999,999},{999,999,999},
  83. {888,888,888},{888,888,888},{888,888,888}
  84. };
  85. int ret, i1, i2;
  86. ret = triPlaneClip3p(tri3, &pl, o1, o2, &i1, &i2);
  87. printf("%s\n", c3dlas_EnumString(ret));
  88. printf(" above1 %d: % .1f,% .1f,% .1f - % .1f,% .1f,% .1f - % .1f,% .1f,% .1f \n", i1, o1[0].x, o1[0].y, o1[0].z, o1[1].x, o1[1].y, o1[1].z, o1[2].x, o1[2].y, o1[2].z);
  89. printf(" above2 %d: % .1f,% .1f,% .1f - % .1f,% .1f,% .1f - % .1f,% .1f,% .1f - %f \n", i1, o1[3].x, o1[3].y, o1[3].z, o1[4].x, o1[4].y, o1[4].z, o1[5].x, o1[5].y, o1[5].z, o1[6].x );
  90. printf(" below1 %d: % .1f,% .1f,% .1f - % .1f,% .1f,% .1f - % .1f,% .1f,% .1f \n", i2, o2[0].x, o2[0].y, o2[0].z, o2[1].x, o2[1].y, o2[1].z, o2[2].x, o2[2].y, o2[2].z);
  91. printf(" below2 %d: % .1f,% .1f,% .1f - % .1f,% .1f,% .1f - % .1f,% .1f,% .1f - %f \n", i2, o2[3].x, o2[3].y, o2[3].z, o2[4].x, o2[4].y, o2[4].z, o2[5].x, o2[5].y, o2[5].z, o2[6].x );
  92. Vector3 n[] = {{999,999,999},{999,999,999},{999,999,999},{999,999,999},{999,999,999},};
  93. vpTriFaceNormal3p(o1, &n[0]);
  94. vpTriFaceNormal3p(o1+3, &n[1]);
  95. vpTriFaceNormal3p(o2, &n[2]);
  96. vpTriFaceNormal3p(o2+3, &n[3]);
  97. vpTriFaceNormal3p(tri3, &n[4]);
  98. printf(" nin: % .2f,% .2f,% .2f\n", n[4].x, n[4].y, n[4].z);
  99. printf(" na1: % .2f,% .2f,% .2f\n", n[0].x, n[0].y, n[0].z);
  100. printf(" na2: % .2f,% .2f,% .2f\n", n[1].x, n[1].y, n[1].z);
  101. printf(" nb1: % .2f,% .2f,% .2f\n", n[2].x, n[2].y, n[2].z);
  102. printf(" nb2: % .2f,% .2f,% .2f\n", n[3].x, n[3].y, n[3].z);
  103. printf(" %f, %f, %f\n", vDot3p(n, n+2), vDot3p(n, n+1), vDot3p(n+2, n+3));
  104. }
  105. int main(int argc, char* argv) {
  106. Matrix m = IDENT_MATRIX;
  107. mOrtho(-2.2, 3.3, 4.4, -5.5, 0.66, 7.7, &m);
  108. float a,b,c,d,e,f;
  109. mOrthoExtractPlanes(&m, &a, &b, &c, &d, &e, &f);
  110. printf("%f,%f,%f,%f,%f,%f\n", a, b,c,d,e,f);
  111. return 0;
  112. }