-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
200 lines (176 loc) · 4.21 KB
/
example.js
File metadata and controls
200 lines (176 loc) · 4.21 KB
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
"use strict";
/* globals Tundra, Physijs, THREE, Stats, ExampleApp, Car, PhysijsView */
// For conditions of distribution and use, see copyright notice in LICENSE
/*
* @author Tapani Jamsa
* Date: 2014
*/
var app;
// var carSize; // TODO debug remove
var ground_material;
function init() {
app = new ExampleApp();
var host = "localhost"; // hostname of the Tundra server
var port = 2345; // and port to the server
app.start();
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
function createElement(pos, rot, scale) {
var element = new Physijs.BoxMesh(
new THREE.CubeGeometry(scale.x, scale.y, scale.z),
ground_material,
0 // mass
);
element.position.set(pos.x, pos.y, pos.z);
element.rotation.set(rot.x, rot.y, rot.z);
element.receiveShadow = true;
app.viewer.scene.add(element);
}
// Custom app specific properties
app.dataConnection.loginData = {
"name": Date.now().toString() + getRandomInt(0, 2000000).toString()
};
// STATS
app.physics_stats = new Stats();
app.physics_stats.domElement.style.position = 'absolute';
app.physics_stats.domElement.style.bottom = '50px';
app.physics_stats.domElement.style.zIndex = 100;
app.viewer.container.appendChild(app.physics_stats.domElement);
// GROUND
ground_material = Physijs.createMaterial(
new THREE.MeshLambertMaterial({
map: THREE.ImageUtils.loadTexture('images/rocks.jpg')
}),
0.8, // high friction
.3 // low restitution
);
ground_material.map.wrapS = ground_material.map.wrapT = THREE.RepeatWrapping;
ground_material.map.repeat.set(3, 3);
createElement({
x: 0,
y: -3,
z: -25
}, {
x: 0,
y: 0,
z: 0
}, {
x: 50,
y: 1,
z: 100
});
// RAMPS
createElement({
x: 0,
y: -3,
z: -10
}, {
x: -0.2,
y: 0,
z: 0
}, {
x: 10,
y: 1,
z: 13
});
createElement({
x: 10,
y: -3,
z: -10
}, {
x: -0.5,
y: 0,
z: 0
}, {
x: 10,
y: 1,
z: 25
});
// WALLS
createElement({
x: -25,
y: 0,
z: -25
}, {
x: 0,
y: 0,
z: 0
}, {
x: 1,
y: 25,
z: 100
});
createElement({
x: 25,
y: 0,
z: -25
}, {
x: 0,
y: 0,
z: 0
}, {
x: 1,
y: 25,
z: 100
});
createElement({
x: 0,
y: 0,
z: -75
}, {
x: 0,
y: 0,
z: 0
}, {
x: 50,
y: 25,
z: 1
});
createElement({
x: 0,
y: 0,
z: 25
}, {
x: 0,
y: 0,
z: 0
}, {
x: 50,
y: 5,
z: 1
});
// Car
app.car = new Car(app, new THREE.Vector3(0, 2, -60));
// CAMERA
app.viewer.camera.position.set(0, 20, 40);
app.viewer.camera.lookAt(new THREE.Vector3());
app.car.useCameraFollow = false;
// // FREE LOOK
// var freeLookCtrl = new THREE.FreeLookControls(app.viewer.camera, app.viewer.renderer.domElement);
// app.scene.add(freeLookCtrl.getObject());
// // An object in freeLookCtrl that carries the camera. Set it's position instead of setting camera position directly
// freeLookCtrl.getObject().position.set(0, 8.50, 28.50);
app.connect(host, port);
}
function ExampleApp() {
Tundra.Application.call(this); // Super class
}
ExampleApp.prototype = new Tundra.Application();
ExampleApp.prototype.constructor = ExampleApp;
ExampleApp.prototype.createViewer = function() {
return new PhysijsView();
};
ExampleApp.prototype.logicUpdate = function(dt) {
// PHYSICS
// Fixed time step
// app.viewer.scene.setFixedTimeStep(1 / 240);
// var timeStep = 1 / 60;
// var maxSubSteps = 5;
// this.viewer.scene.simulate(timeStep, maxSubSteps); // run physics
this.viewer.scene.simulate(); // run physics
if (this.physics_stats) {
this.physics_stats.update();
}
};
init();