forked from therauli/WebNaali
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscenetest.js
92 lines (72 loc) · 2.16 KB
/
scenetest.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
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
ws = {};
ws.send = function(string) {
};
function checkkeys() {
var camerapos = camera.getPosition();
var camerarot = camera.getRotation();
var mat = camera.getRotMatrix();
var trans = GLGE.mulMat4Vec4(mat, [0, 0, -1, 1]);
var magnitude = Math.sqrt(Math.pow(trans[0], 2) + Math.pow(trans[2], 2));
trans[0] = trans[0] / magnitude;
trans[2] = trans[2] / magnitude;
var yinc = 0;
var xinc = 0;
var zinc = 0;
var rot = 0;
if (keys.isKeyPressed(GLGE.KI_PAGE_UP)) {
yinc = 1;
}
if (keys.isKeyPressed(GLGE.KI_PAGE_DOWN)) {
yinc = -1;
}
if (keys.isKeyPressed(GLGE.KI_W) || keys.isKeyPressed(GLGE.KI_UP_ARROW)) {
xinc = xinc + parseFloat(trans[0]);
zinc = zinc + parseFloat(trans[2]);
}
if (keys.isKeyPressed(GLGE.KI_S) || keys.isKeyPressed(GLGE.KI_DOWN_ARROW)) {
xinc = xinc - parseFloat(trans[0]);
zinc = zinc - parseFloat(trans[2]);
}
if (keys.isKeyPressed(GLGE.KI_A)) {
xinc = xinc + parseFloat(trans[2]);
zinc = zinc - parseFloat(trans[0]);
}
if (keys.isKeyPressed(GLGE.KI_D)) {
xinc = xinc - parseFloat(trans[2]);
zinc = zinc + parseFloat(trans[0]);
}
if (keys.isKeyPressed(GLGE.KI_LEFT_ARROW)) {
rot = 0.03;
}
if (keys.isKeyPressed(GLGE.KI_RIGHT_ARROW)) {
rot = -0.03;
}
if (xinc != 0 || yinc != 0 || zinc != 0) {
var movediv = 7;
camera.setLocX(camerapos.x + (xinc / movediv));
camera.setLocY(camerapos.y + (yinc / movediv));
camera.setLocZ(camerapos.z + (zinc / movediv));
}
if (rot != 0) {
camera.setRotY(camera.getRotY() + rot);
}
}
function checkmouse() {
var mouseposition = mouse.getMousePosition();
mouseposition.x -= document.getElementById("container").offsetLeft;
mouseposition.y -= document.getElementById("container").offsetTop;
var rot = 0;
if (mouse.isButtonDown(GLGE.MI_RIGHT) && mouseposition.x && mouseposition.y) {
var dx = old_mousex - mouseposition.x;
if (dx < 0) {
rot = -0.03;
} else if (dx > 0) {
rot = 0.03;
}
if (rot != 0) {
camera.setRotY(camera.getRotY() + rot);
}
old_mousex = mouseposition.x;
old_mousey = mouseposition.y;
}
}