text: /*
  GLGE WebGL Graphics Engine
  Copyright (c) 2010, Paul Brunt
  All rights reserved.
  
  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are met:
      * Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.
      * Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.
      * Neither the name of GLGE nor the
        names of its contributors may be used to endorse or promote products
        derived from this software without specific prior written permission.
  
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  DISCLAIMED. IN NO EVENT SHALL PAUL BRUNT BE LIABLE FOR ANY
  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
  
  /**
   * @fileOverview
   * @name glge_camera.js
   * @author me@paulbrunt.co.uk
   */
  
  
  (function(GLGE){
  
  
  
  /**
  * @constant 
  * @description Enumeration for a perspective camera
  */
  GLGE.C_PERSPECTIVE=1;
  /**
  * @constant 
  * @description Enumeration for a orthographic camera
  */
  GLGE.C_ORTHO=2;
  
  /**
  * @class Creates a new camera object
  * @augments GLGE.Animatable
  * @augments GLGE.Placeable
  * @augments GLGE.QuickNotation
  * @augments GLGE.JSONLoader
  */
  GLGE.Camera=function(uid){
  	GLGE.Assets.registerAsset(this,uid);
  };
  GLGE.augment(GLGE.Placeable,GLGE.Camera);
  GLGE.augment(GLGE.Animatable,GLGE.Camera);
  GLGE.augment(GLGE.QuickNotation,GLGE.Camera);
  GLGE.augment(GLGE.JSONLoader,GLGE.Camera);
  GLGE.Camera.prototype.className="Camera";
  GLGE.Camera.prototype.fovy=35;
  GLGE.Camera.prototype.aspect=1.0;
  GLGE.Camera.prototype.near=0.1;
  GLGE.Camera.prototype.far=1000.0;
  GLGE.Camera.prototype.orthoscale=5;
  GLGE.Camera.prototype.type=GLGE.C_PERSPECTIVE;
  GLGE.Camera.prototype.pMatrix=null;
  
  
  /**
  * Method gets the orthographic scale for the camers
  * @return {Matrix} Returns the orthographic scale
  */
  GLGE.Camera.prototype.getOrthoScale=function(){
  	if(this.type==GLGE.C_ORTHO) {
  		return this.orthoscale
  	}else{
  		GLGE.error("You may only get a scale for a orthographic camera");
  		return 1;
  	}
  };
  /**
  * Method sets the orthographic scale for the camers
  * @param {number} scale The new orthographic scale
  */
  GLGE.Camera.prototype.setOrthoScale=function(scale){
  	if(this.type==GLGE.C_ORTHO) {
  		this.orthoscale=scale;
  		this.pMatrix=null;
  	}
  	else
  	{
  		GLGE.error("You may only set a scale for a orthographic camera");
  	}
  	return this;
  };
  
  /**
  * Method gets the far drawing distance
  * @return {Matrix} Returns the cameras far draw distance
  */
  GLGE.Camera.prototype.getFar=function(){
  	return this.far;
  };
  /**
  * Method sets the far draw distance of the camera
  * @param {number} distance The far draw distance
  */
  GLGE.Camera.prototype.setFar=function(distance){
  	this.pMatrix=null;
  	this.far=+distance;
  	return this;
  };
  
  /**
  * Method gets the near drawing distance
  * @return {Matrix} Returns the cameras near draw distance
  */
  GLGE.Camera.prototype.getNear=function(){
  	return this.near;
  };
  /**
  * Method sets the near draw distance of the camera
  * @param {number} distance The near draw distance
  */
  GLGE.Camera.prototype.setNear=function(distance){
  	this.pMatrix=null;
  	this.near=+distance;
  	return this;
  };
  
  /**
  * Method gets the current camera type
  * @return {Matrix} Returns the camera type
  */
  GLGE.Camera.prototype.getType=function(){
  	this.pMatrix=null;
  	return this.type
  };
  /**
  * Method sets the type of camera GLGE.C_PERSPECTIVE or GLGE.C_ORTHO
  * @param {number} type The type of this camera
  */
  GLGE.Camera.prototype.setType=function(type){
  	if(type==GLGE.C_PERSPECTIVE || type==GLGE.C_ORTHO){
  		this.type=type;
  		this.pMatrix=null;
  	}else{
  		GLGE.error("unsuported camera type");
  	}
  	return this;
  };
  
  /**
  * Method gets the current yfov if the camera type is GLGE.C_PERSPECTIVE
  * @return {Matrix} Returns the yfov
  */
  GLGE.Camera.prototype.getFovY=function(){
  	if(this.type==GLGE.C_PERSPECTIVE) {
  		return this.fovy
  	}else{
  		GLGE.error("You may only get a yfov for a perspective camera");
  		return 1;
  	}
  };
  /**
  * Method sets the yfov of the camera
  * @param {number} yfov The new yfov of the camera
  */
  GLGE.Camera.prototype.setFovY=function(fovy){
  	if(this.type==GLGE.C_PERSPECTIVE) {
  		this.fovy=+fovy;
  		this.ymax=null;
  		this.pMatrix=null;
  	}
  	else
  	{
  		GLGE.error("You may only set a yfov for a perspective camera");
  	}
  	return this;
  };
  
  /**
  * Method gets the current aspect if the camera type is GLGE.C_PERSPECTIVE
  * @return {Matrix} Returns the yfov
  */
  GLGE.Camera.prototype.getAspect=function(){
  	if(this.type==GLGE.C_PERSPECTIVE || this.type==GLGE.C_ORTHO) {
  		return this.aspect
  	}
  	else
  	{
  		GLGE.error("You may only set a aspect for a perspective or orthographic camera");
  		return 1;
  	}
  };
  /**
  * Method sets the aspect of the camera
  * @param {number} aspect The new projection matrix
  */
  GLGE.Camera.prototype.setAspect=function(aspect){
  	if(this.type==GLGE.C_PERSPECTIVE || this.type==GLGE.C_ORTHO) {
  		this.aspect=+aspect;
  		this.pMatrix=null;
  	}
  	else
  	{
  		GLGE.error("You may only set a aspect for a perspective or orthographic camera");
  	}
  	return this;
  };
  
  
  /**
  * Method gets the current projection matrix of this camera
  * @return {Matrix} Returns the camera projection matrix
  */
  GLGE.Camera.prototype.getProjectionMatrix=function(){
  	if(!this.pMatrix){
  		if(this.pMatrixOveride){
  			this.pMatrix=this.pMatrixOveride;
  		}else{
  			switch(this.type){
  				case GLGE.C_PERSPECTIVE:
  					this.pMatrix=GLGE.makePerspective(this.fovy, this.aspect, this.near, this.far);
  					break;
  				case GLGE.C_ORTHO:
  					this.pMatrix=GLGE.makeOrtho(-this.orthoscale*this.aspect,this.orthoscale*this.aspect,-this.orthoscale,this.orthoscale, this.near, this.far);
  					break;
  			}
  		}
  	}
  	return this.pMatrix;
  };
  /**
  * Method generates the projection matrix based on the 
  * camera paramaters
  * @param {Matrix} projection The new projection matrix
  */
  GLGE.Camera.prototype.setProjectionMatrix=function(projection){
  	this.pMatrix=projection;
  	return this;
  };
  /**
  * Method sets a custom projection matrix
  * @param {Matrix} projection The new projection matrix
  */
  GLGE.Camera.prototype.setCustomProjectionMatrix=function(projection){
  	this.pMatrix=projection;
  	this.pMatrixOveride=projection;
  	return this;
  };
  /**
  * Method generates the cameras view matrix
  * @return Returns the view matrix based on this camera
  * @type Matrix
  */
  GLGE.Camera.prototype.updateMatrix=function(){
  	var position=this.getPosition();
  	var vMatrix=GLGE.translateMatrix(position.x,position.y,position.z);
  	vMatrix=GLGE.mulMat4(vMatrix,this.getRotMatrix());
  	if(this.parent) vMatrix=GLGE.mulMat4(this.parent.getModelMatrix(),vMatrix);
  	this.location=[vMatrix[3],vMatrix[7],vMatrix[11]];
  	this.matrix=GLGE.inverseMat4(vMatrix);
  };
  /**
  * Method generates the cameras view matrix
  * @return Returns the view matrix based on this camera
  * @type Matrix
  */
  GLGE.Camera.prototype.getViewMatrix=function(){
  	if(!this.matrix || !this.rotmatrix) this.updateMatrix();
  	return this.matrix;
  };
  
  /**
  * Method generates the cameras view projection matrix
  * @return Returns the view projection  matrix based on this camera
  * @type Matrix
  */
  GLGE.Camera.prototype.getViewProjection=function(){
  	var projectionMatrix=this.getProjectionMatrix();
  	var viewMatrix=this.getViewMatrix();
  	if(projectionMatrix!=this.vpProjectionMatrix || viewMatrix!=this.vpViewMatrix){
  		this.cameraViewProjection=GLGE.mulMat4(projectionMatrix,viewMatrix);
  		this.vpProjectionMatrix=projectionMatrix;
  		this.vpViewMatrix=viewMatrix;
  	}
  	return this.cameraViewProjection;
  };
  
  
  
  })(GLGE);