-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
202 lines (170 loc) · 6.83 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
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
<!DOCTYPE HTML>
<html>
<head>
<title></title>
</head>
<body onload="init()" style="background-color: #eeeeee">
<canvas id="canvas" width="800" height="800"></canvas>
<script src="js/glMatrix-0.9.5.min.js"></script>
<script src="js/space.js"></script>
<script src="js/utils.js"></script>
<script type="text/javascript">
//Globals
var canvas, context, sceneRoot, viewer, environment, viewMode;
var animationDuration = 2500;
var mvMatrix = mat4.create();
var pMatrix = mat4.create();
var renderPipeline2D;
var init = function () {
SPACE.initCanvas('canvas', '2D');
environment = new SPACE.Environment();
environment.alpha = 0;
sceneRoot = new SPACE.Node();
canvas.onclick = SPACE.canvasClicked;
createViewer();
createPeople();
viewMode = 'circle';
document.onkeyup = handleKeys;
animate();
};
var animate = function () {
setTimeout(function () {
animate()
}, 100);
drawScene();
};
var drawScene = function () {
var timer = new Date().getTime();
context.save();
renderPipeline2D = [];
viewer.setupView(context, pMatrix, mvMatrix);
environment.setupSceneForDraw(context);
viewer.animate(timer);
sceneRoot.animate(timer);
sceneRoot.draw(context, mvMatrix, pMatrix);
SPACE.drawRenderPipeline2D(renderPipeline2D, viewer);
context.restore();
};
var handleKeys = function (event) {
if (event.keyCode == 37) {
viewer.position.x -= 3;
}
else if (event.keyCode == 39) {
viewer.position.x += 3;
}
else if (event.keyCode == 38) {
viewer.position.y += 3;
}
else if (event.keyCode == 40) {
viewer.position.y -= 3;
}
else if(event.keyCode == 32) {
toggleViewModes();
}
viewer.lookAt({x: 0, y: 0, z: 0});
};
var toggleViewModes = function() {
console.log('Toggling view mode');
viewMode = (viewMode == 'circle') ? 'benchmarking' : 'circle';
var animationStartTime = new Date().getTime();
viewer.animationStartTime = animationStartTime;
viewer.animationStartPosition = UTILS.copyObject(viewer.position);
viewer.animationEndPosition = UTILS.copyObject(viewer.positions[viewMode]);
viewer.animationDuration = animationDuration;
for(var i in sceneRoot.children) {
var person = sceneRoot.children[i];
person.animationStartTime = animationStartTime;
person.animationStartPosition = UTILS.copyObject(person.position);
person.animationEndPosition = UTILS.copyObject(person.positions[viewMode]);
person.animationDuration = animationDuration;
}
};
var createViewer = function() {
viewer = new SPACE.Viewer();
viewer.positions = {
circle: {x: 5, y: 70, z: 80},
benchmarking: {x: 0, y: 0, z: 150}
};
viewer.position = UTILS.copyObject(viewer.positions.circle);
viewer.animate = function (timer) {
if (this.animationEndPosition) {
if ((timer - this.animationStartTime) > this.animationDuration) {
this.animationStartTime = null;
this.animationStartPosition = null;
this.animationEndPosition = null;
this.animationDuration = null;
}
else {
var animationIndex = (timer - this.animationStartTime) / this.animationDuration;
this.position.x = UTILS.naturalInterpolate(this.animationStartPosition.x, this.animationEndPosition.x, animationIndex, 1);
this.position.y = UTILS.naturalInterpolate(this.animationStartPosition.y, this.animationEndPosition.y, animationIndex, 1);
this.position.z = UTILS.naturalInterpolate(this.animationStartPosition.z, this.animationEndPosition.z, animationIndex, 1);
this.lookAt({x: 0, y: 0, z: 0});
}
}
};
viewer.lookAt({x: 0, y: 0, z: 0});
};
var createPeople = function () {
for (var i = 0; i < 50; i++) {
var x = 30 * Math.cos(i);
var z = 30 * Math.sin(i) + 3 * Math.random();
createPerson({x: x, y: 0, z: z}, i);
}
};
var createPerson = function (position, index) {
var person = new SPACE.Node();
person.position = position;
person.positions = {};
person.positions['circle'] = UTILS.copyObject(position);
if (index < 37) {
person.positions['benchmarking'] = {x: Math.random() + 2 * index - 30, y: 10, z: 0};
}
else {
person.positions['benchmarking'] = {x: Math.random() + 2 * index - 104, y: 0, z: 0};
}
person.animate = function (timer) {
if (this.animationEndPosition) {
if ((timer - this.animationStartTime) > this.animationDuration) {
this.animationStartTime = null;
this.animationStartPosition = null;
this.animationEndPosition = null;
this.animationDuration = null;
}
else {
var animationIndex = Math.max(2 * ((timer - this.animationStartTime) / this.animationDuration) - 1, 0);
this.position.x = UTILS.naturalInterpolate(this.animationStartPosition.x, this.animationEndPosition.x, animationIndex, 1);
this.position.y = UTILS.naturalInterpolate(this.animationStartPosition.y, this.animationEndPosition.y, animationIndex, 1);
this.position.z = UTILS.naturalInterpolate(this.animationStartPosition.z, this.animationEndPosition.z, animationIndex, 1);
}
}
};
var image = window.location.search ? 'images/' + window.location.search.replace('?image=', '') : 'images/man.png';
var sprite = new SPACE.Sprite();
sprite.size = 2.5;
sprite.setupForContext(context);
sprite.initialize(context, null, image);
person.children.push(sprite);
sprite.handleClick = function () {
alert('Here');
};
/*var mesh = new SPACE.Mesh();
mesh.setupForContext(context);
mesh.position = {x: 0, y: 0, z: 0};
mesh.drawingInformation.vertices = [
[
{x: 1.8, y: 2, z: 1},
{x: -1.8, y: 2, z: 1},
{x: -1.8, y: 2, z: -1},
{x: 1.8, y: 2, z: -1}
]
];
mesh.fillStyle = 'red';
mesh.isVisible = true;
mesh.drawingInformation.renderMode = 'SHAPES';
person.children.push(mesh);*/
sceneRoot.children.push(person);
};
</script>
</body>
</html>