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