/** * Raw Camera API object - should always correspond with the Camera Schema * @param id * @param name * @param cameraType GameLib.D3.Camera.CAMERA_TYPE_* * @param fov * @param aspect * @param near * @param far * @param position GameLib.API.Vector3 * @param lookAt GameLib.API.Vector3 * @param minX * @param maxX * @param minY * @param maxY * @param minZ * @param maxZ * @param quaternion GameLib.Quaternion * @param parentEntity * @constructor */ GameLib.D3.API.Camera = function( id, cameraType, name, fov, aspect, near, far, position, lookAt, minX, maxX, minY, maxY, minZ, maxZ, quaternion, parentEntity ) { GameLib.Component.call( this, GameLib.Component.COMPONENT_CAMERA, null, null, parentEntity ); if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); } this.id = id; if (GameLib.Utils.UndefinedOrNull(cameraType)) { cameraType = GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE; } this.cameraType = cameraType; if (GameLib.Utils.UndefinedOrNull(name)) { name = 'Camera (' + cameraType + ')'; } this.name = name; if (GameLib.Utils.UndefinedOrNull(fov)) { fov = 75; } this.fov = fov; if (GameLib.Utils.UndefinedOrNull(aspect)) { aspect = window.innerWidth / window.innerHeight; } this.aspect = aspect; if (GameLib.Utils.UndefinedOrNull(near)) { near = 0.001; } this.near = near; if (GameLib.Utils.UndefinedOrNull(far)) { far = 1000; } this.far = far; if (GameLib.Utils.UndefinedOrNull(position)) { position = new GameLib.API.Vector3( 15, 15, 15 ); } this.position = position; if (GameLib.Utils.UndefinedOrNull(quaternion)) { quaternion = new GameLib.API.Quaternion(); } this.quaternion = quaternion; if (GameLib.Utils.UndefinedOrNull(lookAt)) { lookAt = new GameLib.API.Vector3( 0, 0, 0 ); } this.lookAt = lookAt; if (GameLib.Utils.UndefinedOrNull(minX)) { minX = -100; } this.minX = minX; if (GameLib.Utils.UndefinedOrNull(maxX)) { maxX = 100; } this.maxX = maxX; if (GameLib.Utils.UndefinedOrNull(minY)) { minY = -100; } this.minY = minY; if (GameLib.Utils.UndefinedOrNull(maxY)) { maxY = 100; } this.maxY = maxY; if (GameLib.Utils.UndefinedOrNull(minZ)) { minZ = -100; } this.minZ = minZ; if (GameLib.Utils.UndefinedOrNull(maxZ)) { maxZ = 100; } this.maxZ = maxZ; }; GameLib.D3.API.Camera.prototype = Object.create(GameLib.Component.prototype); GameLib.D3.API.Camera.prototype.constructor = GameLib.D3.API.Camera; /** * Creates an API camera from an Object camera * @param objectCamera * @constructor */ GameLib.D3.API.Camera.FromObjectCamera = function(objectCamera) { return new GameLib.D3.API.Camera( objectCamera.id, objectCamera.cameraType, objectCamera.name, objectCamera.fov, objectCamera.aspect, objectCamera.near, objectCamera.far, GameLib.API.Vector3.FromObjectVector(objectCamera.position), GameLib.API.Vector3.FromObjectVector(objectCamera.lookAt), objectCamera.minX, objectCamera.maxX, objectCamera.minY, objectCamera.maxY, objectCamera.minZ, objectCamera.maxZ, GameLib.API.Quaternion.FromObjectQuaternion(objectCamera.quaternion), objectCamera.parentEntity ); };