-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphmath.c
More file actions
32 lines (27 loc) · 867 Bytes
/
graphmath.c
File metadata and controls
32 lines (27 loc) · 867 Bytes
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
#include "graphmath.h"
#include <math.h>
vec2 point_projection(vec3 v3){
return (vec2){v3.x, v3.y};
}
vec3 translate(vec3 v3, vec3 o){
return (vec3){
v3.x + o.x,
v3.y + o.y,
v3.z + o.z
};
}
vec3 scale(vec3 v3, vec3 s){
return (vec3){
v3.x * s.x,
v3.y * s.y,
v3.z * s.z
};
}
vec3 rotate(vec3 v3, vec3 theta){
vec3 vp = (vec3){
v3.x*cosf(theta.z)*cosf(theta.y) + v3.y*cosf(theta.z)*sinf(theta.y)*sinf(theta.x) - v3.y*sinf(theta.z)*cosf(theta.x) + v3.z*cosf(theta.z)*sinf(theta.y)*cosf(theta.x) + v3.z*sinf(theta.z)*sinf(theta.x),
v3.x*sinf(theta.z)*cosf(theta.y) + v3.y*sinf(theta.z)*sinf(theta.y)*sinf(theta.x) + v3.y*cosf(theta.z)*cosf(theta.x) + v3.z*sinf(theta.z)*sinf(theta.y)*cosf(theta.x) - v3.z*cosf(theta.z)*sinf(theta.x),
-v3.x*sinf(theta.y) + v3.y*cosf(theta.y)*sinf(theta.x) + v3.z*cosf(theta.y)*cosf(theta.x)
};
return vp;
}