From 5a98239a7c326520f0ebe06bbd213a54895b2f6f Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Sat, 22 Aug 2015 19:42:44 -0400 Subject: [PATCH] reset navigation --- js/menus/NavViewMenu.js | 5 +++-- js/models/AppState.js | 4 ++++ js/three/ThreeModel.js | 24 ++++++++++++++++++++---- js/three/ThreeView.js | 6 ++++++ 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/js/menus/NavViewMenu.js b/js/menus/NavViewMenu.js index 95787de6..f1a8b4eb 100644 --- a/js/menus/NavViewMenu.js +++ b/js/menus/NavViewMenu.js @@ -10,7 +10,7 @@ define(['jquery', 'underscore', 'backbone', 'plist', 'text!navViewMenuTemplate'] el: "#navViewMenu", events: { - "click a": "_makeSelection", + "click a.boolProperty": "_makeSelection", "click #reset3DView": "_reset3DNavigation" }, @@ -40,8 +40,9 @@ define(['jquery', 'underscore', 'backbone', 'plist', 'text!navViewMenuTemplate'] return null; }, - _reset3DNavigation: function(){ + _reset3DNavigation: function(e){ e.preventDefault(); + this.model.reset3DNavigation(); }, render: function(){ diff --git a/js/models/AppState.js b/js/models/AppState.js index d5cbe716..eca22a9e 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -158,6 +158,10 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'], fu }) }, + reset3DNavigation: function(){ + three.resetCameraPosition(); + }, + /////////////////////////////////////////////////////////////////////////////// /////////////////////KEY BINDINGS////////////////////////////////////////////// diff --git a/js/three/ThreeModel.js b/js/three/ThreeModel.js index 497e1b36..168b7d40 100644 --- a/js/three/ThreeModel.js +++ b/js/three/ThreeModel.js @@ -25,13 +25,15 @@ define(['underscore', 'three'], function(_, THREE){ var shouldRender = false; + var initialCameraPosition = new THREE.Vector3(-15, -12, 12); + + var threeView = null; + initialize(); function initialize(){ - camera.position.x = -15; - camera.position.y = -12; - camera.position.z = 12; + resetCameraPosition(); camera.up.set(0,0,1);//set z axis as "up" var fogColor = 0xcccccc; @@ -65,6 +67,14 @@ define(['underscore', 'three'], function(_, THREE){ window.addEventListener('resize', onWindowResize, false); } + function resetCameraPosition(){ + camera.position.x = initialCameraPosition.x; + camera.position.y = initialCameraPosition.y; + camera.position.z = initialCameraPosition.z; + if (threeView) threeView.reset3DNavigation(); + render(); + } + function onWindowResize(){ camera.aspect = window.innerWidth/window.innerHeight; camera.updateProjectionMatrix(); @@ -72,6 +82,10 @@ define(['underscore', 'three'], function(_, THREE){ render(); } + function setThreeView(view){ + threeView = view; + } + function sceneAdd(object){ scene.add(object); } @@ -187,7 +201,9 @@ define(['underscore', 'three'], function(_, THREE){ removeCompositeCell: removeCompositeCell, getBasePlane: getBasePlane, removeAllCells: removeAllCells, - removeAllCompositeCells: removeAllCompositeCells + removeAllCompositeCells: removeAllCompositeCells, + resetCameraPosition: resetCameraPosition, + setThreeView: setThreeView } }); \ No newline at end of file diff --git a/js/three/ThreeView.js b/js/three/ThreeView.js index 86b6285d..d06897b8 100644 --- a/js/three/ThreeView.js +++ b/js/three/ThreeView.js @@ -36,6 +36,8 @@ define(['underscore', 'backbone', 'three', 'appState', 'globals', 'lattice', 'or this.$el.append(this.model.domElement);//render only once + this.model.setThreeView(this); + this.model.render(); // this._animate(); }, @@ -54,6 +56,10 @@ define(['underscore', 'backbone', 'three', 'appState', 'globals', 'lattice', 'or this.controls.noRotate = state; }, + reset3DNavigation: function(){ + this.controls.reset(); + }, + //////////////////////////////////////////////////////////////////////////////// ///////////////////////////////MOUSE EVENTS///////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// -- GitLab