-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path3d.js
137 lines (106 loc) · 3.09 KB
/
3d.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
3d.js - Drawing avs in three dimensions. Handles input also.
*/
var scene;
var renderer;
var camera;
var keys;
var mouse;
var hoverobject;
var mouseovercanvas;
var lasttime=0;
var frameratebuffer=60;
var start=parseInt(new Date().getTime());
var now;
function initGraffa() {
canvas = document.getElementById('graffa');
canvas.onmouseover = function(event) {
mouseovercanvas = true;
};
canvas.onmousemove = function(event) {
mouseovercanvas = true;
};
canvas.onmouseout = function(event) {
mouseovercanvas = false;
};
//disable context menu for canvas
canvas.oncontextmenu = function(event) {
return false;
}
renderer = new GLGE.Renderer(canvas);
scene = new GLGE.Scene();
// temp testing
var static_scene = new GLGE.Collada();
static_scene.setDocument(url_to_static);
static_scene.docURL = "/";
static_scene.setRot(0, 0, 0);
scene.addCollada(static_scene);
keys = new GLGE.KeyInput();
mouse = new GLGE.MouseInput(canvas);
scene.setAmbientColor('#fff');
renderer.setScene(scene);
camera = new GLGE.Camera();
camera.setType(GLGE.C_PERSPECTIVE);
scene.setCamera(camera);
startRender()
}
function startRender() {
rendertimerid = setInterval(render, 50);
}
function render() {
renderer.render();
checkkeys();
checkmouse();
now=parseInt(new Date().getTime());
frameratebuffer = Math.round(((frameratebuffer * 9) + 1000/ (now - lasttime)) / 10);
//document.getElementById("fps").innerHTML = "FPS: " + frameratebuffer+ " #obj: " + scene.getObjects().length;
//document.getElementById("info").innerHTML="Camera:" + camera.getLocX() +", " + camera.getLocY() + ", " + camera.getLocZ() + " : " + camera.getRotX() + ", " + camera.getRotY() + ", " + camera.getRotZ();
lasttime = now;
}
function checkkeys() {
if (!mouseovercanvas) {
return;
}
if (keys.isKeyPressed(GLGE.KI_PAGE_UP)) {
addmove('Move,up');
}
if (keys.isKeyPressed(GLGE.KI_PAGE_DOWN)) {
addmove('Move,down');
}
if (keys.isKeyPressed(GLGE.KI_W) || keys.isKeyPressed(GLGE.KI_UP_ARROW)) {
addmove('Move,forward');
}
if (keys.isKeyPressed(GLGE.KI_S) || keys.isKeyPressed(GLGE.KI_DOWN_ARROW)) {
addmove('Move,back');
}
if (keys.isKeyPressed(GLGE.KI_A)) {
addmove('Move,left');
}
if (keys.isKeyPressed(GLGE.KI_D)) {
addmove('Move,right');
}
if (keys.isKeyPressed(GLGE.KI_LEFT_ARROW)) {
addmove('Rotate,left');
}
if (keys.isKeyPressed(GLGE.KI_RIGHT_ARROW)) {
addmove('Rotate,right');
}
checkmove();
}
function checkmouse() {
if (mouseovercanvas) {
var mouseposition = mouse.getMousePosition();
mouseposition.x -= document.getElementById("container").offsetLeft;
mouseposition.y -= document.getElementById("container").offsetTop;
if (mouse.isButtonDown(GLGE.MI_RIGHT) & mouseposition.x && mouseposition.y) {
var dx = old_mousex - mouseposition.x;
if (dx < 0) {
addmove('Rotate,right');
} else if (dx > 0) {
addmove('Rotate,left');
}
old_mousex = mouseposition.x;
old_mousey = mouseposition.y;
}
}
}