1 /**
  2  * potree.js 
  3  * http://potree.org
  4  *
  5  * Copyright 2012, Markus Sch�tz
  6  * Licensed under the GPL Version 2 or later.
  7  * - http://potree.org/wp/?page_id=7
  8  * - http://www.gnu.org/licenses/gpl-3.0.html
  9  *
 10  */
 11 
 12 /**
 13  * @class
 14  * @augments SceneNode
 15  * 
 16  */
 17 function Camera(name) {
 18 	SceneNode.call(this, name);
 19 	this._nearClipPlane = 0.1;
 20 	this._farClipPlane = 500.0;
 21 	this._fieldOfView = 60.0;
 22 	this._aspectRatio = 1;
 23 	this._viewMatrix = null;
 24 	this._projectionMatrix = null;
 25 	this.updateViewMatrix();
 26 	this.updateProjectionMatrix();
 27 }
 28 
 29 Camera.prototype = new SceneNode(inheriting);
 30 Camera.base = SceneNode.prototype;
 31 
 32 Object.defineProperties(Camera.prototype, {
 33 	"farClipPlane" : {
 34 		set: function(farClipPlane){
 35 			this._farClipPlane = farClipPlane;
 36 			this.updateProjectionMatrix();
 37 		},
 38 		get: function(){
 39 			return this._farClipPlane;
 40 		}
 41 	},
 42 	"nearClipPlane" : {
 43 		set: function(nearClipPlane){
 44 		this._nearClipPlane = nearClipPlane;
 45 		this.updateProjectionMatrix();
 46 	},
 47 	get: function(){
 48 		return this._nearClipPlane;
 49 	}
 50 	},
 51 	"transform": {
 52 		set: function(transform){
 53 			Object.getOwnPropertyDescriptor(Camera.base, 'transform').set.call(this, transform);
 54 			this.updateViewMatrix();
 55 		},
 56 		get: function(){
 57 			return this._transform;
 58 		}
 59 	},
 60 	"frustum": {
 61 		get: function(){
 62 			return Frustum.fromCamera(this);
 63 		}
 64 	},
 65 	"projectionMatrix": {
 66 		get: function(){
 67 			return this._projectionMatrix;
 68 		}
 69 	},
 70 	"viewMatrix": {
 71 		get: function(){
 72 			return this._viewMatrix;
 73 		},
 74 		set: function(viewMatrix){
 75 			this._viewMatrix = viewMatrix;
 76 		}
 77 	},
 78 	"fieldOfView": {
 79 		set: function(fieldOfView){
 80 			this._fieldOfView = fieldOfView;
 81 			this.updateProjectionMatrix();
 82 		},
 83 		get: function(){
 84 			return this._fieldOfView;
 85 		}
 86 	},
 87 	"aspectRatio": {
 88 		set: function(aspectRatio){
 89 			this._aspectRatio = aspectRatio;
 90 			this.updateProjectionMatrix();
 91 		},
 92 		get: function(){
 93 			return this._aspectRatio;
 94 		}
 95 	}
 96 });
 97 
 98 Camera.prototype.updateProjectionMatrix = function(){
 99 	this._projectionMatrix = M4x4.makePerspective(this.fieldOfView, this.aspectRatio,
100 			this.nearClipPlane, this.farClipPlane);
101 };
102 
103 /**
104  * calculates the current view matrix and stores it in _viewMatrix. use .viewMatrix if you want to get the matrix.
105  */
106 Camera.prototype.updateViewMatrix = function(){
107 	this.viewMatrix = this.getInverseGlobalTransformation();
108 };
109 
110 Camera.prototype.translate = function(x, y, z){
111 	Camera.base.translate.call(this, x, y, z);
112 	this.updateViewMatrix();
113 };
114 
115 
116 
117 
118