1 tQuery.MD2Character.registerStatic('CameraControls', function(opts){ 2 // handle parameters polymorphism 3 if( opts instanceof tQuery.MD2Character ){ 4 opts = { character : opts }; 5 } 6 // handle parameters 7 this._opts = tQuery.extend(opts, { 8 camera : tQuery.world.tCamera(), 9 deltaPosition : new THREE.Vector3(5,2,5).normalize().multiplyScalar(3), 10 deltaLookAt : new THREE.Vector3(0,0.3,0) 11 }); 12 // sanity check 13 console.assert(this._opts.character instanceof tQuery.MD2Character); 14 }); 15 16 tQuery.MD2Character.CameraControls.prototype.update = function() 17 { 18 var opts = this._opts; 19 var container = opts.character.container(); 20 var camera = opts.camera; 21 // if the character isnt yet loaded, do nothing 22 if( opts.character.isLoaded() === false ) return; 23 // camera position 24 camera.position.copy(container.position); 25 camera.position.addSelf(opts.deltaPosition); 26 // camera lookAt 27 camera.lookAt( container.position.clone().addSelf(opts.deltaLookAt) ); 28 } 29