-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcamera.js
executable file
·55 lines (39 loc) · 1.25 KB
/
camera.js
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
function camera() {
this.ortho = new Matrix4().setOrtho(-1,1, -1, 1, 1, 7);
this.perspective = new Matrix4().setPerspective(60, 1, 0.1, 7);//.translate(0, 0, -2.0);
this.fov = 60;
this.applied_trans = new Matrix4().translate(0, 0, -2.0);;
this.trans = new Matrix4();
//this.rot = new Matrix4();
this.apply_trans = function(){
this.applied_trans = this.trans.multiply(this.applied_trans);
this.trans = new Matrix4();
}
this.set_trans = function(trans) {
this.trans = new Matrix4().set(trans);
}
this.add_fov = function(delta_fov) {
this.set_fov(this.fov + delta_fov);
}
this.set_fov = function(fov) {
if(!(fov > 1 && fov < 179)) return;
this.fov = fov;
this.perspective = new Matrix4().setPerspective(fov, 1, 0.1, 7);
}
this.getProjmat = function() {
var proj = new Matrix4();
var trans = new Matrix4();
var rot = new Matrix4();
trans.set(this.trans);
trans = trans.multiply(this.applied_trans);
//rot.set(this.rot);
if(showOrtho) {
proj.set(this.ortho);
} else {
proj.set(this.perspective);
}
proj = proj.multiply(trans);
// console.log(proj.elements);
return proj;
}
}