1 /***************************************
  2  * Copyright 2011, 2012 GlobWeb contributors.
  3  *
  4  * This file is part of GlobWeb.
  5  *
  6  * GlobWeb is free software: you can redistribute it and/or modify
  7  * it under the terms of the GNU Lesser General Public License as published by
  8  * the Free Software Foundation, version 3 of the License, or
  9  * (at your option) any later version.
 10  *
 11  * GlobWeb is distributed in the hope that it will be useful,
 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14  * GNU Lesser General Public License for more details.
 15  *
 16  * You should have received a copy of the GNU General Public License
 17  * along with GlobWeb. If not, see <http://www.gnu.org/licenses/>.
 18  ***************************************/
 19 
 20 define( ['./MouseNavigationHandler', './KeyboardNavigationHandler', './InertiaAnimation' ], function(MouseNavigationHandler,KeyboardNavigationHandler,InertiaAnimation) {
 21 
 22 /**************************************************************************************************************/
 23 
 24 /** @name BaseNavigation
 25 	@constructor
 26 	Base class for navigation object
 27 
 28 	@param globe Globe
 29 	@param options Configuration options
 30 		<ul>
 31 			<li>handlers : Array of objects defining navigation events for different supports(mouse, keyboard..)</li>
 32 			<li>inertia : Boolean for inertia effect</li>
 33 			<li>panFactor : Pan factor</li>
 34 			<li>rotateFactor : Rotate factor</li>
 35 			<li>zoomFactor : Zoom factor</li>
 36 		</ul>
 37 
 38  */
 39 var BaseNavigation = function(globe, options)
 40 {
 41 	this.globe = globe;
 42 
 43 	// Copy options
 44 	for (var x in options)
 45 	{
 46 		this[x] = options[x];
 47 	}
 48 	
 49 	// Create default handlers if none are created in options
 50 	if ( !this.handlers ) 
 51 	{
 52 		this.handlers = [new MouseNavigationHandler({ zoomOnDblClick : true }), new KeyboardNavigationHandler()];
 53 	}
 54 	
 55 	// Inertia effect
 56 	if( options && options.inertia )
 57 	{
 58 		this.inertia = new InertiaAnimation(this, options);
 59 	}
 60 	// ZoomTo animation
 61 	this.zoomToAnimation = null;
 62 
 63 	// Automatically start
 64 	this.start();
 65 }
 66 
 67 /**************************************************************************************************************/
 68 
 69 /** @export
 70 	Start the navigation
 71 */
 72 BaseNavigation.prototype.start = function()
 73 {
 74 	// Install handlers
 75 	for (var i=0; i<this.handlers.length; i++)
 76 	{
 77 		this.handlers[i].install(this);
 78 	}
 79 }
 80 
 81 /**************************************************************************************************************/
 82 
 83 /** @export
 84 	Stop the navigation
 85 */
 86 BaseNavigation.prototype.stop = function()
 87 {
 88 	// Uninstall handlers
 89 	for (var i=0; i<this.handlers.length; i++)
 90 	{
 91 		this.handlers[i].uninstall();
 92 	}
 93 }
 94 
 95 /**************************************************************************************************************/
 96 
 97 /** @export
 98 	Stop the animations running on the navigation
 99 */
100 BaseNavigation.prototype.stopAnimations = function()
101 {
102 	if ( this.inertia )
103 	{
104 		this.inertia.stop();
105 	}
106 	if( this.zoomToAnimation )
107 	{
108 		this.zoomToAnimation.stop();
109 		this.zoomToAnimation = null;
110 	}
111 }
112 
113 /**************************************************************************************************************/
114 
115 /** @export
116 	Get the field of view used by the navigation
117 	
118 	@return {Float[]} Fovx and fovy in degrees
119 */
120 BaseNavigation.prototype.getFov = function()
121 {
122 	var aspect = this.globe.renderContext.canvas.width / this.globe.renderContext.canvas.height;
123 	return [ aspect * this.globe.renderContext.fov, this.globe.renderContext.fov ];
124 }
125 
126 /**************************************************************************************************************/
127 
128 return BaseNavigation;
129 
130 });
131