Update index.html
Browse files- index.html +49 -16
index.html
CHANGED
@@ -1,19 +1,52 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
+
<head>
|
4 |
+
<meta charset="utf-8">
|
5 |
+
<title>3D Flight Demo</title>
|
6 |
+
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
|
7 |
+
</head>
|
8 |
+
<body>
|
9 |
+
<a-scene>
|
10 |
+
<a-assets>
|
11 |
+
<img id="skyTexture" src="https://cdn.aframe.io/a-painter/images/sky.jpg">
|
12 |
+
<img id="terrainTexture" src="https://cdn.aframe.io/a-painter/images/terrain.jpg">
|
13 |
+
<img id="aircraftTexture" src="https://cdn.aframe.io/a-painter/images/brushes/fur.jpg">
|
14 |
+
</a-assets>
|
15 |
+
<a-sky src="#skyTexture"></a-sky>
|
16 |
+
<a-plane src="#terrainTexture" rotation="-90 0 0" height="100" width="100"></a-plane>
|
17 |
+
<a-entity id="aircraft" position="0 2 -5" rotation="0 0 0" geometry="primitive: box; height: 0.5; width: 1.5; depth: 2" material="src: #aircraftTexture"></a-entity>
|
18 |
+
<a-camera>
|
19 |
+
<a-cursor></a-cursor>
|
20 |
+
</a-camera>
|
21 |
+
</a-scene>
|
22 |
+
<script>
|
23 |
+
var aircraft = document.querySelector('#aircraft');
|
24 |
+
var velocity = new THREE.Vector3(0, 0, 0);
|
25 |
+
var gravity = new THREE.Vector3(0, -0.1, 0);
|
26 |
+
var thrust = new THREE.Vector3(0, 0, -0.1);
|
27 |
+
var keys = {};
|
28 |
+
|
29 |
+
function update() {
|
30 |
+
if (keys['ArrowUp']) {
|
31 |
+
velocity.add(thrust);
|
32 |
+
}
|
33 |
+
velocity.add(gravity);
|
34 |
+
aircraft.object3D.position.add(velocity);
|
35 |
+
aircraft.object3D.rotation.x = velocity.z * 0.1;
|
36 |
+
aircraft.object3D.rotation.y = -velocity.x * 0.1;
|
37 |
+
aircraft.object3D.rotation.z = -velocity.y * 0.1;
|
38 |
+
requestAnimationFrame(update);
|
39 |
+
}
|
40 |
+
|
41 |
+
window.addEventListener('keydown', function(event) {
|
42 |
+
keys[event.code] = true;
|
43 |
+
});
|
44 |
+
|
45 |
+
window.addEventListener('keyup', function(event) {
|
46 |
+
keys[event.code] = false;
|
47 |
+
});
|
48 |
+
|
49 |
+
update();
|
50 |
+
</script>
|
51 |
+
</body>
|
52 |
</html>
|