From 75352e2929e85d6ffb27f2514863757933ea6d03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Mart=C3=ADn?= Date: Fri, 31 May 2013 12:03:32 +0200 Subject: [PATCH] Moved cameras to a separate file --- .../studio/static/coffee/cameras.coffee | 40 ++++++++++++++++ .../studio/static/coffee/studio.coffee | 47 ++----------------- .../studio/templates/studio/main.html | 1 + 3 files changed, 45 insertions(+), 43 deletions(-) create mode 100644 minecraftcodex/studio/static/coffee/cameras.coffee diff --git a/minecraftcodex/studio/static/coffee/cameras.coffee b/minecraftcodex/studio/static/coffee/cameras.coffee new file mode 100644 index 0000000..91f1074 --- /dev/null +++ b/minecraftcodex/studio/static/coffee/cameras.coffee @@ -0,0 +1,40 @@ +# +# CAMERAS +# +orthograpicCamera = + _self: null + _left: 0 + _right: 0 + _top: 0 + _bottom: 0 + + _near: -1000 + _far: 1000 + + init: (width, height) -> + @_left = width / -2 + @_right = width / 2 + @_top = height / 2 + @_bottom = height / -2 + @_near = width * -2 + @_far = width * 2 + camera = new THREE.OrthographicCamera @_left, @_right, @_top, @_bottom, @_near, @_far + @_self = camera + + +perspectiveCamera = + _fov: 45 + _aspectRatio: 0 + _near: 1 + _far: 1000 + + init: (width, height) -> + @_aspectRatio = width / height + camera = new THREE.PerspectiveCamera @_fov, @_aspectRatio, @_near, @_far + camera.position.z = 40 + @_self = camera + + +window.StudioCameras = + orthographicCamera: orthograpicCamera + perspectiveCamera: perspectiveCamera diff --git a/minecraftcodex/studio/static/coffee/studio.coffee b/minecraftcodex/studio/static/coffee/studio.coffee index 8a721bd..4dd5c39 100644 --- a/minecraftcodex/studio/static/coffee/studio.coffee +++ b/minecraftcodex/studio/static/coffee/studio.coffee @@ -25,9 +25,9 @@ Studio = # Callbacks onCameraChange: (cameraType) -> - if "#{cameraType}Camera" of StudioObjects + if "#{cameraType}Camera" of window.StudioCameras @_cameraType = cameraType - @camera = StudioObjects["#{cameraType}Camera"].init @width, @height + @camera = window.StudioCameras["#{cameraType}Camera"].init @width, @height if not @animating @animate() @@ -89,51 +89,12 @@ Studio = @light.intensity = 1.6 @scene.add @light - @object = new THREE.Mesh new THREE.CubeGeometry(16, 16, 16), new THREE.MeshNormalMaterial() + #@object = new THREE.Mesh new THREE.CubeGeometry(16, 16, 16), new THREE.MeshNormalMaterial() - @scene.add @object + #@scene.add @object # /test @animate() -# -# CAMERAS -# -orthograpicCamera = - _self: null - _left: 0 - _right: 0 - _top: 0 - _bottom: 0 - - _near: -1000 - _far: 1000 - - init: (width, height) -> - @_left = width / -2 - @_right = width / 2 - @_top = height / 2 - @_bottom = height / -2 - @_near = width * -2 - @_far = width * 2 - camera = new THREE.OrthographicCamera @_left, @_right, @_top, @_bottom, @_near, @_far - @_self = camera - - -perspectiveCamera = - _fov: 45 - _aspectRatio: 0 - _near: 1 - _far: 1000 - - init: (width, height) -> - @_aspectRatio = width / height - camera = new THREE.PerspectiveCamera @_fov, @_aspectRatio, @_near, @_far - camera.position.z = 40 - @_self = camera - window.Studio = Studio -window.StudioObjects = - 'orthographicCamera': orthograpicCamera - 'perspectiveCamera': perspectiveCamera diff --git a/minecraftcodex/studio/templates/studio/main.html b/minecraftcodex/studio/templates/studio/main.html index 515adb1..eb233d5 100644 --- a/minecraftcodex/studio/templates/studio/main.html +++ b/minecraftcodex/studio/templates/studio/main.html @@ -21,6 +21,7 @@ +