-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.js
More file actions
52 lines (42 loc) · 941 Bytes
/
node.js
File metadata and controls
52 lines (42 loc) · 941 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class Node{
constructor(data){
this.pos_vec = new Vec4(0, 0, 0, 1);
this.scale_vec = new Vec4(1, 1, 1, 1);
this.rot_vec = new Vec4(0, 0, 0, 0);
this.data = data;
this.children = [];
}
add_child(){
let child = new Node();
this.children.push(child);
return child;
}
roll_by(amount){
this.rot_vec.x += amount;
}
pitch_by(amount){
this.rot_vec.y += amount;
}
yaw_by(amount){
this.rot_vec.z += amount;
}
strafe_by(amount){
this.pos_vec.x += amount;
}
move_forward_by(amount){
this.pos_vec.z += amount;
}
move_up_by(amount){
this.pos_vec.y += amount;
}
generate_matrix(){
return (
Mat4.identity()
.mul(Mat4.translation(this.pos_vec.x, this.pos_vec.y, this.pos_vec.z))
.mul(Mat4.rotation_xz(this.rot_vec.z))
.mul(Mat4.rotation_yz(this.rot_vec.y))
.mul(Mat4.rotation_xy(this.rot_vec.x))
.mul(Mat4.scale(this.scale_vec.x, this.scale_vec.y, this.scale_vec.z))
);
}
}