-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
119 lines (104 loc) · 3.02 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Cornell Box</title>
<style>
body {
margin: 0;
}
canvas {
width: 100%;
height: 100%
}
</style>
</head>
<body>
<script src="three.js"></script>
<script src="box.js"></script>
<script src="cube.js"></script>
<script src="sphere.js"></script>
<script src="js/controls/OrbitControls.js"></script>
<script>
// Creating the scene
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(
75, window.innerWidth / window.innerHeight, 0.1, 1000);
var controls = new THREE.OrbitControls(camera);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Adding geometry
scene.add(boxMesh);
scene.add(cubeMesh);
scene.add(sphereMesh);
// Light sources
var pointLight = new THREE.PointLight(0xffffff, 1.3); // Inside the box
pointLight.position.set(0, 5, 5);
scene.add(pointLight);
camera.position.z = 15;
/* Generating random direction of movement
* If random number is between 0.00-0.49, set to false.
* If random number is between 0.50-1.00, set to true.
*/
var sphereRight = (Math.random() > 0.5);
var sphereUp = (Math.random() > 0.5);
var sphereForward = (Math.random() > 0.5);
var cubeRight = (Math.random() > 0.5);
var cubeUp = (Math.random() > 0.5);
var cubeForward = (Math.random() > 0.5);
// Rendering
function animate() {
requestAnimationFrame(animate);
cubeMesh.rotation.x += 0.01;
cubeMesh.rotation.y += 0.01;
cubeMesh.rotation.z += 0.01;
if (sphereRight) {
sphereMesh.position.x += 0.05
if (sphereMesh.position.x > 7) sphereRight = false;
} else {
sphereMesh.position.x -= 0.05
if (sphereMesh.position.x < -7) sphereRight = true;
}
if (sphereUp) {
sphereMesh.position.y += 0.05
if (sphereMesh.position.y > 7) sphereUp = false;
} else {
sphereMesh.position.y -= 0.05
if (sphereMesh.position.y < -7) sphereUp = true;
}
if (sphereForward) {
sphereMesh.position.z += 0.05
if (sphereMesh.position.z > 7) sphereForward = false;
} else {
sphereMesh.position.z -= 0.05
if (sphereMesh.position.z < -7) sphereForward = true;
}
if (cubeRight) {
cubeMesh.position.x += 0.05
if (cubeMesh.position.x > 7) cubeRight = false;
} else {
cubeMesh.position.x -= 0.05
if (cubeMesh.position.x < -7) cubeRight = true;
}
if (cubeUp) {
cubeMesh.position.y += 0.05
if (cubeMesh.position.y > 7) cubeUp = false;
} else {
cubeMesh.position.y -= 0.05
if (cubeMesh.position.y < -7) cubeUp = true;
}
if (cubeForward) {
cubeMesh.position.z += 0.05
if (cubeMesh.position.z > 7) cubeForward = false;
} else {
cubeMesh.position.z -= 0.05
if (cubeMesh.position.z < -7) cubeForward = true;
}
controls.update();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>