-
Notifications
You must be signed in to change notification settings - Fork 0
/
vec3.sj
98 lines (85 loc) · 1.6 KB
/
vec3.sj
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
vec3(
x : 0.0f
y : 0.0f
z : 0.0f
isEqual(v : 'vec3) {
x == v.x && y == v.y && z == v.z
}
interpolate(v : 'vec3, percent : 'f32) {
vec3(
x : x * (1.0f - percent) + v.x * percent
y : y * (1.0f - percent) + v.y * percent
z : z * (1.0f - percent) + v.z * percent
)
}
asString() {
x.asString() + ", " + y.asString() + ", " + z.asString()
}
add(v : 'vec3) {
vec3(
x + v.x
y + v.y
z + v.z
)
}
subtract(v : 'vec3) {
vec3(
x - v.x
y - v.y
z - v.z
)
}
normalize() {
t := f32_sqrt(x * x + y * y + z * z)
vec3(
x / t
y / t
z / t
)
}
cross(v : 'vec3) {
vec3(
y * v.z - z * v.y
z * v.x - x * v.z
x * v.y - y * v.x
)
}
dot(v : 'vec3) {
x * v.x + y * v.y + z * v.z
}
asVec4() {
vec4(x, y, z, 1.0f)
}
) { this }
vec3_min(a : 'vec3, b : 'vec3) {
vec3(
f32_min(a.x, b.x)
f32_min(a.y, b.y)
f32_min(a.z, b.z)
)
}
vec3_max(a : 'vec3, b : 'vec3) {
vec3(
f32_max(a.x, b.x)
f32_max(a.y, b.y)
f32_max(a.z, b.z)
)
}
vec3_getRawSize() {
--c--
int x = sizeof(float) * 3;
#return(i32, x);
--c--
}
vec3_rawCopy(v : 'vec3, p := 'ptr) {
--c--
float* f = (float*)p;
*f = v->x;
f++;
*f = v->y;
f++;
*f = v->z;
f++;
#return(ptr, (void*)f);
--c--
}