summaryrefslogtreecommitdiff
path: root/js/lib/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/app.js')
-rw-r--r--js/lib/app.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/js/lib/app.js b/js/lib/app.js
new file mode 100644
index 0000000..2138025
--- /dev/null
+++ b/js/lib/app.js
@@ -0,0 +1,69 @@
+
+var scene, cam, controls
+
+var app = (function() {
+
+ var app = {}
+ var last_t = 0, initial_t = 0
+
+ app.init = function() {
+ app.bind()
+ app.build()
+ // check if we're in an iframe
+ if (window.self === window.top) {
+ app.ready()
+ }
+ }
+
+ app.bind = function() {
+ $(window).resize(app.resize)
+ }
+
+ app.build = function() {
+ if ($.browser.msie || ! has3d()) { return app.fallback() }
+
+ scene = new MX.Scene().addTo('#scene')
+ cam = scene.camera
+
+ app.resize()
+
+ window.scrollTo(0,0)
+ environment.init()
+ }
+
+ app.ready = function() {
+ if (last_t) return
+ setTimeout(function () {
+ $("html").removeClass("loading")
+ }, 100)
+ app.animate(0)
+ }
+
+ app.animate = function (t) {
+ requestAnimationFrame(app.animate)
+ if (! initial_t) {
+ initial_t = t
+ return
+ }
+ t -= initial_t
+ var dt = t - last_t
+ last_t = t
+ environment.update(t)
+ }
+
+ app.resize = function () {
+ scene.width = window.innerWidth
+ scene.height = window.innerHeight
+ scene.perspective = Math.min(window.innerWidth, scene.height)
+ scene.update()
+ }
+
+ app.fallback = function(){
+ $('body').addClass('fallback')
+ }
+
+ return app
+
+})()
+
+document.addEventListener('DOMContentLoaded', app.init)