-
Notifications
You must be signed in to change notification settings - Fork 0
/
globalFuncs.js
131 lines (118 loc) · 3.01 KB
/
globalFuncs.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
function transform(){
let tx = 0.0, ty = 0.0, tz = 0.0, rx = 0.0, ry = 0.0, rz = 0.0;
if (keyStates['KeyW']){
ty -= 0.05;
}
if (keyStates['KeyA']){
tx -= 0.05;
}
if (keyStates['KeyS']){
ty += 0.05;
}
if (keyStates['KeyD']){
tx += 0.05;
}
if (keyStates['Space']){
tz += 0.05;
}
if (keyStates['KeyC']){
tz -= 0.05;
}
if (keyStates['KeyE']){
ry += 1.0;
}
if (keyStates['KeyF']){
ry -= 1.0;
}
if (keyStates['KeyR']){
rx += 1.0;
}
if (keyStates['KeyG']){
rx -= 1.0;
}
if (keyStates['KeyT']){
rz += 1.0;
}
if (keyStates['KeyH']){
rz -= 1.0;
}
if(renderMode === 1){
renderPassWireFrame(wcPtr, tx, ty, tz, rx, ry, rz);
ctx.putImageData(imageData, 0, 0);
}
else if(renderMode === 0){
renderPass(wcPtr, tx, ty, tz, rx, ry, rz);
ctx.putImageData(imageData, 0, 0);
}
}
function changeMenus(){
event.target.blur()
const menuIds = ["controls", "transforms", "rasterization", "mesh"];
menuIds.forEach(id => {
document.getElementById(id).classList.add("hidden");
});
document.getElementById(this.dataset.target).classList.remove("hidden");
}
function submitNewExplodeScalar(scalar){
event.target.blur()
updateExplodeScalar(wcPtr, scalar);
render();
document.getElementById("explodeScalarValue").textContent = scalar.toString();
}
function submitNewColor(r, g, b){
event.target.blur()
r = clampUnsignedChar(r);
g = clampUnsignedChar(g);
b = clampUnsignedChar(b);
updateColorBuffer(wcPtr, r, g, b);
render();
}
function randomizeColors(){
console.log("here");
event.target.blur();
randomizeColorBuffer(wcPtr);
render();
}
function submitNewLightVector(x, y, z){
event.target.blur()
updateLightVector(wcPtr, x, y, z)
render();
}
function submitNewMatrix(){
event.target.blur()
const matrixInputs = document.querySelectorAll('#matrixInput input[type="number"]');
const matrix = Array.from(matrixInputs).map(input => parseFloat(input.value));
addMatrixSlot(wcPtr)
for(i = 0; i < 16; i++){
addMatrixValue(wcPtr, matrix[i]);
}
render();
}
function clampUnsignedChar(value){
if(value > 255) return 255;
if(value < 0) return 0;
return value;
}
function changeRenderMode(){
event.target.blur()
if(renderMode == 0){
renderMode = 1;
document.getElementById("renderWireFrame").innerText = "Enable Polygon Filling"
render()
return;
}
if(renderMode == 1){
renderMode = 0;
document.getElementById("renderWireFrame").innerText = "Disable Polygon Filling"
}
render();
}
function render(){
if(renderMode === 1){
renderPassWireFrame(wcPtr, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
ctx.putImageData(imageData, 0, 0);
return;
}
renderPass(wcPtr, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
ctx.putImageData(imageData, 0, 0);
}