1 //////////////////////////////////////////////////////////////////////////////////
  2 //										//
  3 //////////////////////////////////////////////////////////////////////////////////
  4 
  5 tQuery.registerStatic('createCameraFpsControls', function(opts){
  6 	return new tQuery.CameraFpsControls(opts)
  7 });
  8 
  9 //////////////////////////////////////////////////////////////////////////////////
 10 //										//
 11 //////////////////////////////////////////////////////////////////////////////////
 12 
 13 tQuery.registerStatic('CameraFpsControls', function(opts){
 14 	// handle default values
 15 	opts		= this._opts	= tQuery.extend(opts, {
 16 		world		: tQuery.world,
 17 		deltaTarget	: tQuery.createVector3(0, 0, +3),
 18 		deltaCamera	: tQuery.createVector3(0, 2, -3),
 19 		debug		: false 
 20 	});
 21 	// sanity check
 22 	console.assert( opts.trackedObject instanceof THREE.Object3D )
 23 	console.assert( opts.tCamera instanceof THREE.Camera )
 24 
 25 	// create target object
 26 	var deltaTarget	= !opts.debug ? tQuery.createObject3D() : tQuery.createSphere()
 27 					.setBasicMaterial().wireframe(true).back()	
 28 					.geometry().scaleBy(1/4).back()
 29 	this._deltaTarget	= deltaTarget;
 30 	deltaTarget.addTo(opts.trackedObject)
 31 		.position(opts.deltaTarget);
 32 
 33 	// create camera
 34 	var deltaCamera	= !opts.debug ? tQuery.createObject3D() : tQuery.createSphere()
 35 					.setBasicMaterial().wireframe(true).back()	
 36 					.geometry().scaleBy(1/4).back()
 37 	this._deltaCamera	= deltaCamera;
 38 	deltaCamera.addTo(opts.trackedObject)
 39 		.position(opts.deltaCamera);
 40 		// .position(0, 2, -3)
 41 		//.position(0, 1, 0)
 42 		//.position(0, 0.7, -0.07)
 43 
 44 	// add the camera
 45 	tQuery(opts.tCamera).position(0,0,0).addTo(deltaCamera);
 46 });
 47 
 48 tQuery.CameraFpsControls.prototype.update	= function(delta, now){
 49 	var delta	= this._deltaTarget.get(0).position.clone()
 50 	delta.subSelf(this._deltaCamera.get(0).position);
 51 	this._opts.tCamera.lookAt(delta);
 52 }
 53 
 54 tQuery.CameraFpsControls.prototype.deltaTarget	= function(){
 55 	return this._deltaTarget
 56 }
 57 
 58 tQuery.CameraFpsControls.prototype.deltaCamera	= function(){
 59 	return this._deltaCamera
 60 }
 61 
 62