/** * GameLib.D3.Camera.Stereo * @param graphics GameLib.GraphicsRuntime * @param apiStereoCamera * @constructor */ GameLib.D3.Camera.Stereo = function( graphics, apiStereoCamera ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); if (GameLib.Utils.UndefinedOrNull(apiStereoCamera)) { apiStereoCamera = { cameraType : GameLib.D3.API.Camera.CAMERA_TYPE_STEREO }; } GameLib.D3.API.Camera.Stereo.call( this, apiStereoCamera, apiStereoCamera.eyeSep, apiStereoCamera.cameraL, apiStereoCamera.cameraR ); if (this.cameraL instanceof GameLib.D3.API.Camera.Perspective) { this.cameraL = new GameLib.D3.Camera.Perspective( this.graphics, this.cameraL ); } if (this.cameraR instanceof GameLib.D3.API.Camera.Perspective) { this.cameraR = new GameLib.D3.Camera.Perspective( this.graphics, this.cameraR ); } // // this.eyeSep = new GameLib.Number( // this.eyeSep, // this // ); GameLib.D3.Camera.call( this, this.graphics, apiStereoCamera ); }; GameLib.D3.Camera.Stereo.prototype = Object.create(GameLib.D3.Camera.prototype); GameLib.D3.Camera.Stereo.prototype.constructor = GameLib.D3.Camera.Stereo; /** * Creates a camera instance * @returns {*} */ GameLib.D3.Camera.Stereo.prototype.createInstance = function() { this.instance = new THREE.StereoCamera(); this.instance.aspect = this.aspect; this.instance.eyeSep = this.eyeSep; GameLib.D3.Camera.prototype.createInstance.call(this); }; /** * Updates the instance with the current state */ GameLib.D3.Camera.Stereo.prototype.updateInstance = function(property) { if (property === 'eyeSep') { this.instance.eyeSep = this.eyeSep; return; } if (property === 'aspect') { this.instance.aspect = this.aspect; return; } if (property === 'cameraL') { console.warn('update stereo camera cameraL instance'); return; } if (property === 'cameraR') { console.warn('update stereo camera cameraR instance'); return; } GameLib.D3.Camera.prototype.updateInstance.call(this, property); }; /** * Converts a GameLib.D3.Camera to a GameLib.D3.API.Camera * @returns {GameLib.D3.API.Camera} */ GameLib.D3.Camera.Stereo.prototype.toApiObject = function() { var apiCamera = GameLib.D3.Camera.prototype.toApiObject.call(this); var apiStereoCamera = new GameLib.D3.API.Camera.Stereo( apiCamera, this.eyeSep, GameLib.Utils.IdOrNull(this.cameraL), GameLib.Utils.IdOrNull(this.cameraR) ); return apiStereoCamera; }; GameLib.D3.Camera.Stereo.prototype.updateFromInstance = function() { this.eyeSep = this.instance.eyeSep; this.cameraL.instance = this.instance.cameraL; this.cameraL.updateFromInstance(); this.cameraR.instance = this.instance.cameraR; this.cameraR.updateFromInstance(); GameLib.D3.Camera.prototype.updateFromInstance.call(this); };