r3-legacy/src/game-lib-d3-api-camera.js

184 lines
4.0 KiB
JavaScript
Raw Normal View History

2016-11-29 12:54:25 +01:00
/**
* 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
2016-12-15 14:53:39 +01:00
* @param position GameLib.API.Vector3
* @param lookAt GameLib.API.Vector3
2016-11-29 12:54:25 +01:00
* @param minX
* @param maxX
* @param minY
* @param maxY
* @param minZ
* @param maxZ
2016-12-15 14:53:39 +01:00
* @param quaternion GameLib.Quaternion
2017-01-02 17:05:40 +01:00
* @param parentEntity
2017-01-09 15:20:48 +01:00
* @param eyeSeparation
* @param focalLength
2016-11-29 12:54:25 +01:00
* @constructor
*/
GameLib.D3.API.Camera = function(
id,
cameraType,
name,
fov,
aspect,
near,
far,
position,
lookAt,
minX,
maxX,
minY,
maxY,
minZ,
maxZ,
2017-01-02 17:05:40 +01:00
quaternion,
2017-01-09 15:20:48 +01:00
parentEntity,
eyeSeparation,
focalLength
2016-11-29 12:54:25 +01:00
) {
GameLib.Component.call(
this,
2017-01-02 17:05:40 +01:00
GameLib.Component.COMPONENT_CAMERA,
null,
parentEntity
);
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
2016-11-29 12:54:25 +01:00
}
this.id = id;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(cameraType)) {
2017-01-19 17:50:11 +01:00
cameraType = GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE;
2016-11-29 12:54:25 +01:00
}
this.cameraType = cameraType;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(name)) {
2017-01-09 15:20:48 +01:00
name = 'Camera (' + this.id + ')';
2016-11-29 12:54:25 +01:00
}
this.name = name;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(fov)) {
2016-11-29 12:54:25 +01:00
fov = 75;
}
this.fov = fov;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(aspect)) {
2016-11-29 12:54:25 +01:00
aspect = window.innerWidth / window.innerHeight;
}
this.aspect = aspect;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(near)) {
2017-01-31 15:23:38 +01:00
near = 0.01;
2016-11-29 12:54:25 +01:00
}
this.near = near;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(far)) {
2016-11-29 12:54:25 +01:00
far = 1000;
}
this.far = far;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(position)) {
position = new GameLib.API.Vector3(
2016-11-29 12:54:25 +01:00
15,
15,
15
);
}
this.position = position;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(quaternion)) {
quaternion = new GameLib.API.Quaternion();
}
this.quaternion = quaternion;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(lookAt)) {
lookAt = new GameLib.API.Vector3(
2016-11-29 12:54:25 +01:00
0,
0,
0
);
}
this.lookAt = lookAt;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(minX)) {
2016-11-29 12:54:25 +01:00
minX = -100;
}
this.minX = minX;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(maxX)) {
2016-11-29 12:54:25 +01:00
maxX = 100;
}
this.maxX = maxX;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(minY)) {
2016-11-29 12:54:25 +01:00
minY = -100;
}
this.minY = minY;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(maxY)) {
2016-11-29 12:54:25 +01:00
maxY = 100;
}
this.maxY = maxY;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(minZ)) {
2016-11-29 12:54:25 +01:00
minZ = -100;
}
this.minZ = minZ;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(maxZ)) {
2016-11-29 12:54:25 +01:00
maxZ = 100;
}
this.maxZ = maxZ;
2017-01-09 15:20:48 +01:00
if (GameLib.Utils.UndefinedOrNull(eyeSeparation)) {
eyeSeparation = 30;
}
this.eyeSeparation = eyeSeparation;
if (GameLib.Utils.UndefinedOrNull(focalLength)) {
focalLength = 150;
}
this.focalLength = focalLength;
};
GameLib.D3.API.Camera.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.Camera.prototype.constructor = GameLib.D3.API.Camera;
2017-01-05 19:34:28 +01:00
/**
* 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),
2017-01-09 15:20:48 +01:00
objectCamera.parentEntity,
objectCamera.eyeSeparation,
objectCamera.focalLength
2017-01-05 19:34:28 +01:00
);
};