-
Notifications
You must be signed in to change notification settings - Fork 0
/
index3DMode.html
287 lines (211 loc) · 9.86 KB
/
index3DMode.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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<html>
<head>
<title>TSuKBG</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<script src="js/three.min.js"></script>
<script>
// --allow-file-access-from-files should be added when starting chrome
// so local files can be loaded. This is because of security restrictions
var renderer, camera, controls, scene, pointLight, planet, sky, stats;
var mouseDown = false, mouseX = 0, mouseY = 0;
var minZoom = 20, maxZoom = 50;
init();
mainLoop();
function init()
{
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//renderer
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//camera
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.setZ(40);
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//scene
scene = new THREE.Scene();
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// the planet
var planetGeometry = new THREE.SphereGeometry(10, 100, 100);
var planetMaterial = new THREE.MeshPhongMaterial;
planetMaterial.map = THREE.ImageUtils.loadTexture('textures/NASA_world_reduced1.jpg');
planetMaterial.specularMap = THREE.ImageUtils.loadTexture('textures/water_4k.png');
planetMaterial.specular = new THREE.Color('grey');
planet = new THREE.Mesh(planetGeometry, planetMaterial);
scene.add(planet);
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// the sky
var skyGeometry = new THREE.SphereGeometry(900, 64, 64);
var skyMaterial = new THREE.MeshPhongMaterial;
var texture = THREE.ImageUtils.loadTexture('textures/galaxy_starfield1.jpg');
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(12, 12);
skyMaterial.map = texture;
skyMaterial.side = THREE.BackSide;
sky = new THREE.Mesh(skyGeometry, skyMaterial);
scene.add(sky);
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// ambient light
scene.add(new THREE.AmbientLight(0xffffff));
var light = new THREE.DirectionalLight(0xffffff, 0.2);
light.position.set(0, 50, 0);
scene.add(light);
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//listeners for mouse move mouse down and mouse up
document.body.addEventListener('mousemove', function (e){ onMouseMove(e);}, false);
document.body.addEventListener('mousedown', function (e) {onMouseDown(e);}, false);
document.body.addEventListener('mouseup', function (e) { onMouseUp(e); }, false);
document.body.addEventListener('mousewheel', function (e) { onMouseWheel(e); }, false);
document.body.addEventListener('DOMMouseScroll', function (e) { onMouseWheel(e); }, false);//Mozilla
}
function onMouseWheel(event)
{
var delta = 0;
if (event.wheelDelta) //Chrome
{
delta = -event.wheelDelta / 120;
}
else if (event.detail) //Mozilla
{
delta = event.detail / 3;
}
if (camera.position.z + delta > minZoom && camera.position.z + delta < maxZoom)
{
camera.translateZ(delta);
}
}
function onMouseMove(event)
{
if (!mouseDown)
{
return;
}
var deltaX = event.clientX - mouseX;
var deltaY = event.clientY - mouseY;
mouseX = event.clientX;
mouseY = event.clientY;
rotatePlanet(deltaX, deltaY);
}
function onMouseDown(event)
{
mouseDown = true;
mouseX = event.clientX;
mouseY = event.clientY;
}
function onMouseUp(event)
{
mouseDown = false;
}
function rotatePlanet(deltaX, deltaY)
{
planet.rotation.y += deltaX / 300;
planet.rotation.x += deltaY / 300;
}
function mainLoop()
{
requestAnimationFrame(mainLoop);
update();
render();
}
function update()
{
//rotates the planet constantly
planet.rotation.y += 0.0003;
}
function render()
{
renderer.render(scene, camera);
}
//changes the visiblity of certain element on the screen( div for instance)
function setVisibility(id, visibility)
{
document.getElementById(id).style.visibility = visibility;
}
</script>
<!--search form-->
<div id="searchDiv" style="position: absolute; top: 0; left: 0; margin-top: 50px; margin-left: 50px; font-size: 15pt; font-family: 'Times New Roman';">
<form id="searchForm">
<input id="search" value="" style="font-size: 15pt; font-family: 'Times New Roman'" />
<input type="button" style="font-size: 15pt; font-family: 'Times New Roman';" value="Search" />
</form>
</div>
<!--Login button-->
<div style="position:absolute;top:0;right:0;margin-top:50px;margin-right:100px;">
<button name ="login" id ="login" style="font-size:15pt;font-family:'Times New Roman'" value ="Login" onclick="setVisibility('openLogin', 'visible');"> Login </button>
</div>
<!--Login dialog-->
<div id="openLogin" class="loginDialog">
<div>
<a href="#openLogin" onclick="setVisibility('openLogin', 'hidden');" class="closeButtonLogin">X</a>
<div style="position: relative; left: 10%;">
<form id="Form1">
<br /><br /><br />
<label style="font-size: 25pt; font-family: 'Times New Roman'">Login </label> <br /><br />
Username <br />
<input name="username" id="username" value="" style="font-size: 15pt; font-family: 'Times New Roman'" /><br /> <br />
Password<br />
<input name="password" id="password" value="" style="font-size: 15pt; font-family: 'Times New Roman'" /><br /><br />
<input type="button" style="font-size: 15pt; font-family: 'Times New Roman'" value="Login" />
</form>
</div>
</div>
</div>
<!--Register button-->
<div style="position:absolute;top:0;right:0;margin-top:50px;margin-right:200px;">
<button name ="register" id ="Button2" style="font-size:15pt;font-family:'Times New Roman'" onclick="setVisibility('openRegister', 'visible');"> Register </button>
</div>
<!--Register dialog-->
<div id="openRegister" class="registerDialog">
<div>
<a href="#openRegister" onclick="setVisibility('openRegister', 'hidden');" title="Close" class="closeButtonRegister">X</a>
<div style="position: relative; left: 13%;">
<form id="Form2">
<br /><br />
<label style="font-size: 25pt; font-family: 'Times New Roman'">Register</label><br /><br />
Email <br />
<input name="email" id="Text3" value="" style="font-size: 15pt; font-family: 'Times New Roman'" /><br /><br />
Username<br />
<input name="username" id="Text1" value="" style="font-size: 15pt; font-family: 'Times New Roman'" /> <br /><br />
Password
<br />
<input name="password" id="Text2" value="" style="font-size: 15pt; font-family: 'Times New Roman'" /><br /><br />
Repeat password<br />
<input name="repeatPassword" id="Text4" value="" style="font-size: 15pt; font-family: 'Times New Roman'" /><br /><br />
<input type="button" style="font-size: 15pt; font-family: 'Times New Roman'" value="Register" />
</form>
</div>
</div>
</div>
<!--2d mode button-->
<div style="position:absolute;bottom:0;left:0;margin-bottom:10px;margin-left:50px;">
<form action="index.html">
<input type="submit" id ="Submit2" style="font-size:15pt;font-family:'Times New Roman'" value ="Go to 2D mode">
</form>
</div>
<!-- find route button -->
<div style="position:absolute;top:0;left:0;margin-top:50px;margin-left:400px;">
<button name ="openRoute" id ="Button1" style="font-size:15pt;font-family:'Times New Roman'" onclick="setVisibility('openRoute', 'visible');"> Find route </button>
</div>
<!-- find route dialog -->
<div id="openRoute" class="routeDialog">
<div>
<a href="#openRoute" onclick="setVisibility('openRoute', 'hidden');" title="Close" class="closeButtonRoute">X</a>
<div style="position: relative; left: 8%;">
<form id="Form3">
<br /><br />
<label style="font-size: 25pt; font-family: 'Times New Roman'">Find route between places</label><br /><br />
Starting place <br />
<input name="email" id="Text5" value="" style="font-size: 15pt; font-family: 'Times New Roman'" /><br /><br />
Target place<br />
<input name="username" id="Text6" value="" style="font-size: 15pt; font-family: 'Times New Roman'" /><br /> <br />
<input type="button" style="font-size: 15pt; font-family: 'Times New Roman'" value="Find route" />
</form>
</div>
</div>
</div>
</body>
</html>