-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_old.html
308 lines (208 loc) · 9.54 KB
/
index_old.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<!DOCTYPE HTML>
<html manifest="" lang="en">
<head>
<meta charset="utf-8">
<title>SHOOTER HTML5 WEBGL</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-touch-fullscreen" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="apple-touch-icon" sizes="57x57" href="assets/img/ico/favicon114.png" />
<link rel="apple-touch-icon" sizes="114x114" href="assets/img/ico/favicon114.png" />
<link rel="apple-touch-icon" sizes="72x72" href="assets/img/ico/favicon144.png" />
<link rel="apple-touch-icon" sizes="144x144" href="assets/img/ico/favicon144.png" />
<link rel="apple-touch-icon-precomposed" href="assets/img/ico/favicon144.png" />
<link rel="shortcut icon" href="assets/img/ico/favicon.ico">
<!--[if gte IE 9]>
<meta name="application-name" content="SHOOTER HTML5 WEBGL" />
<meta name="msapplication-tooltip" content="SHOOTER HTML5 WEBGL" />
<meta name="msapplication-starturl" content="git.t2p0.com/roccojanse/shooter" />
<![endif]-->
<link rel="stylesheet" href="css/shooter.css" />
<script src="js/jquery/jquery-2.0.3.min.js"></script>
<script src="js/three/three.js"></script>
<script src="js/physijs/physi.js"></script>
<script src="js/three/libs/stats.min.js"></script>
<!-- <script src="js/three/THREEx.KeyboardState.js"></script> -->
<script src="js/three/controls/PointerLockControls.js"></script>
<script src="src/js/Skybox.js"></script>
<script src="src/js/Lensflare.js"></script>
<!-- <script src="../three.js/examples/js/loaders/ctm/lzma.js"></script>
<script src="../three.js/examples/js/loaders/ctm/ctm.js"></script>
<script src="../three.js/examples/js/loaders/ctm/CTMLoader.js"></script>
<script src="../three.js/examples/js/loaders/BinaryLoader.js"></script>
<script src="../three.js/examples/js/loaders/OBJLoader.js"></script>
<script src="../three.js/examples/js/loaders/VTKLoader.js"></script>
<script src="../three.js/examples/js/loaders/STLLoader.js"></script>
<script src="../three.js/examples/js/loaders/ColladaLoader.js"></script>
<script src="../three.js/examples/js/loaders/UTF8Loader.js"></script>
<script src="../three.js/examples/js/loaders/MTLLoader.js"></script> -->
</head>
<body>
<script>
// screens
// objects
// assets
// game -> world -> threejs
//
var havePointerLock = 'pointerLockElement' in document ||
'mozPointerLockElement' in document ||
'webkitPointerLockElement' in document;
if (havePointerLock) {
var element = document.body;
var pointerlockchange = function (e) {
if (document.pointerLockElement === element ||
document.mozPointerLockElement === element ||
document.webkitPointerLockElement === element) {
controls.enabled = true;
} else {
controls.enabled = false;
}
};
var pointerlockerror = function (e) {};
// Hook pointer lock state change events
document.addEventListener('pointerlockchange', pointerlockchange, false);
document.addEventListener('mozpointerlockchange', pointerlockchange, false);
document.addEventListener('webkitpointerlockchange', pointerlockchange, false);
document.addEventListener('pointerlockerror', pointerlockerror, false);
document.addEventListener('mozpointerlockerror', pointerlockerror, false);
document.addEventListener('webkitpointerlockerror', pointerlockerror, false);
document.addEventListener( 'click', function ( event ) {
// Ask the browser to lock the pointer
element.requestPointerLock = element.requestPointerLock || element.mozRequestPointerLock || element.webkitRequestPointerLock;
if ( /Firefox/i.test( navigator.userAgent ) ) {
var fullscreenchange = function ( event ) {
if ( document.fullscreenElement === element || document.mozFullscreenElement === element || document.mozFullScreenElement === element ) {
document.removeEventListener( 'fullscreenchange', fullscreenchange );
document.removeEventListener( 'mozfullscreenchange', fullscreenchange );
element.requestPointerLock();
}
}
document.addEventListener( 'fullscreenchange', fullscreenchange, false );
document.addEventListener( 'mozfullscreenchange', fullscreenchange, false );
element.requestFullscreen = element.requestFullscreen || element.mozRequestFullscreen || element.mozRequestFullScreen || element.webkitRequestFullscreen;
element.requestFullscreen();
} else {
element.requestPointerLock();
}
}, false );
} else {
console.log('Your browser doesn\'t seem to support Pointer Lock API');
}
// vars
var width = $(window).width(),
height = $(window).height(),
view_angle = 60,
aspect = width / height,
near = 0.1,
far = 20000,
movespeed = 100,
lookspeed = 0.5,
models = [];
// Physijs physics setup
Physijs.scripts.worker = 'js/physijs/physijs_worker.js';
Physijs.scripts.ammo = 'ammo.js';
// stats
var stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.bottom = '0px';
stats.domElement.style.zIndex = 100;
$(document.body).append(stats.domElement);
// timer
var timer = new THREE.Clock(),
time = Date.now();
// keyboard
//var keyboard = new THREEx.KeyboardState();
// scene
//var scene = new THREE.Scene();
var scene = new Physijs.Scene();
scene.setGravity(new THREE.Vector3(0, -30, 0));
scene.fog = new THREE.FogExp2(0xffffff, 0.00025);
// camera
var camera = new THREE.PerspectiveCamera(view_angle, aspect, near, far);
camera.position.set(0, 0, -30);
camera.lookAt(scene.position);
//scene.add(camera);
// renderer
var renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true
});
renderer.setSize(width, height);
renderer.shadowMapEnabled = true;
renderer.shadowMapSoft = true;
$(document.body).append(renderer.domElement);
// helpers
var axisHelper = new THREE.AxisHelper(50);
scene.add(axisHelper);
var test = new THREE.Object3D();
cube1 = new Physijs.BoxMesh(
new THREE.CubeGeometry(10, 10, 10),
Physijs.createMaterial(
new THREE.MeshNormalMaterial(), 0.2, 0.9
)
);
cube1.name = 'cube1';
cube1.addEventListener('collision', function(obj) {
console.log('CUBE -> ', obj);
});
test.add(cube1);
test.add(camera);
scene.add(test);
cube2 = new Physijs.BoxMesh(
new THREE.CubeGeometry(10, 10, 10),
Physijs.createMaterial(
new THREE.MeshNormalMaterial(), 0.2, 0.9
)
);
cube1.name = 'cube2';
cube2.position.z = 50;
cube2.addEventListener('collision', function(obj) {
console.log('CUBE2 -> ', obj);
});
scene.add(cube2);
// controls
//var controls = new THREE.FirstPersonControls(cube1);
//controls.movementSpeed = movespeed;
//controls.lookSpeed = lookspeed;
// controls.lookVertical = false;
// controls.noFly = true;
var controls = new THREE.PointerLockControls(test);
scene.add(controls.getObject());
// skybox
var Skybox = new Skybox('mp_001', 5000);
scene.add(Skybox.getElement());
// lensflare
new Lensflare(scene);
var loader = new THREE.JSONLoader();
loader.load('src/js/obj/maps/mp_001.js', function(geo, mat) {
material = Physijs.createMaterial(new THREE.MeshFaceMaterial(mat), 1, 1);
terrain = new Physijs.PlaneMesh(geo, material, 0);
//models.push(new THREE.Mesh(data, material));
//scene.add(model = new THREE.Mesh(data, material));
//
terrain.name = 'dirtroad';
terrain.position.z = 0;
terrain.position.y = 0;
terrain.position.x = 0;
scene.add(terrain);
}, 'assets/img/textures');
animate();
function animate() {
requestAnimationFrame(animate);
render();
update();
}
function update() {
stats.update();
}
function render() {
scene.simulate();
controls.update(Date.now() - time);
renderer.render(scene, camera);
time = Date.now();
}
</script>
</body>
</html>