geometry.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #pragma lib "libgeometry.a"
  2. #pragma src "/sys/src/libgeometry"
  3. typedef double Matrix[4][4];
  4. typedef struct Point3 Point3;
  5. typedef struct Quaternion Quaternion;
  6. typedef struct Space Space;
  7. struct Point3{
  8. double x, y, z, w;
  9. };
  10. struct Quaternion{
  11. double r, i, j, k;
  12. };
  13. struct Space{
  14. Matrix t;
  15. Matrix tinv;
  16. Space *next;
  17. };
  18. /*
  19. * 3-d point arithmetic
  20. */
  21. Point3 add3(Point3 a, Point3 b);
  22. Point3 sub3(Point3 a, Point3 b);
  23. Point3 neg3(Point3 a);
  24. Point3 div3(Point3 a, double b);
  25. Point3 mul3(Point3 a, double b);
  26. int eqpt3(Point3 p, Point3 q);
  27. int closept3(Point3 p, Point3 q, double eps);
  28. double dot3(Point3 p, Point3 q);
  29. Point3 cross3(Point3 p, Point3 q);
  30. double len3(Point3 p);
  31. double dist3(Point3 p, Point3 q);
  32. Point3 unit3(Point3 p);
  33. Point3 midpt3(Point3 p, Point3 q);
  34. Point3 lerp3(Point3 p, Point3 q, double alpha);
  35. Point3 reflect3(Point3 p, Point3 p0, Point3 p1);
  36. Point3 nearseg3(Point3 p0, Point3 p1, Point3 testp);
  37. double pldist3(Point3 p, Point3 p0, Point3 p1);
  38. double vdiv3(Point3 a, Point3 b);
  39. Point3 vrem3(Point3 a, Point3 b);
  40. Point3 pn2f3(Point3 p, Point3 n);
  41. Point3 ppp2f3(Point3 p0, Point3 p1, Point3 p2);
  42. Point3 fff2p3(Point3 f0, Point3 f1, Point3 f2);
  43. Point3 pdiv4(Point3 a);
  44. Point3 add4(Point3 a, Point3 b);
  45. Point3 sub4(Point3 a, Point3 b);
  46. /*
  47. * Quaternion arithmetic
  48. */
  49. void qtom(Matrix, Quaternion);
  50. Quaternion mtoq(Matrix);
  51. Quaternion qadd(Quaternion, Quaternion);
  52. Quaternion qsub(Quaternion, Quaternion);
  53. Quaternion qneg(Quaternion);
  54. Quaternion qmul(Quaternion, Quaternion);
  55. Quaternion qdiv(Quaternion, Quaternion);
  56. Quaternion qunit(Quaternion);
  57. Quaternion qinv(Quaternion);
  58. double qlen(Quaternion);
  59. Quaternion slerp(Quaternion, Quaternion, double);
  60. Quaternion qmid(Quaternion, Quaternion);
  61. Quaternion qsqrt(Quaternion);
  62. void qball(Rectangle, Mouse *, Quaternion *, void (*)(void), Quaternion *);
  63. /*
  64. * Matrix arithmetic
  65. */
  66. void ident(Matrix);
  67. void matmul(Matrix, Matrix);
  68. void matmulr(Matrix, Matrix);
  69. double determinant(Matrix);
  70. void adjoint(Matrix, Matrix);
  71. double invertmat(Matrix, Matrix);
  72. /*
  73. * Space stack routines
  74. */
  75. Space *pushmat(Space *);
  76. Space *popmat(Space *);
  77. void rot(Space *, double, int);
  78. void qrot(Space *, Quaternion);
  79. void scale(Space *, double, double, double);
  80. void move(Space *, double, double, double);
  81. void xform(Space *, Matrix);
  82. void ixform(Space *, Matrix, Matrix);
  83. void look(Space *, Point3, Point3, Point3);
  84. int persp(Space *, double, double, double);
  85. void viewport(Space *, Rectangle, double);
  86. Point3 xformpoint(Point3, Space *, Space *);
  87. Point3 xformpointd(Point3, Space *, Space *);
  88. Point3 xformplane(Point3, Space *, Space *);
  89. #define radians(d) ((d)*.01745329251994329572)