-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.js
38 lines (28 loc) · 1.18 KB
/
render.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
worldOriginX = canvas.width / 2;
worldOriginY = canvas.height / 2;
function renderScene(scene) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (let obj = 0; obj < scene.objects.length; obj++) {
renderObject(scene.objects[obj], scene);
}
}
function renderObject(object, scene) {
newobject = JSON.parse(JSON.stringify(object));
//Apply zoom
zoom = scene.navTransforms.zoom;
scaleObjectFromWorldOrigin(newobject.points, zoom, zoom, zoom);
//Apply orbit rotation
rotatePoints(newobject.points, 0, 0, scene.navTransforms.orbitZ, 0, 1);
rotatePoints(newobject.points, 0, 0, scene.navTransforms.orbitY, 1, 2);
//Center newobject on screen
translatePoints(newobject.points, worldOriginX, worldOriginY, 0);
translatePoint(newobject.origin, worldOriginX, worldOriginY, 0);
//Apply pan
translatePoints(newobject.points, scene.navTransforms.panX, scene.navTransforms.panY, 0);
translatePoint(newobject.origin, scene.navTransforms.panX, scene.navTransforms.panY, 0);
Wireframe = newobject.display.wireframe;
if (scene.display.wireframe) {
Wireframe = 1;
}
drawObject(newobject, 0, 1, "red", Wireframe);
}