aboutsummaryrefslogtreecommitdiff
path: root/geometry.h
blob: ec4e8d1e2147e49897c75e252f4587f3f1c84de4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#define DEG 0.01745329251994330	/* π/180 */

typedef struct Point2 Point2;
typedef struct Point3 Point3;
typedef double Matrix[3][3];
typedef double Matrix3[4][4];
typedef struct Quaternion Quaternion;
typedef struct RFrame RFrame;
typedef struct RFrame3 RFrame3;
typedef struct Triangle2 Triangle2;
typedef struct Triangle3 Triangle3;

struct Point2 {
	double x, y, w;
};

struct Point3 {
	double x, y, z, w;
};

struct Quaternion {
	double r, i, j, k;
};

struct RFrame {
	Point2 p;
	Point2 bx, by;
};

struct RFrame3 {
	Point3 p;
	Point3 bx, by, bz;
};

struct Triangle2
{
	Point2 p0, p1, p2;
};

struct Triangle3 {
	Point3 p0, p1, p2;
};

/* utils */
double flerp(double, double, double);
double fclamp(double, double, double);

/* Point2 */
Point2 Pt2(double, double, double);
Point2 Vec2(double, double);
Point2 addpt2(Point2, Point2);
Point2 subpt2(Point2, Point2);
Point2 mulpt2(Point2, double);
Point2 divpt2(Point2, double);
Point2 lerp2(Point2, Point2, double);
double dotvec2(Point2, Point2);
double vec2len(Point2);
Point2 normvec2(Point2);
int edgeptcmp(Point2, Point2, Point2);
int ptinpoly(Point2, Point2*, ulong);

/* Point3 */
Point3 Pt3(double, double, double, double);
Point3 Vec3(double, double, double);
Point3 addpt3(Point3, Point3);
Point3 subpt3(Point3, Point3);
Point3 mulpt3(Point3, double);
Point3 divpt3(Point3, double);
Point3 lerp3(Point3, Point3, double);
double dotvec3(Point3, Point3);
Point3 crossvec3(Point3, Point3);
double vec3len(Point3);
Point3 normvec3(Point3);

/* Matrix */
void identity(Matrix);
void addm(Matrix, Matrix);
void subm(Matrix, Matrix);
void mulm(Matrix, Matrix);
void smulm(Matrix, double);
void transposem(Matrix);
double detm(Matrix);
double tracem(Matrix);
void adjm(Matrix);
void invm(Matrix);
Point2 xform(Point2, Matrix);

/* Matrix3 */
void identity3(Matrix3);
void addm3(Matrix3, Matrix3);
void subm3(Matrix3, Matrix3);
void mulm3(Matrix3, Matrix3);
void smulm3(Matrix3, double);
void transposem3(Matrix3);
double detm3(Matrix3);
double tracem3(Matrix3);
void adjm3(Matrix3);
void invm3(Matrix3);
Point3 xform3(Point3, Matrix3);

/* Quaternion */
Quaternion Quat(double, double, double, double);
Quaternion Quatvec(double, Point3);
Quaternion addq(Quaternion, Quaternion);
Quaternion subq(Quaternion, Quaternion);
Quaternion mulq(Quaternion, Quaternion);
Quaternion smulq(Quaternion, double);
Quaternion sdivq(Quaternion, double);
double dotq(Quaternion, Quaternion);
Quaternion invq(Quaternion);
double qlen(Quaternion);
Quaternion normq(Quaternion);
Quaternion slerp(Quaternion, Quaternion, double);
Point3 qrotate(Point3, Point3, double);

/* RFrame */
Point2 rframexform(Point2, RFrame);
Point3 rframexform3(Point3, RFrame3);
Point2 invrframexform(Point2, RFrame);
Point3 invrframexform3(Point3, RFrame3);

/* Triangle2 */
Point2 centroid(Triangle2);
Point3 barycoords(Triangle2, Point2);

/* Triangle3 */
Point3 centroid3(Triangle3);

/* Fmt */
#pragma varargck type "v" Point2
#pragma varargck type "V" Point3
int vfmt(Fmt*);
int Vfmt(Fmt*);
void GEOMfmtinstall(void);