From 7f2f119c8d3ff1d91b6ae649d30b877f3fcba81f Mon Sep 17 00:00:00 2001
From: amandaghassaei <amandaghassaei@gmail.com>
Date: Wed, 24 May 2017 19:33:09 -0400
Subject: [PATCH] camera controls

---
 dependencies/TrackballControls.js |  7 +++++--
 index.html                        |  7 +++++++
 js/controls.js                    | 13 +++++++++++++
 js/threeView.js                   | 26 +++++++++++++++++++++++++-
 4 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/dependencies/TrackballControls.js b/dependencies/TrackballControls.js
index 2654f4e..c61ddd3 100755
--- a/dependencies/TrackballControls.js
+++ b/dependencies/TrackballControls.js
@@ -211,6 +211,7 @@ THREE.TrackballControls = function ( object, domElement ) {
 			_touchZoomDistanceStart = _touchZoomDistanceEnd;
 			_eye.multiplyScalar( factor );
 
+
 		} else {
 
 			factor = 1.0 + ( _zoomEnd.y - _zoomStart.y ) * _this.zoomSpeed;
@@ -331,13 +332,15 @@ THREE.TrackballControls = function ( object, domElement ) {
 
 	};
 
-	this.reset = function () {
+	this.reset = function (position) {
 
 		_state = STATE.NONE;
 		_prevState = STATE.NONE;
 
 		_this.target.copy( _this.target0 );
-		_this.object.position.copy( _this.position0 );
+		if (position === undefined) position = _this.position0;
+		else position.normalize().multiplyScalar(_this.object.position.length());
+		_this.object.position.copy( position );
 		_this.object.up.copy( _this.up0 );
 
 		_eye.subVectors( _this.object.position, _this.target );
diff --git a/index.html b/index.html
index 78bf3c5..7e282f8 100755
--- a/index.html
+++ b/index.html
@@ -619,6 +619,13 @@
                 <div id="VRoptions">
 
                 </div>
+            </div><br/>
+            View Angle:<br/>
+            <div class="indent">
+                <a href="#" id="cameraX" class="btn btn-lg btn-default">X</a>
+                <a href="#" id="cameraY" class="btn btn-lg btn-default">Y</a>
+                <a href="#" id="cameraZ" class="btn btn-lg btn-default">Z</a>
+                <a href="#" id="cameraOrtho" class="btn btn-lg btn-default">Ortho</a>
             </div>
         </div>
     </div>
diff --git a/js/controls.js b/js/controls.js
index 9951e5d..db1310a 100755
--- a/js/controls.js
+++ b/js/controls.js
@@ -24,6 +24,19 @@ function initControls(globals){
         $('#aboutAnimationModal').modal('show');
     });
 
+    setLink("#cameraX", function(){
+        globals.threeView.setCameraX();
+    });
+    setLink("#cameraY", function(){
+        globals.threeView.setCameraY();
+    });
+    setLink("#cameraZ", function(){
+        globals.threeView.setCameraZ();
+    });
+    setLink("#cameraOrtho", function(){
+        globals.threeView.setCameraOrtho();
+    });
+
     setLink("#exportFOLD", function(){
         updateDimensions();
         $("#foldFilename").val(globals.filename + " : " + parseInt(globals.creasePercent*100) +  "PercentFolded");
diff --git a/js/threeView.js b/js/threeView.js
index cbb0df9..bab85bf 100755
--- a/js/threeView.js
+++ b/js/threeView.js
@@ -95,6 +95,26 @@ function initThreeView(globals) {
         // effectComposer.addPass( ssaoPass );
     }
 
+    function setCameraX(){
+        controls.reset(new THREE.Vector3(1,0,0));
+        manuallySetCamera();
+    }
+    function setCameraY(){
+        controls.reset(new THREE.Vector3(0,1,0));
+        manuallySetCamera();
+    }
+    function setCameraZ(){
+        controls.reset(new THREE.Vector3(0,0,1));
+        manuallySetCamera();
+    }
+    function setCameraOrtho(){
+        controls.reset(new THREE.Vector3(1,1,1));
+        manuallySetCamera();
+    }
+    function manuallySetCamera(){
+        render();
+    }
+
     function render() {
         if (!animationRunning) {
             console.log("render");
@@ -249,6 +269,10 @@ function initThreeView(globals) {
         modelWrapper:modelWrapper,
         running: running,
         setScale:setScale,
-        saveSVG: saveSVG
+        saveSVG: saveSVG,
+        setCameraX:setCameraX,
+        setCameraY: setCameraY,
+        setCameraZ: setCameraZ,
+        setCameraOrtho: setCameraOrtho
     }
 }
\ No newline at end of file
-- 
GitLab