154 lines
3.8 KiB
JavaScript
154 lines
3.8 KiB
JavaScript
/**
|
|
* 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.stereoMode,
|
|
apiStereoCamera.main,
|
|
apiStereoCamera.cameraL,
|
|
apiStereoCamera.cameraR
|
|
);
|
|
|
|
if (this.main instanceof GameLib.D3.API.Camera.Perspective) {
|
|
this.main = new GameLib.D3.Camera.Perspective(
|
|
this.graphics,
|
|
this.main
|
|
);
|
|
}
|
|
|
|
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
|
|
);
|
|
}
|
|
|
|
GameLib.D3.Camera.call(
|
|
this,
|
|
this.graphics,
|
|
this
|
|
);
|
|
|
|
};
|
|
|
|
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 = this.main.instance;
|
|
|
|
var instance = new THREE.StereoCamera();
|
|
|
|
for (var property in instance) {
|
|
this.instance[property] = instance[property];
|
|
}
|
|
//
|
|
//
|
|
// Object.keys(instance).map(
|
|
// function(property) {
|
|
// this.instance[property] = instance[property];
|
|
// }.bind(this)
|
|
// );
|
|
|
|
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 === 'stereoMode') {
|
|
console.warn('experimental update stereo mode');
|
|
return;
|
|
}
|
|
|
|
if (property === 'main') {
|
|
console.warn('experimental update stereo camera main instance');
|
|
return;
|
|
}
|
|
|
|
if (property === 'cameraL') {
|
|
console.warn('experimental update stereo camera cameraL instance');
|
|
return;
|
|
}
|
|
|
|
if (property === 'cameraR') {
|
|
console.warn('experimental 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,
|
|
this.stereoMode,
|
|
GameLib.Utils.IdOrNull(this.main),
|
|
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);
|
|
}; |