-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrols.js
104 lines (86 loc) · 4.08 KB
/
controls.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
// Controls for ray tracer UI
function initControls(loopFunction, lightPosRef, sphereCenterRef, sphereRadiusRef, sphereColorRef, bgColorRef) {
// Light position controls
const lightX = document.getElementById('lightX');
const lightY = document.getElementById('lightY');
const lightZ = document.getElementById('lightZ');
lightX.addEventListener('input', () => {
lightPosRef.x = parseFloat(lightX.value);
document.getElementById('lightXValue').textContent = lightX.value;
loopFunction(); // Auto-render on change
});
lightY.addEventListener('input', () => {
lightPosRef.y = parseFloat(lightY.value);
document.getElementById('lightYValue').textContent = lightY.value;
loopFunction(); // Auto-render on change
});
lightZ.addEventListener('input', () => {
lightPosRef.z = parseFloat(lightZ.value);
document.getElementById('lightZValue').textContent = lightZ.value;
loopFunction(); // Auto-render on change
});
// Sphere position controls
const sphereX = document.getElementById('sphereX');
const sphereY = document.getElementById('sphereY');
const sphereZ = document.getElementById('sphereZ');
sphereX.addEventListener('input', () => {
sphereCenterRef.x = parseFloat(sphereX.value);
document.getElementById('sphereXValue').textContent = sphereX.value;
loopFunction(); // Auto-render on change
});
sphereY.addEventListener('input', () => {
sphereCenterRef.y = parseFloat(sphereY.value);
document.getElementById('sphereYValue').textContent = sphereY.value;
loopFunction(); // Auto-render on change
});
sphereZ.addEventListener('input', () => {
sphereCenterRef.z = parseFloat(sphereZ.value);
document.getElementById('sphereZValue').textContent = sphereZ.value;
loopFunction(); // Auto-render on change
});
// Sphere radius control
const sphereRadius = document.getElementById('sphereRadius');
sphereRadius.addEventListener('input', () => {
sphereRadiusRef.value = parseFloat(sphereRadius.value);
document.getElementById('sphereRadiusValue').textContent = sphereRadius.value;
loopFunction(); // Auto-render on change
});
// Sphere color controls
const sphereRed = document.getElementById('sphereRed');
const sphereGreen = document.getElementById('sphereGreen');
const sphereBlue = document.getElementById('sphereBlue');
sphereRed.addEventListener('input', () => {
sphereColorRef.x = parseInt(sphereRed.value);
document.getElementById('sphereRedValue').textContent = sphereRed.value;
loopFunction(); // Auto-render on change
});
sphereGreen.addEventListener('input', () => {
sphereColorRef.y = parseInt(sphereGreen.value);
document.getElementById('sphereGreenValue').textContent = sphereGreen.value;
loopFunction(); // Auto-render on change
});
sphereBlue.addEventListener('input', () => {
sphereColorRef.z = parseInt(sphereBlue.value);
document.getElementById('sphereBlueValue').textContent = sphereBlue.value;
loopFunction(); // Auto-render on change
});
// Background color controls
const bgRed = document.getElementById('bgRed');
const bgGreen = document.getElementById('bgGreen');
const bgBlue = document.getElementById('bgBlue');
bgRed.addEventListener('input', () => {
bgColorRef.r = parseInt(bgRed.value);
document.getElementById('bgRedValue').textContent = bgRed.value;
loopFunction(); // Auto-render on change
});
bgGreen.addEventListener('input', () => {
bgColorRef.g = parseInt(bgGreen.value);
document.getElementById('bgGreenValue').textContent = bgGreen.value;
loopFunction(); // Auto-render on change
});
bgBlue.addEventListener('input', () => {
bgColorRef.b = parseInt(bgBlue.value);
document.getElementById('bgBlueValue').textContent = bgBlue.value;
loopFunction(); // Auto-render on change
});
}