-
Notifications
You must be signed in to change notification settings - Fork 0
/
citrus_glm.rs
49 lines (40 loc) · 851 Bytes
/
citrus_glm.rs
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
struct Vec3 {
x: f64;
y: f64;
z: f64;
}
struct Vec2 {
x: f64;
y: f64;
}
struct Vec<T> {
elems: T*;
capacity: u64;
len: u64;
}
fn Vec::cross(a: Vec3*, b: Vec3*) =
Vec3{x: a.y * b.z - a.z * b.y,
y: a.z * b.x - a.x * b.z,
z: a.x * b.y - a.y * b.z};
struct Vertex {
pos: Vec3;
norm: Vec2;
}
struct QuadFace {
vertices: Vertex[4];
}
struct WorldMesh {
faces: Vec<QuadFace>;
}
fn WorldMesh::vertices(self: WorldMesh*) -> Vec<Vertex> =
Vec<Vertex>.from_ptr(self.faces[0], self.faces.len() * 4);
fn compute_normals(faces: Vec<QuadFace>) = {
for(faces, fn(f: QuadFace*) = {
let e1 = f.a.pos - f.b.pos;
let e2 = f.c.pos - f.b.pos;
let norm = e1.cross e2;
for(f.vertices, fn(v: Vertex*) = {
v.norm = norm;
});
});
}