forked from kevinroast/phoria.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
297 lines (287 loc) · 10.7 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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>phoria.js</title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300' rel='stylesheet' type='text/css'>
<style type="text/css">
@font-face
{
font-family: OstrichSans;
src: url('ostrich-black-webfont.woff');
}
body
{
background-color: #fff;
font-family: 'Open Sans', Helvetica;
color: #333;
}
.header
{
margin: 20px;
background-color: #eee;
border-radius: 32px;
height: 18em;
}
P
{
font-size: 1.2em;
padding-left: 20px;
padding-top: 0;
padding-bottom: 0;
line-height: 1em;
margin-top: 0;
}
.inline
{
display: inline-block;
}
.left
{
float: left;
}
.title
{
font-family: 'Open Sans', Helvetica;
padding-left: 20px;
padding-top: 120px;
color: #000;
font-size: 1.75em;
}
.desc
{
font-family: 'Open Sans', Helvetica;
font-weight: 300;
color: #333;
line-height: 1.75em;
}
canvas
{
border: 1px solid #aaa;
background-color: #eee;
vertical-align: top;
}
.info > p
{
line-height: 1.2em;
}
a, a:visited, a:active, a:hover
{
font-size: 1em;
line-height: 1em;
color: #225588;
text-decoration: none;
}
a:hover
{
text-decoration: underline;
}
.credits
{
text-align: center;
font-size: 90%;
}
.button-overlay
{
position: absolute;
right: 8em;
}
</style>
<script src="scripts/gl-matrix-min.js"></script>
<script src="scripts/phoria-min.js"></script>
<script async defer src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4e4813104686cad8"></script>
<script>
var requestAnimFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame || window.msRequestAnimationFrame ||
function(c) {window.setTimeout(c, 15)};
// bind to window onload event
window.addEventListener('load', onloadHandler, false);
function onloadHandler()
{
// get the canvas DOM element and the 2D drawing context
var canvas = document.getElementById('canvas');
// create the scene and setup camera, perspective and viewport
var scene = new Phoria.Scene();
scene.camera.position = {x:0.0, y:5.0, z:-15.0};
scene.perspective.aspect = canvas.width / canvas.height;
scene.viewport.width = canvas.width;
scene.viewport.height = canvas.height;
// create a canvas renderer
var renderer = new Phoria.CanvasRenderer(canvas);
// add a grid to help visualise camera position etc.
var plane = Phoria.Util.generateTesselatedPlane(16,16,0,20);
scene.graph.push(Phoria.Entity.create({
points: plane.points,
edges: plane.edges,
polygons: plane.polygons,
style: {
drawmode: "wireframe",
linewidth: 0.5,
objectsortmode: "back"
}
}));
var cube = Phoria.Util.generateUnitCube(1);
var testCube = Phoria.Entity.create({
points: cube.points,
edges: cube.edges,
polygons: cube.polygons,
style: {
drawmode: "solid"
}
});
scene.graph.push(testCube);
cube = Phoria.Util.generateUnitCube(0.5);
var childCube = Phoria.Entity.create({
points: cube.points,
edges: cube.edges,
polygons: cube.polygons,
style: {
color: [0,0,0],
drawmode: "wireframe"
}
});
// add child object
testCube.children.push(childCube);
var blueLightObj = Phoria.Entity.create({
points: [{x:0, y:2, z:-5}],
style: {
color: [0,0,255],
drawmode: "point",
shademode: "plain",
linewidth: 5,
linescale: 2
}
});
scene.graph.push(blueLightObj);
var blueLight = Phoria.PointLight.create({
position: {x:0, y:2, z:-5},
color: [0,0,1]
});
blueLightObj.children.push(blueLight);
var redLightObj = Phoria.Entity.create({
points: [{x:0, y:2, z:5}],
style: {
color: [255,0,0],
drawmode: "point",
shademode: "plain",
linewidth: 5,
linescale: 2
}
});
scene.graph.push(redLightObj);
var redLight = Phoria.PointLight.create({
position: {x:0, y:2, z:5},
color: [1,0,0]
});
redLightObj.children.push(redLight);
var greenLightObj = Phoria.Entity.create({
points: [{x:0, y:2, z:5}],
style: {
color: [0,255,0],
drawmode: "point",
shademode: "plain",
linewidth: 5,
linescale: 2
}
});
scene.graph.push(greenLightObj);
var greenLight = Phoria.PointLight.create({
position: {x:0, y:2, z:5},
color: [0,1,0]
});
greenLightObj.children.push(greenLight);
var pause = false;
var rotates = [0,0,0];
var fnAnimate = function() {
if (!pause)
{
// rotate local matrix of an object
testCube.rotateY(0.5*Phoria.RADIANS);
// translate local matrix of child object - will receive rotation from parent
childCube.identity().translateY(Math.sin(Date.now() / 1000) + 3);
// translate visible light objects around the origin - will rotate child Light emitters
var sine = Math.sin(Date.now() / 500);
blueLightObj.identity().rotateY(rotates[0]+=1*Phoria.RADIANS).translateY(sine);
redLightObj.identity().rotateY(rotates[1]+=0.5*Phoria.RADIANS).translateY(sine);
greenLightObj.identity().rotateY(rotates[2]+=1.5*Phoria.RADIANS).translateY(sine);
// execute the model view 3D pipeline
scene.modelView();
// and render the scene
renderer.render(scene);
}
requestAnimFrame(fnAnimate);
};
// key binding
document.addEventListener('keydown', function(e) {
switch (e.keyCode)
{
case 27:
{
pause = !pause;
break;
}
}
}, false);
requestAnimFrame(fnAnimate);
}
</script>
</head>
<body>
<a href="https://github.com/kevinroast"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://github-camo.global.ssl.fastly.net/e7bbb0521b397edbd5fe43e7f760759336b5e05f/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677265656e5f3030373230302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png"></a>
<div class="button-overlay">
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style addthis_32x32_style">
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_compact"></a>
<a class="addthis_counter addthis_bubble_style"></a>
</div>
<!-- AddThis Button END -->
</div>
<div class="header">
<div class="left"><a href="."><img style="padding-left:20px" src="flower.png" width="214" height="263" alt="" border="0"></a></div>
<div style="margin-left:14em">
<p class="title">Phoria</p>
<p class="desc">pho·ri·a (fôr-)</p>
<p class="desc">n. The relative directions of the eyes during binocular fixation on a given object</p>
</div>
</div>
<div style="margin: 24px 20px">
<canvas id="canvas" width="384" height="256"></canvas>
<div class="inline" style="margin-left:20px">
<p><a href="test0.html">test 0 - basic cube on grid</a>
<p><a href="test0t.html">test 0t - textured cube</a>
<p><a href="test0uv.html">test 0uv - UV coordinates texturing</a>
<p><a href="test0k.html">test 0k - WASD and arrow keys move around scene</a>
<p><a href="test0r.html">test 0r - incremental rotation - mouse control</a>
<p><a href="test0q.html">test 0q - World and Local axis rotation using quaternions</a>
<p><a href="test0p.html">test 0p - object selection 'picking'</a>
<p><a href="test1.html">test 1 - animated point lights around a cube</a>
<p><a href="test1d.html">test 1d - live debug information in a scene</a>
<p><a href="test1t.html">test 1t - transparent polygons, plain and textured</a>
<p><a href="test2i.html">test 2 - example WaveFront .obj file importer</a>
<p><a href="test3.html">test 3 - sphere with point lighting</a>
<p><a href="test3s.html">test 3s - software rendered triangles</a>
<p><a href="test3p.html">test 3p - lightsourced point sphere</a>
<p><a href="test3m.html">test 3m - material test with specular highlights</a>
<p><a href="test4g.html">test 4g - particle emitter with gravity</a>
<p><a href="test4p.html">test 4p - particles as point lights</a>
<p><a href="test4t.html">test 4t - sprite particles flame effect</a>
<p><a href="test5.html">test 5 - dynamic texturing - paint gun</a>
<p><a href="test6.html">test 6 - data visualisation - graph</a>
<p><a href="test7.html">test 7 - scene triggers - a sequence of actions</a>
<p><a href="test8.html">test 8 - scene triggers, particle field, spaceships</a>
<p><a href="test9.html">test 9 - fireworks demo - scene triggers, particles</a>
</div>
<div class="info">
<p><b>What's all this then?</b> - phoria.js is a JavaScript library for simple 3D graphics on a canvas 2D renderer. It does not use WebGL - so works on any device that can display HTML5 Canvas - so all modern browsers and including iOS and Android phones! It uses the excellent vector and matrix maths library <a href="http://glmatrix.net">gl-matrix.js</a>.</p>
<p><b>Can I play with it?</b> - Yes you can: view the code on <a href="https://github.com/kevinroast/phoria.js">GitHub</a> or <a href="https://github.com/kevinroast/phoria.js/releases">download the latest release</a> including all the demos.</p>
<p><b>Is there any documentation?</b> - Not much. It's still in development and there is no documentation but the well commented code and simple example pages.</p>
<p><b>This is cool, is there more?</b> - There's a bunch more fun HTML5 canvas demos and games to play <a href="../index.html">on my site</a>.</p>
</div>
</div>
<div class="credits">
Copyright (C) Kevin Roast 2013-2014 - <a href="http://twitter.com/kevinroast" target="new">Follow me on Twitter</a> - Last updated: 26th January 2014.
</div>
</body>
</html>