199 lines
4.3 KiB
JavaScript
199 lines
4.3 KiB
JavaScript
/**
|
|
* 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 offsetX
|
|
* @param offsetY
|
|
* @param quaternion GameLib.Quaternion
|
|
* @param parentEntity
|
|
* @param eyeSeparation
|
|
* @param focalLength
|
|
* @constructor
|
|
*/
|
|
GameLib.D3.API.Camera = function(
|
|
id,
|
|
cameraType,
|
|
name,
|
|
fov,
|
|
aspect,
|
|
near,
|
|
far,
|
|
position,
|
|
lookAt,
|
|
minX,
|
|
maxX,
|
|
minY,
|
|
maxY,
|
|
minZ,
|
|
maxZ,
|
|
offsetX,
|
|
offsetY,
|
|
quaternion,
|
|
parentEntity,
|
|
eyeSeparation,
|
|
focalLength
|
|
) {
|
|
|
|
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 (' + this.id + ')';
|
|
}
|
|
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.01;
|
|
}
|
|
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;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(offsetX)) {
|
|
offsetX = 0;
|
|
}
|
|
this.offsetX = offsetX;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(offsetY)) {
|
|
offsetY = 0;
|
|
}
|
|
this.offsetY = offsetY;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(eyeSeparation)) {
|
|
eyeSeparation = 30;
|
|
}
|
|
this.eyeSeparation = eyeSeparation;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(focalLength)) {
|
|
focalLength = 150;
|
|
}
|
|
this.focalLength = focalLength;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
|
parentEntity = null;
|
|
}
|
|
this.parentEntity = parentEntity;
|
|
};
|
|
|
|
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.FromObject = 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.FromObject(objectCamera.position),
|
|
GameLib.API.Vector3.FromObject(objectCamera.lookAt),
|
|
objectCamera.minX,
|
|
objectCamera.maxX,
|
|
objectCamera.minY,
|
|
objectCamera.maxY,
|
|
objectCamera.minZ,
|
|
objectCamera.maxZ,
|
|
objectCamera.offsetX,
|
|
objectCamera.offsetY,
|
|
GameLib.API.Quaternion.FromObject(objectCamera.quaternion),
|
|
objectCamera.parentEntity,
|
|
objectCamera.eyeSeparation,
|
|
objectCamera.focalLength
|
|
);
|
|
|
|
};
|