-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathApp.js
137 lines (107 loc) · 3.51 KB
/
App.js
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
"use strict";
//Core
include("core/math/MatrixGenerator.js");
include("core/math/Vector2.js");
include("core/math/Vector3.js");
include("core/math/Vector4.js");
include("core/math/Matrix.js");
include("core/math/Matrix4.js");
include("core/math/Conversion.js");
include("core/math/MathsUtils.js");
include("core/math/Color.js");
include("core/math/geometry/Box.js");
include("core/math/geometry/Sphere.js");
include("core/input/Key.js");
include("core/input/Keyboard.js");
include("core/input/Mouse.js");
include("core/loaders/FileLoader.js");
include("core/loaders/OBJLoader.js");
include("core/utils/Timer.js");
include("core/Font.js");
include("core/texture/Texture.js");
include("core/texture/DataTexture.js");
include("core/texture/RenderTargetTexture.js");
include("core/geometry/Geometry.js");
include("core/geometry/BoxGeometry.js");
include("core/geometry/PlaneGeometry.js");
include("core/geometry/GrassGeometry.js");
include("core/geometry/SphereGeometry.js");
include("core/materials/Material.js");
include("core/materials/mesh/MeshMaterial.js");
include("core/materials/mesh/BasicMaterial.js");
include("core/materials/mesh/DepthMaterial.js");
include("core/materials/mesh/PhongMaterial.js");
include("core/materials/mesh/GrassMaterial.js");
include("core/materials/mesh/DissolveMaterial.js");
include("core/materials/mesh/NormalMaterial.js");
include("core/objects/Object3D.js");
include("core/objects/Scene.js");
include("core/objects/Sprite.js");
include("core/objects/Mesh.js");
include("core/objects/particle/Particle.js");
include("core/objects/particle/ParticleEmitter.js");
include("core/objects/light/AmbientLight.js");
include("core/objects/light/DirectionalLight.js");
include("core/objects/light/PointLight.js");
include("core/objects/camera/Camera.js");
include("core/objects/camera/OrthographicCamera.js");
include("core/objects/camera/PerspectiveCamera.js");
include("core/renderer/shader/Shader.js");
include("core/renderer/Renderer.js");
include("core/physics/Body.js");
include("core/physics/World.js");
include("core/physics/BodyObject.js");
//Data
include("data/models/house.js");
include("data/models/tank.js");
//Game
include("example/Player.js");
include("example/Axis.js");
include("example/Arena.js");
//App class
function App(){}
// App Initialization
App.initialize = function()
{
App.renderer = new Renderer();
App.renderer.canvas.onclick = function()
{
try
{
var canvas = App.renderer.canvas;
canvas.requestPointerLock = canvas.mozRequestPointerLock || canvas.requestPointerLock || canvas.webkitRequestPointerLock;
canvas.requestPointerLock();
}
catch(e){}
};
App.keyboard = new Keyboard();
App.mouse = new Mouse();
App.screen = new Arena();
App.resize(window.innerWidth, window.innerHeight);
App.loop();
}
// Timer to update game logic and render stuff (switch to independent timers?)
App.loop = function()
{
//Update Mouse Values (to keep in sync with game actions)
App.mouse.update();
App.screen.update();
App.screen.draw(App.renderer);
//Call loop again
requestAnimationFrame(App.loop, 0);
}
// Called every time page is resized
App.resize = function()
{
var width = window.innerWidth;
var height = window.innerHeight;
App.renderer.canvas.width = width;
App.renderer.canvas.height = height;
App.renderer.resize(width, height);
App.screen.resize(width, height);
}
//Check if mouse is locked (cross-browser)
App.isMouseLocked = function()
{
return document.pointerLockElement === canvas || document.mozPointerLockElement === canvas || document.webkitPointerLockElement === canvas;
}