-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
73 lines (59 loc) · 1.58 KB
/
index.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
let board;
let controlPanel;
const controlsContainer = document.getElementById("controls-container");
const addButton = document.getElementById("add-button");
const WEBGLButton = document.getElementById("WEBGL-toggle-button");
function setup() {
const renderer = createCanvas(windowWidth, windowHeight, WEBGL);
renderer.elt.addEventListener("contextmenu", (e) => e.preventDefault());
renderer.drawingContext.disable(renderer.drawingContext.DEPTH_TEST);
board = new Board();
controlPanel = new ControlPanel(controlsContainer, addButton, board);
if (board.orthoWEBGL) {
ortho(-width / 2, width / 2, -height / 2, height / 2, 10000, -10000);
}
WEBGLButton.addEventListener("click", () => {
board.WEBGL = !board.WEBGL;
});
}
function draw() {
background(15);
if (!board.WEBGL) {
translate(-windowWidth / 2, -windowHeight / 2);
board.drawBackground();
board.drawShapes();
board.xLimit = controlsContainer.offsetWidth;
} else {
translate(
board.translateXWEBGL,
board.translateYWEBGL,
board.translateZWEBGL
);
rotateX(board.rotateXWEBGL);
rotateY(board.rotateYWEBGL);
board.drawAxisWEBGL();
board.drawPH();
board.drawPV();
board.drawShapes();
}
}
function mouseDragged(e) {
if (!board.WEBGL) {
board.moveCameraPos();
} else {
board.moveCameraPosWEBGL(e);
}
}
// function mouseClicked(e) {
// controlPanel.test();
// }
function mouseWheel(e) {
if (!board.WEBGL) {
board.zoom(e);
} else {
board.zoomWEBGL(e);
}
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}