forked from imakewebthings/deck.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpresentation.html
More file actions
597 lines (489 loc) · 17.7 KB
/
Copy pathpresentation.html
File metadata and controls
597 lines (489 loc) · 17.7 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
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=1024, user-scalable=no">
<title>Your deck.js Presentation</title>
<!-- Required stylesheet -->
<link rel="stylesheet" href="core/deck.core.css">
<!-- Extension CSS files go here. Remove or add as needed. -->
<link rel="stylesheet" media="screen" href="extensions/goto/deck.goto.css">
<link rel="stylesheet" media="screen" href="extensions/menu/deck.menu.css">
<link rel="stylesheet" media="screen" href="extensions/navigation/deck.navigation.css">
<link rel="stylesheet" media="screen" href="extensions/status/deck.status.css">
<link rel="stylesheet" media="screen" href="extensions/scale/deck.scale.css">
<!-- Style theme. More available in /themes/style/ or create your own. -->
<link rel="stylesheet" media="screen" href="themes/style/neon.css">
<!-- Transition theme. More available in /themes/transition/ or create your own. -->
<link rel="stylesheet" media="screen" href="themes/transition/vertical-slide.css">
<!-- Basic black and white print styles -->
<link rel="stylesheet" media="print" href="core/print.css">
<!-- Required Modernizr file -->
<script src="modernizr.custom.js"></script>
</head>
<body>
<div class="deck-container">
<!-- Begin slides. Just make elements with a class of slide. -->
<section class="slide">
<h1>Reactive Orientation</h1>
<h3>@zapletal_martin, @teroxik</h3>
</section>
<section class="slide">
<h2>Application overview</h2>
<ul>
<li> HTML5 orientation API </li>
<li> Ember.js </li>
<li> Three.js </li>
<li> Play framework 2.3
<ul>
<li> Iteratee/Enumerator </API>
<li> Web socket actors </API>
</ul>
</li>
<li> Scalaz </li>
<li> Bootstrap </li>
</ul>
</section>
<section class="slide">
<h2>Iteratee/Enumerator/Enumeratee</h2>
<ul>
<li>abstraction over data streams</li>
<li>handle data streams reactively in a non-blocking, generic & composable way for modern web programming in distributed environments</li>
<li>Websockets in our case</li>
<li>Iteratee => Consumer</li>
<li>Enumerator => Producer</li>
<li>Enumerator => Adapter</li>
</ul>
</section>
<section class="slide">
<h2>Iteratee/Enumerator/Enumeratee</h2>
<ul>
<li>Iteratee => Consumer - Iteratee[A,E] - consumes value A and eventually produces value B
<pre>
object Step {
case class Done[+A, E](a: A, remaining: Input[E]) extends Step[E, A]
case class Cont[E, +A](k: Input[E] => Iteratee[E, A]) extends Step[E, A]
case class Error[E](msg: String, input: Input[E]) extends Step[E, Nothing]
}
</pre>
<p>Input[E] - El[E],Empty,EOF</p>
</li>
<li>Enumerator => Producer, pushes data to Iteratee, contains methods for reading streams
<pre>
trait Enumerator[E] {
/**
* Apply this Enumerator to an Iteratee
*/
def apply[A](i: Iteratee[E, A]): Future[Iteratee[E, A]]
}
</pre>
<p>Another method for creation of Enumerators is by using channels.</p>
<pre>
val enumerator = Concurrent.unicast[String](onStart = channel => {
channel.push("Hello")
channel.push("World")
})
</pre>
</li>
<li>Enumeratee => Adapter - used for mapping Iteratees/Enumerators to Iteratees/Enumerators which accepts different types</li>
</ul>
</section>
<section class="slide">
<h2>Web Sockets </h2>
<ul>
<li>Call backs - onOpen, onClose, onMessage</li>
<li>Two way realtime communication - send method</li>
<li>well supported</li>
<li>Iteratee => Consumer</li>
<li>Enumerator => Producer</li>
</ul>
</section>
<section class="slide">
<h2>Web Sockets - Iteratees</h2>
<pre>
val (dataEnumerator, dataChannel) = Concurrent.broadcast[JsValue]
def mobileWebSocket = WebSocket.acceptWithActor[OrientationChangeEvent, JsValue] { request => out =>
Props(new StreamMergingActor(dataChannel))
}
def dashboardWebSocket = WebSocket.using[JsValue] { request =>
(Iteratee.ignore, dataEnumerator)
}
</pre>
<ul>
<li>You have to provide in and out channels</li>
<li>you can get a broadcast channel on which you can listen</li>
<li>
<pre>
// Concurrent.broadcast returns (Enumerator, Concurrent.Channel)
val (out, channel) = Concurrent.broadcast[String]
</pre>
</li>
<li>
We used Iteratee/Enumerator approach in the beginning in the beginnig and the we combined it with the Web Socket Actors
</li>
</ul>
</section>
<section class="slide">
<h2>Web Sockets - Actors</h2>
<pre>
import play.api.mvc._
import play.api.Play.current
def socket = WebSocket.acceptWithActor[JsValue, JsValue] { request => out =>
MyWebSocketActor.props(out)
}
</pre>
<ul>
<li><h4>tryAcceptWith</h4> - deny a message - if user is not present</li>
<li><h4>cleaning resources</h4> - when websocket is closed - actor is stopped
<pre>
override def postStop() = {
someResource.close()
}
</pre>
</li>
<li><h4>Message types</h4>
String, ArrayByte, JSValue - parsed from String, implicit FrameFormatter
</li>
<li><pre>
def receive = {
case e: OrientationChangeEvent =>
println(self + e.toString)
produceMessage(convertDegreesToRadians(e))
}
def produceMessage(event: OrientationChangeEvent) = dataChannel.push(Json.toJson(event))
</pre></li>
<li><a href="http://www.playframework.com/documentation/2.3.x/ScalaWebSockets">http://www.playframework.com/documentation/2.3.x/ScalaWebSockets</a></li>
</ul>
</section>
<section class="slide">
<h2>Scalaz</h2>
<ul>
<li> Provides purely functional data structures to complement those from the Scala standard library </li>
<li> Requires deep understanding of functional programming idioms </li>
<li> The good parts of Scalaz </li>
<li> <a href="http://www.cakesolutions.net/teamblogs/2011/11/19/u-s-scalaz-layout"> Keybord layout</a> </li>
<li><a href="https://github.com/scalaz/scalaz"> https://github.com/scalaz/scalaz </a></li>
</ul>
</section>
<section class="slide">
<h2>Scalaz</h2>
<pre>
cohoist[M[_], N[_]: Comonad](f: M ~> N): ({type f[x] = F[M, x]})#f ~> ({type f[x] = F[N, x]})#f
<br\>
def co2_2[T[_, +_], Z, A, B](a: B <~< Z): T[A, B] <~< T[A, Z] =
a.subst[({type λ[-α]= T[A, α] <~< T[A, Z]})#λ](refl)
</pre>
</section>
<section class="slide">
<h2>Scalaz</h2>
<ul>
<li>Typeclasses</li>
<li>Functors, applicatives, monoids, monads</li>
<li>Validation</li>
<li>Lenses</li>
</ul>
</section>
<section class="slide">
<h2>HTML 5 orientation API</h2>
<p><img src="images/motion-control.jpg"></p>
</section>
<section class="slide">
<h2>HTML 5 orienation </h2>
<ul>
<li><h3>DeviceOrientationEvent</h3>
<p>Event provides values in degrees which are difference between device and earth coordinates.
<pre>window.addEventListener("deviceorientation", processEvent, true);</pre>
<img src="images/axes.png" >
</li>
</ul>
</section>
<section class="slide">
<h2>HTML 5 orienation </h2>
<ul>
<li><h4>DeviceOrientationEvent.alpha</h4>
<p>the motion of the device around the z axis, <0,360> </p>
<img src="images/alpha.png" >
</li>
</ul>
</section>
<section class="slide">
<h2>HTML 5 orienation </h2>
<ul>
<li><h4>DeviceOrientationEvent.beta</h4>
<p>the motion of the device around the x axis, <-180,180></p>
<img src="images/beta.png" >
</li>
</ul>
</section>
<section class="slide">
<h2>HTML 5 orienation </h2>
<ul>
<li><h4>DeviceOrientationEvent.gamma</h4>
<p>the motion of the device around the y axis, <-90,90></p>
<img src="images/gamma.png" >
</li>
</ul>
</section>
<section class="slide">
<h2>Rotation</h2>
<p>Rotation is described about any given axis in terms of the number of degrees of difference between the device's coordinate frame and the Earth coordinate frame, and is measured in degrees.<p>
<ul>
<li>
Earth Coordinates
<ul>
<li>The <b>X</b> axis follows along the ground plane, perpendicular to the Y axis and positive toward the east (and therefore negative toward the west).</li>
<li>The <b>Y</b> axis follows along the ground plane, and is positive toward true north (that is, the North Pole, not magnetic north) and negative toward true south.</li>
<li>The <b>Z</b> axis is perpendicular to the ground plane; think of it as a line drawn between the device and the center of the Earth. The value of the Z coordinate is positive upward (away from the center of the Earth) and negative downward (toward the center of the Earth).</li>
</ul>
</li>
</ul>
</section>
<section class="slide">
<h2>HTML 5 orientation API - Code Snippet</h2>
<pre>
if(window.DeviceOrientationEvent) {
window.addEventListener('deviceorientation', function(event) {
if (self.get("startOn")) {
var orientationData =
Orientation.calculateEulerOrientationForDevice(event);
var data = {
deviceInfo: self.model.deviceInfo,
deviceId: self.model.deviceId,
colour: self.model.colour,
data: orientationData
};
self.set('model', data)
self.socket.send(JSON.stringify(data));
}
}, false);
}
</pre>
</section>
<section class="slide">
<h2>Science Fun - Apollo 11</h2>
<img src="images/gimbal.gif" style="float:left">
<img src="images/lock.gif" style="float:right">
<div style="clear:both"></div>
<div>
<p><blockquote cite="http://example.org">
<p>The advantages of the redundant gimbal seem to be outweighed by the equipment simplicity, size advantages, and corresponding implied reliability of the direct three degree of freedom unit.
</p>
<p><cite>David Hoag, Apollo Lunar Surface Journal</cite></p></blockquote></p>
<p><blockquote cite="http://example.org">
<p>Near that point, in a closed stabilization loop, the torque motors could theoretically be commanded to flip the gimbal 180 degrees instantaneously. Instead, in the LM, the computer flashed a 'gimbal lock' warning at 70 degrees and froze the IMU at 85 degrees"
</p>
<p><cite>Paul Fjeld, Apollo Lunar Surface Journal</cite></p></blockquote></p>
</div>
</section>
<section class="slide">
<h2>HTML 5 orientation - Caveats + Support </h2>
<ul>
<li><h3>Support</h3>
<p>Supported by most of the Android(Firefox,Chrome) and iOS-based browsers</p>
<p>Not supported by default Android browsers in older versions</p>
</li>
<li><h3>Caveats</h3>
<p>iOS-based browsers deviceOrientationData.alpha as an arbitrary non-compass-based value.
It has to be recomputed = (360 - deviceOrientationData.webkitCompassHeading)</p>
<p>It is not possible to use these values directly for orientation - because of gimbal lock - if the angles get too close we don't know aroud which axis wea are spinnign</p>
<p>Solution: matrix based rotation system, quaternion based system</p>
<li><h3>Links</h3>
<p><a href="http://dev.opera.com/articles/w3c-device-orientation-usage/">http://dev.opera.com/articles/w3c-device-orientation-usage/</a></p>
</li>
</ul>
</section>
<section class="slide">
<h2>Ember.js</h2>
<div style="width:601px; height: auto; float: center">
<img src="images/global_199941742.jpeg" style="width:300px; height: auto; float: center">
<!--<img src="images/tomster-under-construction.png" style="width:300px; height: auto; float: right">-->
</div>
<ul>
<li>js single page web application framework</li>
<li>MVC (MVVM)</li>
<li>data binding</li>
<li>convention over configuration</li>
<li><a href="http://todomvc.com/">Better than Angular?</a></li>
</ul>
</section>
<section class="slide">
<h2>Ember.js</h2>
<img src="images/ember-sketch.png" style="float:right;width:600px; height: auto;"
<ul>
<li>Model</li>
<li>Router</li>
<li>Route</li>
<li>Controller</li>
<li>View</li>
<li>Template</li>
</ul>
</section>
<section class="slide">
<h2>Ember.js</h2>
<img src="images/app-sketch.png" style="float:right">
</section>
<section class="slide">
<h2>Ember.js</h2>
<pre>
var Person = Ember.Object.extend({
say: function(thing) {
var name = this.get('name');
alert(name + " says " + thing);
}
});
var Soldier = Person.extend({
say: function(thing) {
this._super(thing + ", sir!");
}
});
var inst = Soldier.create({
name: "John"
})
inst.say("Yes");
</pre>
</section>
<section class="slide">
<h2>Ember.js</h2>
<pre>
var Person = Ember.Object.extend({
firstName: null,
lastName: null,
displayName: function() {
return this.get('firstName') + " " + this.get('lastName');
}.property('firstName', 'lastName'),
nameChanged: function() {
//do something
}.observer('fullname');
});
</pre>
</section>
<section class="slide">
<h2>Ember.js</h2>
<pre>
App.Person = DS.Model.extend({
firstName: DS.attr('string'),
lastName: DS.attr('string')
})
</pre>
</section>
<section class="slide">
<h2>Three.js</h2>
<ol>
<li>
<h3>Camera</h3>
<p>Slide content is simple HTML.</p>
</li>
<li>
<h3>Scene</h3>
<p>Container for all the objects</p>
</li>
<li>
<h3>Mesh</h3>
<p>geometries + materials => objects in the scene, lights => shadows generation</p>
</li>
<li>
<h3>Renderer</h3>
<pre>
function animate() {
requestAnimationFrame(animate);
render();
}
function render() {
mesh.rotation.x += 0.02;
mesh.rotation.z += 0.03;
renderer.render(scene, camera);
}
</pre>
</li>
<li>
<h3>Coordinates</h3>
<p> <-1;1> </p>
</li>
</ol>
</section>
<section class="slide">
<h2>3D object</h2>
<div id="canvas"></div>
<p><a href="http://jsfiddle.net/teroxik/4Rqgq/">http://jsfiddle.net/teroxik/4Rqgq/</a></p>
<p><a href="http://www.glassdoor.co.uk/Salaries/member-of-technical-staff-salary-SRCH_KO0,25.htm">examples</a></p>
</section>
<section class="slide">
<h2>Questions?</h2>
<h4>Thank you for your patience!</h4>
</section>
<!-- End slides. -->
<!-- Begin extension snippets. Add or remove as needed. -->
<!-- deck.navigation snippet -->
<div aria-role="navigation">
<a href="#" class="deck-prev-link" title="Previous">←</a>
<a href="#" class="deck-next-link" title="Next">→</a>
</div>
<!-- deck.status snippet -->
<p class="deck-status" aria-role="status">
<span class="deck-status-current"></span>
/
<span class="deck-status-total"></span>
</p>
<!-- deck.goto snippet -->
<form action="." method="get" class="goto-form">
<label for="goto-slide">Go to slide:</label>
<input type="text" name="slidenum" id="goto-slide" list="goto-datalist">
<datalist id="goto-datalist"></datalist>
<input type="submit" value="Go">
</form>
<!-- End extension snippets. -->
</div>
<!-- Required JS files. -->
<script src="jquery.min.js"></script>
<script src="core/deck.core.js"></script>
<!-- Extension JS files. Add or remove as needed. -->
<script src="extensions/menu/deck.menu.js"></script>
<script src="extensions/goto/deck.goto.js"></script>
<script src="extensions/status/deck.status.js"></script>
<script src="extensions/navigation/deck.navigation.js"></script>
<script src="extensions/scale/deck.scale.js"></script>
<!-- Initialize the deck. You can put this in an external file if desired. -->
<script>
$(function() {
$.deck('.slide');
});
</script>
<script src="http://www.html5canvastutorials.com/libraries/three.min.js"></script>
<script defer="defer">
// revolutions per second
var angularSpeed = 0.2;
var lastTime = 0;
// this function is executed on each animation frame
function animate(){
// update
var time = (new Date()).getTime();
var timeDiff = time - lastTime;
var angleChange = angularSpeed * timeDiff * 2 * Math.PI / 1000;
cube.rotation.y += angleChange;
lastTime = time;
// render
renderer.render(scene, camera);
// request new frame
requestAnimationFrame(function(){
animate();
});
}
// renderer
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.getElementById("canvas").appendChild(renderer.domElement);
// camera
var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.z = 500;
// scene
var scene = new THREE.Scene();
// cube
var cube = new THREE.Mesh(new THREE.CubeGeometry(200, 200, 200), new THREE.MeshNormalMaterial());
cube.overdraw = true;
scene.add(cube);
// start animation
animate();
</script>
</body>
</html>