-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeometry.h
47 lines (38 loc) · 1.05 KB
/
geometry.h
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
#ifndef GEOMETRY_H
#define GEOMETRY_H
typedef struct {
int x, y;
} Vec2i;
typedef struct {
float x, y;
} Vec2f;
typedef struct {
float x, y, z;
} Vec3f;
Vec3f mult_scalar_vec(float s, Vec3f v);
float vec_magnitude(Vec3f v);
float dot(Vec3f a, Vec3f b);
Vec3f crossProduct(Vec3f a, Vec3f b);
Vec3f vec_add(Vec3f a, Vec3f b);
Vec3f vec_minus(Vec3f a, Vec3f b);
Vec3f normalize(Vec3f a);
float edgeFunction(const Vec3f a, const Vec3f b, const Vec3f c);
Vec3f barycentric(Vec3f v0, Vec3f v1, Vec3f v2, Vec3f p);
typedef struct {
float mat[4][4];
} Matrix44f;
Matrix44f identity();
Vec3f multVecMatrix(Vec3f v, Matrix44f m);
Matrix44f inverse(Matrix44f m);
Matrix44f transpose(Matrix44f m);
Matrix44f lookAt(Vec3f from, Vec3f to);
typedef struct {
float s; // real scalar part
Vec3f v; // imaginary part
} Quat;
#define QUAT_NEW(s, v) \
(Quat) { (s), (v) }
Matrix44f quat_rotation_matrix(Quat *q);
Quat quat_multiply(Quat q1, Quat q2);
Quat quat_from_axis_angle(Vec3f axis, float radians);
#endif