Skip to content

Commit f2bf81b

Browse files
author
Eiren Rain
committed
basic text on screen
1 parent 72cb28b commit f2bf81b

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

apps/front/dist/index.html

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
<script type="module" crossorigin src="/assets/index-D4dv4Lzd.js"></script>
1515
</head>
1616
<body>
17-
<div id="app"></div>
18-
17+
<div style="position: fixed; top: 0; left: 0; color: white">
18+
<div style="background-color: gray; width: 200px; height: 500px;">
19+
HELLO
20+
</div>
21+
</div>
1922
</body>
2023
</html>

apps/front/index.html

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
</style>
1414
</head>
1515
<body>
16-
<div id="app"></div>
16+
<div style="position: fixed; top: 0; left: 0; color: white">
17+
<div style="background-color: rgba(100, 100, 100, 0.2); padding: 5px;">
18+
<div id="angle-text"></div>
19+
</div>
20+
</div>
1721

1822
<script type="module" src="/src/index.ts"></script>
1923
</body>

apps/front/src/index.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,33 @@ const {
1010

1111
const {
1212
onMessage,
13+
1314
} = createWebsocketClient()
1415

16+
let currentAngle = { x: 0, y: 0, z: 0 }
17+
1518
onMessage('server/gyro/angles', ({ angles }) => {
16-
// console.log('angles', angles)
19+
currentAngle = angles;
1720
setRotation(angles)
21+
22+
// You can also do it here
23+
const angleText = document.getElementById("angle-text")!; // <-- whath out for the ! at the end
24+
angleText.innerHTML = `Current angle x: ${angles.x} y: ${angles.y} z: ${angles.z}`;
1825
})
1926

2027
const animate = () => {
2128
renderer.render(scene, camera);
2229
requestAnimationFrame(animate);
2330
};
2431

32+
33+
setInterval(() => { // This is to prevent to re render every threejs -> do not update the dom in animate!
34+
const angleText = document.getElementById("angle-text")!;
35+
36+
angleText.innerHTML = `Current angle x: ${currentAngle.x} y: ${currentAngle.y} z: ${currentAngle.z}`;
37+
}, 100) // this will run every 100ms
38+
39+
2540
animate();
2641

2742

0 commit comments

Comments
 (0)