Skip to content

Commit

Permalink
removed options.startposition and startlook, start view with Y instea…
Browse files Browse the repository at this point in the history
…d of S (used for picking)
  • Loading branch information
EmmanuelSchmuck committed Aug 28, 2017
1 parent 1a61694 commit d7ae5da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion examples/planar.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
<li>Ctrl + Left-Click: camera rotation (orbit)</li>
<li>Spacebar / Wheel-Click: smart zoom</li>
<li>Mouse Wheel: zoom in/out</li>
<li>S: move camera to start position</li>
<li>T: orient camera to a top view</li>
<li>Y: move camera to start position</li>
</ul>
</div>
<div id="viewerDiv"></div>
Expand Down
27 changes: 11 additions & 16 deletions src/Renderer/ThreeExtended/PlanarControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
* Ctrl + left mouse : rotate (orbit) around the camera's focus point.
* Scroll wheel : zooms toward cursor position (animated).
* Middle mouse button (wheel click) : 'smart zoom' at cursor location (animated).
* S : go to start view (animated)
* Y : go to start view (animated)
* T : go to top view (animated)
* How to use : instanciate PlanarControls after camera setup (setPosition and lookAt)
* or you can also setup the camera with options.startPosition and options.startLook
*/

import * as THREE from 'three';
Expand All @@ -16,8 +15,8 @@ import * as THREE from 'three';
const keys = {
CTRL: 17,
SPACE: 32,
S: 83,
T: 84,
Y: 89,
};

const mouseButtons = {
Expand Down Expand Up @@ -85,6 +84,12 @@ function PlanarControls(view, options = {}) {
// should be less than 90 deg (90 = parallel to the ground)
this.maxZenithAngle = (options.maxZenithAngle || 82.5) * Math.PI / 180;

// starting camera position and orientation target are setup before instanciating PlanarControls
// using: view.camera.setPosition() and view.camera.lookAt()
// startPosition and startQuaternion are stored to be able to return to the start view
this.startPosition = this.camera.position.clone();
this.startQuaternion = this.camera.quaternion.clone();

// prevent the default contextmenu from appearing when right-clicking
// this allows to use right-click for input without the menu appearing
this.domElement.addEventListener('contextmenu', onContextMenu.bind(this), false);
Expand Down Expand Up @@ -490,7 +495,7 @@ function PlanarControls(view, options = {}) {
* Triggers an animated movement (travel) to set the camera to starting view
*/
this.goToStartView = function goToStartView() {
this.initiateTravel(this.startPosition, 'auto', this.startLook, true);
this.initiateTravel(this.startPosition, 'auto', this.startQuaternion, true);
};

/**
Expand Down Expand Up @@ -585,14 +590,6 @@ function PlanarControls(view, options = {}) {
PlanarControls.prototype = Object.create(THREE.EventDispatcher.prototype);
PlanarControls.prototype.constructor = PlanarControls;

// starting position and lookAt target can be set outside this class, before instanciating PlanarControls
// or they can be set with options : startPosition and startLookAt
this.startPosition = options.startPosition || this.camera.position.clone();
this.startLook = options.startLook || this.camera.quaternion.clone();

this.camera.position.copy(this.startPosition);
this.camera.quaternion.copy(this.startLook);

// event listeners for user input
this.addInputListeners();
}
Expand Down Expand Up @@ -628,8 +625,7 @@ var onMouseDown = function onMouseDown(event) {
};

/**
* Catch the event when a touch on the mouse is uped. Reinit the state of the controller and disable.
* the listener on the move mouse event.
* Catch the event when a touch on the mouse is uped.
* @param {event} event : the current event
*/
var onMouseUp = function onMouseUp(event) {
Expand Down Expand Up @@ -693,7 +689,7 @@ var onKeyDown = function onKeyDown(event) {
if (event.keyCode === keys.T) {
this.goToTopView();
}
if (event.keyCode === keys.S) {
if (event.keyCode === keys.Y) {
this.goToStartView();
}
if (event.keyCode === keys.SPACE) {
Expand Down Expand Up @@ -726,7 +722,6 @@ var onContextMenu = function onContextMenu(event) {
event.preventDefault();
};


/**
* smoothing function (sigmoid) : based on h01 Hermite function
* returns a value between 0 and 1
Expand Down

0 comments on commit d7ae5da

Please sign in to comment.