-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
209 lines (177 loc) · 6.29 KB
/
index.html
File metadata and controls
209 lines (177 loc) · 6.29 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/107/three.min.js"></script>
<!-- Seus outros elementos de cabeçalho -->
</head>
<body>
<header>
<div class="header">
<h1>10 Dimensões
</h1>
</div>
</header>
<div class="h1">
<h3>Giroscópio</h3>
<div class="cube-content">
<div id="3Dcube"></div>
</div>
</div>
<div class="gyro">
<h3>Valores do giroscópio.</h3>
<p><span class="leitura">X: <span id="gyroX">0</span></span></p>
<p><span class="leitura">Y: <span id="gyroY">0</span></span></p>
<p><span class="leitura">Z: <span id="gyroZ">0</span></span></p>
</div>
<input type="button" onclick="onClick()" value="click to activate">
<div>
<h3>Coreografia</h3>
<label for="coreografia">Coreografia:
<input list="coreografia" id="coreografia">
</label>
<datalist id="coreografia">
<option value="Coreografia 1"></option>
<option value="Coreografia 2"></option>
<option value="Coreografia 3"></option>
<option value="Coreografia 4"></option>
<option value="Coreografia 5"></option>
</datalist>
</div>
<div class= "leds" id="leds">
<h3>LEDs</h3>
<input type="checkbox" name="" id="led1">
<input type="checkbox" name="" id="led2">
<input type="checkbox" name="" id="led3">
<input type="checkbox" name="" id="led4">
<input type="checkbox" name="" id="led5">
<input type="checkbox" name="" id="led6">
<input type="checkbox" name="" id="led7">
<input type="checkbox" name="" id="led8">
</div>
<div class="cards">
<div id="controle">
<h3>
Controle
</h3>
<input id= "button-cima" type="button" value="←">
<input id= "button-esquerda" type="button" value="↑">
<input id= "button-direita" type="button" value="→">
<input id= "button-baixo" type="button" value="↓">
</div>
</div>
<div class = "musica">
<h3>Música</h3>
<label for="musica">Música: </label>
<input type="number" id="musica-input" min="0" max="5">
</div>
<script>
let theta1 = 0;
let theta2 = 0;
let theta3 = 0;
let dthetaXdt = 0;
let dthetaYdt = 0;
let dthetaZdt = 0;
let dtheta1dt = 0;
let dtheta2dt = 0;
let dtheta3dt = 0;
let thetaX = 0;
let thetaY = 0;
let thetaZ = 0;
let det = false;
let t = 0,
dt = 1;
function onClick() {
if (typeof DeviceMotionEvent.requestPermission === 'function') {
DeviceMotionEvent.requestPermission()
.then(permissionState => {
if (permissionState === 'granted') {
window.addEventListener('devicemotion', cb);
}
})
.catch(console.error);
} else {
window.addEventListener('devicemotion', cb);
}
}
function cb(event) {
if (event.rotationRate) {
dthetaXdt = event.rotationRate.alpha * (Math.PI / 180);
dthetaYdt = event.rotationRate.beta * (Math.PI / 180);
dthetaZdt = event.rotationRate.gamma * (Math.PI / 180);
let ct = millis() / 1000;
dt = ct - t;
t = ct;
// Atualize os valores do giroscópio na tela
document.getElementById('gyroX').textContent = dthetaXdt.toFixed(3);
document.getElementById('gyroY').textContent = dthetaYdt.toFixed(3);
document.getElementById('gyroZ').textContent = dthetaZdt.toFixed(3);
det = true;
}
}
function onClick() {
if (typeof DeviceMotionEvent.requestPermission === 'function') {
DeviceMotionEvent.requestPermission()
.then(permissionState => {
if (permissionState === 'granted') {
window.addEventListener('devicemotion', cb);
}
})
.catch(console.error);
} else {
window.addEventListener('devicemotion', cb);
}
}
let scene, camera, renderer, cube;
function init3D() {
scene = new THREE.Scene();
scene.background = new THREE.Color(0xffffff);
camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
1000
);
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.getElementById('3Dcube').appendChild(renderer.domElement);
// Create a geometry
const geometry = new THREE.BoxGeometry(5, 1, 4);
// Materials of each face
var cubeMaterials = [
new THREE.MeshBasicMaterial({ color: 0x03045e }),
new THREE.MeshBasicMaterial({ color: 0x023e8a }),
new THREE.MeshBasicMaterial({ color: 0x0077b6 }),
new THREE.MeshBasicMaterial({ color: 0x03045e }),
new THREE.MeshBasicMaterial({ color: 0x023e8a }),
new THREE.MeshBasicMaterial({ color: 0x0077b6 }),
];
const material = new THREE.MeshFaceMaterial(cubeMaterials);
cube = new THREE.Mesh(geometry, material);
scene.add(cube);
camera.position.z = 5;
renderer.render(scene, camera);
}
// Resize the 3D object when the browser window changes size
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener('resize', onWindowResize, false);
// Create the 3D representation
init3D();
// Função para atualizar a rotação do cubo com base nos valores do giroscópio
function updateCubeRotation() {
if (det && dtheta1dt == dtheta1dt) {
cube.rotation.x = dthetaXdt;
cube.rotation.y = dthetaYdt;
cube.rotation.z = dthetaZdt;
renderer.render(scene, camera);
}
requestAnimationFrame(updateCubeRotation);
}
updateCubeRotation();
</script>
</body>
</html>