more components
parent
15d3c5b446
commit
846bdba6c4
|
@ -1,10 +1,20 @@
|
||||||
GameLib.Component = function(
|
GameLib.Component = function(
|
||||||
componentType
|
componentType,
|
||||||
|
linkedObjects
|
||||||
) {
|
) {
|
||||||
this.componentType = componentType;
|
this.componentType = componentType;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(linkedObjects)) {
|
||||||
|
linkedObjects = [];
|
||||||
|
}
|
||||||
|
this.linkedObjects = linkedObjects;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.Component.COMPONENT_TYPE_PATH_FOLLOWING = 0x1;
|
GameLib.Component.COMPONENT_TYPE_PATH_FOLLOWING = 0x1;
|
||||||
|
GameLib.Component.COMPONENT_RENDERABLE = 0x2;
|
||||||
|
GameLib.Component.COMPONENT_RENDERER = 0x3;
|
||||||
|
GameLib.Component.COMPONENT_EDITOR_INPUT = 0x4;
|
||||||
|
GameLib.Component.COMPONENT_LOOK_AT = 0x5;
|
||||||
|
|
||||||
GameLib.Component.prototype.toApiComponent = function() {
|
GameLib.Component.prototype.toApiComponent = function() {
|
||||||
return this.id;
|
return this.id;
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
/**
|
||||||
|
* GameLib.D3.API.Input namespace
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Input = function() {};
|
|
@ -0,0 +1,46 @@
|
||||||
|
/**
|
||||||
|
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
||||||
|
* @param id String
|
||||||
|
* @param name String
|
||||||
|
* @param domElementId
|
||||||
|
* @param camera GameLib.D3.Camera
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Input.Editor = function (
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
domElementId,
|
||||||
|
camera
|
||||||
|
) {
|
||||||
|
GameLib.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.Component.COMPONENT_EDITOR_INPUT,
|
||||||
|
[
|
||||||
|
'camera'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
id = GameLib.Utils.RandomId();
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = this.constructor.name;
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(domElementId)) {
|
||||||
|
domElementId = "divCanvas";
|
||||||
|
}
|
||||||
|
this.domElementId = domElementId;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
||||||
|
camera = null;
|
||||||
|
}
|
||||||
|
this.camera = camera;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Input.Editor.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
GameLib.D3.API.Input.Editor.prototype.constructor = GameLib.D3.API.Input.Editor;
|
|
@ -0,0 +1,46 @@
|
||||||
|
/**
|
||||||
|
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
||||||
|
* @param id String
|
||||||
|
* @param name String
|
||||||
|
* @param domElementId
|
||||||
|
* @param camera GameLib.D3.Camera
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Input.Fly = function (
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
domElementId,
|
||||||
|
camera
|
||||||
|
) {
|
||||||
|
GameLib.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.Component.COMPONENT_FLY_INPUT,
|
||||||
|
[
|
||||||
|
'camera'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
id = GameLib.Utils.RandomId();
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = this.constructor.name;
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(domElementId)) {
|
||||||
|
domElementId = "divCanvas";
|
||||||
|
}
|
||||||
|
this.domElementId = domElementId;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
||||||
|
camera = null;
|
||||||
|
}
|
||||||
|
this.camera = camera;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Input.Fly.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
GameLib.D3.API.Input.Fly.prototype.constructor = GameLib.D3.API.Input.Fly;
|
|
@ -2,27 +2,30 @@
|
||||||
* Looks from currentPosition to targetPosition (default up is 0,1,0)
|
* Looks from currentPosition to targetPosition (default up is 0,1,0)
|
||||||
* @param id
|
* @param id
|
||||||
* @param name
|
* @param name
|
||||||
* @param currentPosition GameLib.API.Vector3
|
* @param currentComponent GameLib.Component
|
||||||
* @param targetPosition GameLib.API.Vector3
|
* @param targetComponent GameLib.Component
|
||||||
* @param targetPositionOffset GameLib.API.Vector3
|
* @param targetPositionOffset GameLib.API.Vector3
|
||||||
* @param rotationSpeed Number
|
* @param rotationSpeed Number
|
||||||
* @param lookAtMatrix GameLib.API.Matrix4
|
|
||||||
* @param up GameLib.API.Vector3
|
|
||||||
* @param currentRotation GameLib.API.Quaternion
|
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.API.LookAt = function (
|
GameLib.D3.API.LookAt = function (
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
currentPosition,
|
currentComponent,
|
||||||
targetPosition,
|
targetComponent,
|
||||||
targetPositionOffset,
|
targetPositionOffset,
|
||||||
rotationSpeed,
|
rotationSpeed
|
||||||
lookAtMatrix,
|
|
||||||
up,
|
|
||||||
currentRotation
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
GameLib.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.Component.COMPONENT_LOOK_AT,
|
||||||
|
[
|
||||||
|
'currentComponent',
|
||||||
|
'targetComponent'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.Utils.RandomId();
|
id = GameLib.Utils.RandomId();
|
||||||
}
|
}
|
||||||
|
@ -33,15 +36,15 @@ GameLib.D3.API.LookAt = function (
|
||||||
}
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
if(GameLib.Utils.UndefinedOrNull(currentPosition)) {
|
if(GameLib.Utils.UndefinedOrNull(currentComponent)) {
|
||||||
currentPosition = new GameLib.API.Vector3(0, 10, 10);
|
currentComponent = null;
|
||||||
}
|
}
|
||||||
this.currentPosition = currentPosition;
|
this.currentComponent = currentComponent;
|
||||||
|
|
||||||
if(GameLib.Utils.UndefinedOrNull(targetPosition)) {
|
if(GameLib.Utils.UndefinedOrNull(targetComponent)) {
|
||||||
targetPosition = new GameLib.API.Vector3(0, 0, 0);
|
targetComponent = null;
|
||||||
}
|
}
|
||||||
this.targetPosition = targetPosition;
|
this.targetComponent = targetComponent;
|
||||||
|
|
||||||
if(GameLib.Utils.UndefinedOrNull(targetPositionOffset)) {
|
if(GameLib.Utils.UndefinedOrNull(targetPositionOffset)) {
|
||||||
targetPositionOffset = new GameLib.API.Vector3(0, 0, 0);
|
targetPositionOffset = new GameLib.API.Vector3(0, 0, 0);
|
||||||
|
@ -53,18 +56,12 @@ GameLib.D3.API.LookAt = function (
|
||||||
}
|
}
|
||||||
this.rotationSpeed = rotationSpeed;
|
this.rotationSpeed = rotationSpeed;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(lookAtMatrix)) {
|
this.lookAtMatrix = new GameLib.API.Matrix4();
|
||||||
lookAtMatrix = new GameLib.API.Matrix4();
|
|
||||||
}
|
|
||||||
this.lookAtMatrix = lookAtMatrix;
|
|
||||||
|
|
||||||
if(GameLib.Utils.UndefinedOrNull(up)) {
|
this.up = new GameLib.API.Vector3(0, 1, 0);
|
||||||
up = new GameLib.API.Vector3(0, 1, 0);
|
|
||||||
}
|
|
||||||
this.up = up;
|
|
||||||
|
|
||||||
if(GameLib.Utils.UndefinedOrNull(currentRotation)) {
|
this.currentRotation = new GameLib.API.Quaternion();
|
||||||
currentRotation = new GameLib.API.Quaternion();
|
|
||||||
}
|
|
||||||
this.currentRotation = currentRotation;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.LookAt.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
GameLib.D3.API.LookAt.prototype.constructor = GameLib.D3.API.LookAt;
|
|
@ -3,6 +3,7 @@
|
||||||
* @param id String
|
* @param id String
|
||||||
* @param name String
|
* @param name String
|
||||||
* @param spline GameLib.D3.API.Spline
|
* @param spline GameLib.D3.API.Spline
|
||||||
|
* @param mesh GameLib.D3.API.Mesh
|
||||||
* @param raytraceMesh GameLib.D3.API.Mesh
|
* @param raytraceMesh GameLib.D3.API.Mesh
|
||||||
* @param accelleration Number
|
* @param accelleration Number
|
||||||
* @param maxSpeed Number
|
* @param maxSpeed Number
|
||||||
|
@ -14,9 +15,6 @@
|
||||||
* @param currentPathValue Number
|
* @param currentPathValue Number
|
||||||
* @param currentSpeed Number
|
* @param currentSpeed Number
|
||||||
* @param direction Number
|
* @param direction Number
|
||||||
* @param mx GameLib.Utils.MovingAverage
|
|
||||||
* @param my GameLib.Utils.MovingAverage
|
|
||||||
* @param mz GameLib.Utils.MovingAverage
|
|
||||||
* @param raycaster GameLib.D3.Raycaster
|
* @param raycaster GameLib.D3.Raycaster
|
||||||
* @param currentPosition GameLib.API.Vector3
|
* @param currentPosition GameLib.API.Vector3
|
||||||
* @param futurePosition GameLib.API.Vector3
|
* @param futurePosition GameLib.API.Vector3
|
||||||
|
@ -29,6 +27,7 @@ GameLib.D3.API.PathFollowing = function (
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
spline,
|
spline,
|
||||||
|
mesh,
|
||||||
raytraceMesh,
|
raytraceMesh,
|
||||||
accelleration,
|
accelleration,
|
||||||
maxSpeed,
|
maxSpeed,
|
||||||
|
@ -50,7 +49,12 @@ GameLib.D3.API.PathFollowing = function (
|
||||||
|
|
||||||
GameLib.Component.call(
|
GameLib.Component.call(
|
||||||
this,
|
this,
|
||||||
GameLib.Component.COMPONENT_TYPE_PATH_FOLLOWING
|
GameLib.Component.COMPONENT_TYPE_PATH_FOLLOWING,
|
||||||
|
[
|
||||||
|
'spline',
|
||||||
|
'mesh',
|
||||||
|
'raytraceMesh'
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
@ -68,6 +72,11 @@ GameLib.D3.API.PathFollowing = function (
|
||||||
}
|
}
|
||||||
this.spline = spline;
|
this.spline = spline;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(mesh)) {
|
||||||
|
mesh = null;
|
||||||
|
}
|
||||||
|
this.mesh = mesh;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(raytraceMesh)) {
|
if (GameLib.Utils.UndefinedOrNull(raytraceMesh)) {
|
||||||
raytraceMesh = null;
|
raytraceMesh = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
/**
|
||||||
|
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
||||||
|
* @param id String
|
||||||
|
* @param name String
|
||||||
|
* @param visible
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Renderable = function (
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
visible
|
||||||
|
) {
|
||||||
|
|
||||||
|
GameLib.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.Component.COMPONENT_RENDERABLE
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
id = GameLib.Utils.RandomId();
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = this.constructor.name;
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(visible)) {
|
||||||
|
visible = true;
|
||||||
|
}
|
||||||
|
this.visible = visible;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Renderable.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
GameLib.D3.API.Renderable.prototype.constructor = GameLib.D3.API.Renderable;
|
|
@ -0,0 +1,76 @@
|
||||||
|
/**
|
||||||
|
* This component renders a scene
|
||||||
|
* @param id String
|
||||||
|
* @param name String
|
||||||
|
* @param scene GameLib.D3.Scene
|
||||||
|
* @param camera GameLib.D3.Camera
|
||||||
|
* @param autoClear bool
|
||||||
|
* @param localClipping
|
||||||
|
* @param width
|
||||||
|
* @param height
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Renderer = function (
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
scene,
|
||||||
|
camera,
|
||||||
|
autoClear,
|
||||||
|
localClipping,
|
||||||
|
width,
|
||||||
|
height
|
||||||
|
) {
|
||||||
|
|
||||||
|
GameLib.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.Component.COMPONENT_RENDERER,
|
||||||
|
[
|
||||||
|
'scene',
|
||||||
|
'camera'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
id = GameLib.Utils.RandomId();
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = this.constructor.name;
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(scene)) {
|
||||||
|
scene = null;
|
||||||
|
}
|
||||||
|
this.scene = scene;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
||||||
|
camera = null;
|
||||||
|
}
|
||||||
|
this.camera = camera;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(autoClear)) {
|
||||||
|
autoClear = true;
|
||||||
|
}
|
||||||
|
this.autoClear = autoClear;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(localClipping)) {
|
||||||
|
localClipping = false;
|
||||||
|
}
|
||||||
|
this.localClipping = localClipping;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(width)) {
|
||||||
|
width = 800;
|
||||||
|
}
|
||||||
|
this.width = width;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(height)) {
|
||||||
|
height = 600;
|
||||||
|
}
|
||||||
|
this.height = height;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Renderer.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
GameLib.D3.API.Renderer.prototype.constructor = GameLib.D3.API.Renderer;
|
|
@ -0,0 +1,5 @@
|
||||||
|
/**
|
||||||
|
* GameLib.D3.Input namespace
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Input = function () {};
|
|
@ -0,0 +1,84 @@
|
||||||
|
/**
|
||||||
|
* Input parent class
|
||||||
|
* @param graphics GameLib.D3.Graphics
|
||||||
|
* @param parentObject
|
||||||
|
* @param apiInputEditor GameLib.D3.API.Input.Editor
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Input.Editor = function RuntimeEditorInput(
|
||||||
|
graphics,
|
||||||
|
parentObject,
|
||||||
|
apiInputEditor
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||||
|
parentObject = null;
|
||||||
|
}
|
||||||
|
this.parentObject = parentObject;
|
||||||
|
|
||||||
|
GameLib.D3.API.Input.Editor.call(
|
||||||
|
this,
|
||||||
|
apiInputEditor.id,
|
||||||
|
apiInputEditor.name,
|
||||||
|
apiInputEditor.domElementId,
|
||||||
|
apiInputEditor.camera
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Don't create an instance here - since we don't have our camera loaded yet...
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Input.Editor.prototype = Object.create(GameLib.D3.API.Input.Editor.prototype);
|
||||||
|
GameLib.D3.Input.Editor.prototype.constructor = GameLib.D3.Input.Editor;
|
||||||
|
|
||||||
|
GameLib.D3.Input.Editor.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
|
var instance = null;
|
||||||
|
|
||||||
|
if (this.camera && this.domElementId) {
|
||||||
|
instance = new THREE.EditorControls(
|
||||||
|
this.camera.instance,
|
||||||
|
document.getElementById(this.domElementId)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.instance = instance;
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Input.Editor.prototype.updateInstance = function() {
|
||||||
|
this.instance = this.createInstance(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Input.Editor.prototype.toApiComponent = function() {
|
||||||
|
|
||||||
|
var apiInputEditor = new GameLib.D3.API.Input.Editor(
|
||||||
|
this.id,
|
||||||
|
this.name,
|
||||||
|
this.domElementId,
|
||||||
|
GameLib.Utils.IdOrNull(this.camera)
|
||||||
|
);
|
||||||
|
|
||||||
|
return apiInputEditor;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Input.Editor.FromObjectComponent = function(graphics, objectComponent) {
|
||||||
|
|
||||||
|
var apiInputEditor = new GameLib.D3.API.Input.Editor(
|
||||||
|
objectComponent.id,
|
||||||
|
objectComponent.name,
|
||||||
|
objectComponent.domElementId,
|
||||||
|
objectComponent.camera
|
||||||
|
);
|
||||||
|
|
||||||
|
return new GameLib.D3.Input.Editor(
|
||||||
|
graphics,
|
||||||
|
this,
|
||||||
|
apiInputEditor
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,285 @@
|
||||||
|
/**
|
||||||
|
* Input parent class
|
||||||
|
* @param graphics GameLib.D3.Graphics
|
||||||
|
* @param parentObject
|
||||||
|
* @param apiInputFly GameLib.D3.API.Input.Fly
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Input.Fly = function RuntimeEditorInput(
|
||||||
|
graphics,
|
||||||
|
parentObject,
|
||||||
|
apiInputFly
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||||
|
parentObject = null;
|
||||||
|
}
|
||||||
|
this.parentObject = parentObject;
|
||||||
|
|
||||||
|
GameLib.D3.API.Input.Fly.call(
|
||||||
|
this,
|
||||||
|
apiInputFly.id,
|
||||||
|
apiInputFly.name,
|
||||||
|
apiInputFly.domElementId,
|
||||||
|
apiInputFly.camera
|
||||||
|
);
|
||||||
|
|
||||||
|
this.mouseUpCallback = this.onMouseUp.bind(this);
|
||||||
|
this.mouseDownCallback = this.onMouseDown.bind(this);
|
||||||
|
this.mouseMoveCallback = this.onMouseMove.bind(this);
|
||||||
|
this.mouseWheelCallback = this.onMouseWheel.bind(this);
|
||||||
|
this.keyDownCallback = this.onKeyDown.bind(this);
|
||||||
|
this.keyUpCallback = this.onKeyUp.bind(this);
|
||||||
|
|
||||||
|
this.camera = camera;
|
||||||
|
|
||||||
|
this.canvas.addEventListener('keydown', this.keyDownCallback, false);
|
||||||
|
this.canvas.addEventListener('keyup', this.keyUpCallback, false);
|
||||||
|
this.canvas.addEventListener('mousedown', this.mouseDownCallback, false);
|
||||||
|
this.canvas.addEventListener('mouseup', this.mouseUpCallback, false);
|
||||||
|
this.canvas.addEventListener('mousewheel', this.mouseWheelCallback, false);
|
||||||
|
|
||||||
|
this.havePointerLock = 'pointerLockElement' in document || 'mozPointerLockElement' in document || 'webkitPointerLockElement' in document;
|
||||||
|
this.element = document.body;
|
||||||
|
|
||||||
|
if (this.havePointerLock) {
|
||||||
|
this.element.requestPointerLock = this.element.requestPointerLock || this.element.mozRequestPointerLock || this.element.webkitRequestPointerLock;
|
||||||
|
document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock || document.webkitExitPointerLock;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Don't create an instance here - since we don't have our camera loaded yet...
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Input.Fly.prototype = Object.create(GameLib.D3.API.Input.Fly.prototype);
|
||||||
|
GameLib.D3.Input.Fly.prototype.constructor = GameLib.D3.Input.Fly;
|
||||||
|
|
||||||
|
GameLib.D3.Input.Fly.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
|
//todo
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Input.Fly.prototype.updateInstance = function() {
|
||||||
|
this.instance = this.createInstance(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Input.Fly.prototype.toApiComponent = function() {
|
||||||
|
|
||||||
|
var apiInputFly = new GameLib.D3.API.Input.Fly(
|
||||||
|
this.id,
|
||||||
|
this.name,
|
||||||
|
this.domElementId,
|
||||||
|
GameLib.Utils.IdOrNull(this.camera)
|
||||||
|
);
|
||||||
|
|
||||||
|
return apiInputFly;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Input.Fly.FromObjectComponent = function(graphics, objectComponent) {
|
||||||
|
|
||||||
|
var apiInputFly = new GameLib.D3.API.Input.Fly(
|
||||||
|
objectComponent.id,
|
||||||
|
objectComponent.name,
|
||||||
|
objectComponent.domElementId,
|
||||||
|
objectComponent.camera
|
||||||
|
);
|
||||||
|
|
||||||
|
return new GameLib.D3.Input.Fly(
|
||||||
|
graphics,
|
||||||
|
this,
|
||||||
|
apiInputFly
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Go forward / backward on mouse wheel
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
GameLib.D3.Input.Fly.prototype.onMouseWheel = function(event) {
|
||||||
|
this.moveForward = true;
|
||||||
|
this.applyTranslation(event.wheelDelta * 0.001);
|
||||||
|
event.preventDefault();
|
||||||
|
this.moveForward = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start rotating the camera on mouse middle button down
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
GameLib.D3.Input.Fly.prototype.onMouseDown = function(event) {
|
||||||
|
if (event.button == 1) {
|
||||||
|
this.canRotate = true;
|
||||||
|
this.canvas.addEventListener('mousemove', this.mouseMoveCallback, false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop rotating on middle mouse button down
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
GameLib.D3.Input.Fly.prototype.onMouseUp = function(event) {
|
||||||
|
if (event.button == 1) {
|
||||||
|
this.canRotate = false;
|
||||||
|
this.canvas.removeEventListener('mousemove', this.mouseMoveCallback);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply current yaw and pitch to camera
|
||||||
|
*/
|
||||||
|
GameLib.D3.Input.Fly.prototype.applyRotation = function() {
|
||||||
|
this.camera.rotation.set(this.pitch, this.yaw, 0, "YXZ");
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply current position to camera
|
||||||
|
* @param deltaTime
|
||||||
|
*/
|
||||||
|
GameLib.D3.Input.Fly.prototype.applyTranslation = function(deltaTime) {
|
||||||
|
var direction = new this.THREE.Vector3(0, 0, -1);
|
||||||
|
var rotation = new this.THREE.Euler(0, 0, 0, "YXZ");
|
||||||
|
rotation.set(this.pitch, this.yaw, 0, "YXZ");
|
||||||
|
|
||||||
|
direction = direction.applyEuler(rotation);
|
||||||
|
|
||||||
|
var forward = direction.normalize();
|
||||||
|
var right = forward.cross(new this.THREE.Vector3(0, 1, 0));
|
||||||
|
|
||||||
|
if(this.moveForward) {
|
||||||
|
|
||||||
|
this.camera.position.x += forward.x * (deltaTime * this.flySpeed);
|
||||||
|
this.camera.position.y += forward.y * (deltaTime * this.flySpeed);
|
||||||
|
this.camera.position.z += forward.z * (deltaTime * this.flySpeed);
|
||||||
|
|
||||||
|
} else if(this.moveBackward) {
|
||||||
|
|
||||||
|
this.camera.position.x -= forward.x * (deltaTime * this.flySpeed);
|
||||||
|
this.camera.position.y -= forward.y * (deltaTime * this.flySpeed);
|
||||||
|
this.camera.position.z -= forward.z * (deltaTime * this.flySpeed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.moveLeft) {
|
||||||
|
|
||||||
|
this.camera.position.x -= right.x * (deltaTime * this.flySpeed);
|
||||||
|
this.camera.position.y -= right.y * (deltaTime * this.flySpeed);
|
||||||
|
this.camera.position.z -= right.z * (deltaTime * this.flySpeed);
|
||||||
|
|
||||||
|
} else if(this.moveRight) {
|
||||||
|
|
||||||
|
this.camera.position.x += right.x * (deltaTime * this.flySpeed);
|
||||||
|
this.camera.position.y += right.y * (deltaTime * this.flySpeed);
|
||||||
|
this.camera.position.z += right.z * (deltaTime * this.flySpeed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.moveUp) {
|
||||||
|
|
||||||
|
this.camera.position.y += (deltaTime * this.flySpeed);
|
||||||
|
|
||||||
|
} else if(this.moveDown) {
|
||||||
|
|
||||||
|
this.camera.position.y -= (deltaTime * this.flySpeed);
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This update function should be called from the animation function in order to apply the 'frame rate independent'
|
||||||
|
* movement to the camera
|
||||||
|
* @param deltaTime
|
||||||
|
*/
|
||||||
|
GameLib.D3.Input.Fly.prototype.update = function(deltaTime) {
|
||||||
|
this.applyRotation();
|
||||||
|
this.applyTranslation(deltaTime);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotate on mouse move
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
GameLib.D3.Input.Fly.prototype.onMouseMove = function ( event ) {
|
||||||
|
if (this.canRotate) {
|
||||||
|
var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
|
||||||
|
var movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
|
||||||
|
|
||||||
|
this.yaw -= movementX * 0.002;
|
||||||
|
this.pitch -= movementY * 0.002;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keyboard controls
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
GameLib.D3.Input.Fly.prototype.onKeyDown = function ( event ) {
|
||||||
|
switch ( event.keyCode ) {
|
||||||
|
|
||||||
|
case 87: // w
|
||||||
|
this.moveForward = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 65: // a
|
||||||
|
this.moveLeft = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 83: // s
|
||||||
|
this.moveBackward = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 68: // d
|
||||||
|
this.moveRight = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 104: // keypad up arrow
|
||||||
|
this.moveUp = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 98: // keypad down arrow
|
||||||
|
this.moveDown = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keyboard controls
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
GameLib.D3.Input.Fly.prototype.onKeyUp = function ( event ) {
|
||||||
|
switch ( event.keyCode ) {
|
||||||
|
|
||||||
|
case 38: // up
|
||||||
|
case 87: // w
|
||||||
|
this.moveForward = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 37: // left
|
||||||
|
case 65: // a
|
||||||
|
this.moveLeft = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 40: // down
|
||||||
|
case 83: // s
|
||||||
|
this.moveBackward = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 39: // right
|
||||||
|
case 68: // d
|
||||||
|
this.moveRight = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 104: // keypad up arrow
|
||||||
|
this.moveUp = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 98: // keypad down arrow
|
||||||
|
this.moveDown = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,33 +20,18 @@ GameLib.D3.LookAt = function RuntimeLookAt(
|
||||||
|
|
||||||
GameLib.D3.API.LookAt.call(
|
GameLib.D3.API.LookAt.call(
|
||||||
this,
|
this,
|
||||||
apiLookAt.id,
|
apiLookAt.id,
|
||||||
apiLookAt.name,
|
apiLookAt.name,
|
||||||
apiLookAt.currentPosition,
|
apiLookAt.currentComponent,
|
||||||
apiLookAt.targetPosition,
|
apiLookAt.targetComponent,
|
||||||
apiLookAt.targetPositionOffset,
|
apiLookAt.targetPositionOffset,
|
||||||
apiLookAt.rotationSpeed,
|
apiLookAt.rotationSpeed
|
||||||
apiLookAt.lookAtMatrix,
|
|
||||||
apiLookAt.up,
|
|
||||||
apiLookAt.currentRotation
|
|
||||||
);
|
);
|
||||||
|
|
||||||
this.currentPosition = new GameLib.Vector3(
|
this.targetPositionOffset = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this,
|
||||||
this.currentPosition
|
this.targetPositionOffset
|
||||||
);
|
|
||||||
|
|
||||||
this.targetPosition = new GameLib.Vector3(
|
|
||||||
this.graphics,
|
|
||||||
this,
|
|
||||||
this.targetPosition
|
|
||||||
);
|
|
||||||
|
|
||||||
this.targetOffset = new GameLib.Vector3(
|
|
||||||
this.graphics,
|
|
||||||
this,
|
|
||||||
this.targetOffset
|
|
||||||
);
|
);
|
||||||
|
|
||||||
this.lookAtMatrix = new GameLib.Matrix4(
|
this.lookAtMatrix = new GameLib.Matrix4(
|
||||||
|
@ -70,3 +55,43 @@ GameLib.D3.LookAt = function RuntimeLookAt(
|
||||||
|
|
||||||
GameLib.D3.LookAt.prototype = Object.create(GameLib.D3.API.LookAt.prototype);
|
GameLib.D3.LookAt.prototype = Object.create(GameLib.D3.API.LookAt.prototype);
|
||||||
GameLib.D3.LookAt.prototype.constructor = GameLib.D3.LookAt;
|
GameLib.D3.LookAt.prototype.constructor = GameLib.D3.LookAt;
|
||||||
|
|
||||||
|
GameLib.D3.LookAt.prototype.toApiComponent = function() {
|
||||||
|
|
||||||
|
var apiLookAt = new GameLib.D3.API.LookAt(
|
||||||
|
this.id,
|
||||||
|
this.name,
|
||||||
|
GameLib.Utils.IdOrNull(this.currentComponent),
|
||||||
|
GameLib.Utils.IdOrNull(this.targetComponent),
|
||||||
|
this.targetPositionOffset.toApiVector(),
|
||||||
|
this.rotationSpeed
|
||||||
|
);
|
||||||
|
|
||||||
|
return apiLookAt;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.LookAt.FromObjectComponent = function(graphics, objectComponent) {
|
||||||
|
|
||||||
|
var apiLookAt = new GameLib.D3.API.LookAt(
|
||||||
|
objectComponent.id,
|
||||||
|
objectComponent.name,
|
||||||
|
objectComponent.currentComponent,
|
||||||
|
objectComponent.targetComponent,
|
||||||
|
objectComponent.targetPositionOffset,
|
||||||
|
objectComponent.rotationSpeed
|
||||||
|
);
|
||||||
|
|
||||||
|
return new GameLib.D3.LookAt(
|
||||||
|
graphics,
|
||||||
|
this,
|
||||||
|
apiLookAt
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the component
|
||||||
|
* @param deltaTime
|
||||||
|
*/
|
||||||
|
GameLib.D3.LookAt.prototype.update = function(deltaTime) {
|
||||||
|
|
||||||
|
};
|
|
@ -24,7 +24,8 @@ GameLib.D3.PathFollowing = function RuntimePathFollowing(
|
||||||
apiPathFollowing.id,
|
apiPathFollowing.id,
|
||||||
apiPathFollowing.name,
|
apiPathFollowing.name,
|
||||||
apiPathFollowing.spline,
|
apiPathFollowing.spline,
|
||||||
apiPathFollowing.raytraceMesh,
|
apiPathFollowing.mesh,
|
||||||
|
apiPathFollowing.raytraceMesh,
|
||||||
apiPathFollowing.accelleration,
|
apiPathFollowing.accelleration,
|
||||||
apiPathFollowing.maxSpeed,
|
apiPathFollowing.maxSpeed,
|
||||||
apiPathFollowing.baseOffset,
|
apiPathFollowing.baseOffset,
|
||||||
|
@ -113,8 +114,9 @@ GameLib.D3.PathFollowing.prototype.toApiComponent = function() {
|
||||||
var apiPathFollowing = new GameLib.D3.API.PathFollowing(
|
var apiPathFollowing = new GameLib.D3.API.PathFollowing(
|
||||||
this.id,
|
this.id,
|
||||||
this.name,
|
this.name,
|
||||||
this.spline,
|
GameLib.Utils.IdOrNull(this.spline),
|
||||||
this.raytraceMesh,
|
GameLib.Utils.IdOrNull(this.mesh),
|
||||||
|
GameLib.Utils.IdOrNull(this.raytraceMesh),
|
||||||
this.accelleration,
|
this.accelleration,
|
||||||
this.maxSpeed,
|
this.maxSpeed,
|
||||||
this.baseOffset.toApiVector(),
|
this.baseOffset.toApiVector(),
|
||||||
|
@ -142,6 +144,7 @@ GameLib.D3.PathFollowing.FromObjectComponent = function(graphics, objectComponen
|
||||||
objectComponent.id,
|
objectComponent.id,
|
||||||
objectComponent.name,
|
objectComponent.name,
|
||||||
objectComponent.spline,
|
objectComponent.spline,
|
||||||
|
objectComponent.mesh,
|
||||||
objectComponent.raytraceMesh,
|
objectComponent.raytraceMesh,
|
||||||
objectComponent.accelleration,
|
objectComponent.accelleration,
|
||||||
objectComponent.maxSpeed,
|
objectComponent.maxSpeed,
|
||||||
|
@ -217,3 +220,72 @@ GameLib.D3.PathFollowing.FromObjectComponent = function(graphics, objectComponen
|
||||||
apiPathFollowing
|
apiPathFollowing
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the component
|
||||||
|
* @param deltaTime
|
||||||
|
*/
|
||||||
|
GameLib.D3.PathFollowing.prototype.update = function(deltaTime) {
|
||||||
|
|
||||||
|
if (this.spline && this.mesh && this.raytraceMesh) {
|
||||||
|
|
||||||
|
this.currentSpeed += this.accelleration * deltaTime * this.direction;
|
||||||
|
if(this.currentSpeed > this.maxSpeed) {
|
||||||
|
this.currentSpeed = this.maxSpeed;
|
||||||
|
}
|
||||||
|
this.grain = (this.currentSpeed / 100.0);
|
||||||
|
|
||||||
|
this.currentPosition = this.spline.getPointAt(this.currentPathValue);
|
||||||
|
|
||||||
|
this.currentPathValue += this.grain;
|
||||||
|
|
||||||
|
if (this.currentPathValue >= 1) {
|
||||||
|
this.currentPathValue = this.currentPathValue - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.currentPathValue < 0) {
|
||||||
|
this.currentPathValue = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.futurePosition = this.spline.getPointAt(this.currentPathValue);
|
||||||
|
|
||||||
|
this.raycaster.setPosition(
|
||||||
|
this.futurePosition
|
||||||
|
);
|
||||||
|
|
||||||
|
var normal = this.raycaster.getFaceNormal(this.raytraceMesh);
|
||||||
|
|
||||||
|
if (normal) {
|
||||||
|
this.up.x = this.mx(normal.x);
|
||||||
|
this.up.y = this.my(normal.y);
|
||||||
|
this.up.z = this.mz(normal.z);
|
||||||
|
|
||||||
|
this.up.updateInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.rotationMatrix.lookAt(
|
||||||
|
this.currentPosition,
|
||||||
|
this.futurePosition,
|
||||||
|
this.up
|
||||||
|
);
|
||||||
|
|
||||||
|
this.rotationVector.setFromRotationMatrix(this.rotationMatrix);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Position
|
||||||
|
*/
|
||||||
|
this.mesh.position.x = this.futurePosition.x;// + transformedOffset.x;
|
||||||
|
this.mesh.position.y = this.futurePosition.y;// + transformedOffset.y;
|
||||||
|
this.mesh.position.z = this.futurePosition.z;// + transformedOffset.z;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Rotation
|
||||||
|
*/
|
||||||
|
this.mesh.quaternion.x = this.rotationVector.x;
|
||||||
|
this.mesh.quaternion.y = this.rotationVector.y;
|
||||||
|
this.mesh.quaternion.z = this.rotationVector.z;
|
||||||
|
this.mesh.quaternion.w = this.rotationVector.w;
|
||||||
|
|
||||||
|
this.mesh.updateInstance();
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,57 @@
|
||||||
|
/**
|
||||||
|
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
||||||
|
* @param graphics GameLib.D3.Graphics
|
||||||
|
* @param parentObject
|
||||||
|
* @param apiRenderable GameLib.D3.API.Renderable
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Renderable = function RuntimeRenderable(
|
||||||
|
graphics,
|
||||||
|
parentObject,
|
||||||
|
apiRenderable
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||||
|
parentObject = null;
|
||||||
|
}
|
||||||
|
this.parentObject = parentObject;
|
||||||
|
|
||||||
|
GameLib.D3.API.Renderable.call(
|
||||||
|
this,
|
||||||
|
apiRenderable.id,
|
||||||
|
apiRenderable.name,
|
||||||
|
apiRenderable.visible
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Renderable.prototype = Object.create(GameLib.D3.API.Renderable.prototype);
|
||||||
|
GameLib.D3.Renderable.prototype.constructor = GameLib.D3.Renderable;
|
||||||
|
|
||||||
|
GameLib.D3.Renderable.prototype.toApiComponent = function() {
|
||||||
|
|
||||||
|
var apiRenderable = new GameLib.D3.API.Renderable(
|
||||||
|
this.id,
|
||||||
|
this.name,
|
||||||
|
this.visible
|
||||||
|
);
|
||||||
|
|
||||||
|
return apiRenderable;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Renderable.FromObjectComponent = function(graphics, objectComponent) {
|
||||||
|
|
||||||
|
var apiRenderable = new GameLib.D3.API.Renderable(
|
||||||
|
objectComponent.id,
|
||||||
|
objectComponent.name,
|
||||||
|
objectComponent.visible
|
||||||
|
);
|
||||||
|
|
||||||
|
return new GameLib.D3.Renderable(
|
||||||
|
graphics,
|
||||||
|
this,
|
||||||
|
apiRenderable
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,95 @@
|
||||||
|
/**
|
||||||
|
* Renders a scene with a camera
|
||||||
|
* @param graphics GameLib.D3.Graphics
|
||||||
|
* @param parentObject
|
||||||
|
* @param apiRenderer GameLib.D3.API.Renderer
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Renderer = function RuntimeRenderer(
|
||||||
|
graphics,
|
||||||
|
parentObject,
|
||||||
|
apiRenderer
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||||
|
parentObject = null;
|
||||||
|
}
|
||||||
|
this.parentObject = parentObject;
|
||||||
|
|
||||||
|
GameLib.D3.API.Renderer.call(
|
||||||
|
this,
|
||||||
|
apiRenderer.id,
|
||||||
|
apiRenderer.name,
|
||||||
|
apiRenderer.scene,
|
||||||
|
apiRenderer.camera,
|
||||||
|
apiRenderer.autoClear,
|
||||||
|
apiRenderer.localClipping,
|
||||||
|
apiRenderer.width,
|
||||||
|
apiRenderer.height
|
||||||
|
);
|
||||||
|
|
||||||
|
this.instance = this.createInstance();
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Renderer.prototype = Object.create(GameLib.D3.API.Renderer.prototype);
|
||||||
|
GameLib.D3.Renderer.prototype.constructor = GameLib.D3.Renderer;
|
||||||
|
|
||||||
|
GameLib.D3.Renderer.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
|
var instance = null;
|
||||||
|
|
||||||
|
if (update) {
|
||||||
|
instance = this.instance;
|
||||||
|
} else {
|
||||||
|
instance = new THREE.WebGLRenderer();
|
||||||
|
}
|
||||||
|
|
||||||
|
instance.localClippingEnabled = this.localClipping;
|
||||||
|
instance.setSize(this.width, this.height);
|
||||||
|
instance.autoClear = this.autoClear;
|
||||||
|
|
||||||
|
this.instance = instance;
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Renderer.prototype.updateInstance = function() {
|
||||||
|
this.instance = this.createInstance(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Renderer.prototype.toApiComponent = function() {
|
||||||
|
|
||||||
|
var apiRenderer = new GameLib.D3.API.Renderer(
|
||||||
|
this.id,
|
||||||
|
this.name,
|
||||||
|
GameLib.Utils.IdOrNull(this.scene),
|
||||||
|
GameLib.Utils.IdOrNull(this.camera),
|
||||||
|
this.autoClear
|
||||||
|
);
|
||||||
|
|
||||||
|
return apiRenderer;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Renderer.FromObjectComponent = function(graphics, objectComponent) {
|
||||||
|
|
||||||
|
var apiRenderer = new GameLib.D3.API.Renderer(
|
||||||
|
objectComponent.id,
|
||||||
|
objectComponent.name,
|
||||||
|
objectComponent.scene,
|
||||||
|
objectComponent.camera,
|
||||||
|
objectComponent.autoClear
|
||||||
|
);
|
||||||
|
|
||||||
|
return new GameLib.D3.Renderer(
|
||||||
|
graphics,
|
||||||
|
this,
|
||||||
|
apiRenderer
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Renderer.prototype.render = function(deltaTime) {
|
||||||
|
this.instance.render(this.scene.instance, this.camera.instance);
|
||||||
|
};
|
|
@ -75,29 +75,66 @@ GameLib.EntityManager.prototype.removeEntity = function(entity) {
|
||||||
*/
|
*/
|
||||||
GameLib.EntityManager.prototype.query = function(components) {
|
GameLib.EntityManager.prototype.query = function(components) {
|
||||||
|
|
||||||
return this.entities.map(
|
var result = this.entities.reduce(
|
||||||
function(__queryComponents) {
|
function(__queryComponents) {
|
||||||
return function(entity) {
|
return function(result, entity) {
|
||||||
__queryComponents.map(
|
|
||||||
|
var results = __queryComponents.reduce(
|
||||||
|
|
||||||
function(__entity) {
|
function(__entity) {
|
||||||
return function(queryComponent) {
|
return function(componentResult, queryComponent) {
|
||||||
__entity.components.map(
|
|
||||||
|
var components = __entity.components.reduce(
|
||||||
function(__queryComponent) {
|
function(__queryComponent) {
|
||||||
return function(entityComponent) {
|
return function(__components, entityComponent) {
|
||||||
if (__queryComponent == entityComponent.constructor.name) {
|
|
||||||
|
if (__queryComponent == entityComponent.constructor) {
|
||||||
// arrow should point towards a window or sergej --->
|
// arrow should point towards a window or sergej --->
|
||||||
return entityComponent;
|
__components[entityComponent.id] = entityComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return __components;
|
||||||
|
|
||||||
}
|
}
|
||||||
}(queryComponent)
|
}(queryComponent),
|
||||||
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
for (var property in components) {
|
||||||
|
if (components.hasOwnProperty(property)) {
|
||||||
|
componentResult[property] = components[property];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return componentResult;
|
||||||
}
|
}
|
||||||
}(entity)
|
}(entity),
|
||||||
)
|
{}
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
for (var property in results) {
|
||||||
|
if (results.hasOwnProperty(property)) {
|
||||||
|
result[property] = results[property];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
}(components)
|
}(components),
|
||||||
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var array = [];
|
||||||
|
|
||||||
|
for (var property in result) {
|
||||||
|
if (result.hasOwnProperty(property)) {
|
||||||
|
array.push(result[property]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -128,13 +165,22 @@ GameLib.EntityManager.prototype.toApiEntityManager = function() {
|
||||||
GameLib.EntityManager.FromObjectEntityManager = function(graphics, objectEntities) {
|
GameLib.EntityManager.FromObjectEntityManager = function(graphics, objectEntities) {
|
||||||
|
|
||||||
var apiEntities = objectEntities.entities.map(
|
var apiEntities = objectEntities.entities.map(
|
||||||
|
|
||||||
function (objectEntity) {
|
function (objectEntity) {
|
||||||
|
|
||||||
objectEntity.components = objectEntity.components.map(
|
objectEntity.components = objectEntity.components.map(
|
||||||
function (component) {
|
function (component) {
|
||||||
if (component instanceof Object) {
|
if (component instanceof Object) {
|
||||||
if (component.componentType == GameLib.Component.COMPONENT_TYPE_PATH_FOLLOWING) {
|
if (component.componentType === GameLib.Component.COMPONENT_TYPE_PATH_FOLLOWING) {
|
||||||
return GameLib.D3.PathFollowing.FromObjectComponent(graphics, component);
|
return GameLib.D3.PathFollowing.FromObjectComponent(graphics, component);
|
||||||
|
} else if (component.componentType === GameLib.Component.COMPONENT_RENDERABLE) {
|
||||||
|
return GameLib.D3.Renderable.FromObjectComponent(graphics, component);
|
||||||
|
} else if (component.componentType === GameLib.Component.COMPONENT_RENDERER) {
|
||||||
|
return GameLib.D3.Renderer.FromObjectComponent(graphics, component);
|
||||||
|
} else if (component.componentType === GameLib.Component.COMPONENT_EDITOR_INPUT) {
|
||||||
|
return GameLib.D3.Input.Editor.FromObjectComponent(graphics, component);
|
||||||
|
} else if (component.componentType === GameLib.Component.COMPONENT_LOOK_AT) {
|
||||||
|
return GameLib.D3.LookAt.FromObjectComponent(graphics, component);
|
||||||
} else {
|
} else {
|
||||||
console.warn('no component was associated with this object');
|
console.warn('no component was associated with this object');
|
||||||
throw new Error('no component was associated with this object');
|
throw new Error('no component was associated with this object');
|
||||||
|
@ -190,25 +236,15 @@ GameLib.EntityManager.prototype.linkObjects = function(idToObject) {
|
||||||
} else {
|
} else {
|
||||||
array[index] = idToObject[componentId];
|
array[index] = idToObject[componentId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
array[index].linkedObjects.map(
|
||||||
|
function (propertyName) {
|
||||||
|
array[index][propertyName] = idToObject[array[index][propertyName]];
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: fix
|
|
||||||
// this.components.forEach(
|
|
||||||
// function(currentValue, index, array) {
|
|
||||||
//
|
|
||||||
// if (!idToObject[currentValue]) {
|
|
||||||
// //throw new Error('Unable to locate component with ID: ' + currentValue);
|
|
||||||
// console.log('Unable to locate component with ID: ' + currentValue + ' - it must have been deleted before');
|
|
||||||
// array.splice(index, 1);
|
|
||||||
// } else {
|
|
||||||
// array[index] = idToObject[currentValue];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// }.bind(this)
|
|
||||||
// );
|
|
||||||
|
|
||||||
};
|
};
|
|
@ -13,8 +13,25 @@ GameLib.System = function(
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.System.SYSTEM_TYPE_RENDER = 0x1;
|
||||||
|
GameLib.System.SYSTEM_TYPE_ANIMATION = 0x2;
|
||||||
|
GameLib.System.SYSTEM_TYPE_INPUT = 0x3;
|
||||||
|
GameLib.System.SYSTEM_TYPE_ALL = 0x4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @callback
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
|
GameLib.System.prototype.start = function() {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @callback
|
* @callback
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
GameLib.System.prototype.update = function() {};
|
GameLib.System.prototype.update = function() {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @callback
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
|
GameLib.System.prototype.stop = function() {};
|
|
@ -14,80 +14,25 @@ GameLib.System.Animation = function(
|
||||||
GameLib.System.Animation.prototype = Object.create(GameLib.System.prototype);
|
GameLib.System.Animation.prototype = Object.create(GameLib.System.prototype);
|
||||||
GameLib.System.Animation.prototype.constructor = GameLib.System.Animation;
|
GameLib.System.Animation.prototype.constructor = GameLib.System.Animation;
|
||||||
|
|
||||||
|
GameLib.System.Animation.prototype.start = function() {
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
GameLib.System.prototype.update = function() {
|
GameLib.System.Animation.prototype.update = function(deltaTime) {
|
||||||
|
|
||||||
var objects = this.entityManager.queryComponents([GameLib.D3.Mesh, GameLib.D3.Animation]);
|
var objects = this.entityManager.query([GameLib.D3.PathFollowing]);
|
||||||
|
|
||||||
objects.forEach(function(object) {
|
objects.forEach(function(object) {
|
||||||
|
object.update(deltaTime);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: PathFollowingComponent Stuff
|
* TODO: PathFollowingComponent Stuff
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* if (this.spline && this.raytraceMesh) {
|
*
|
||||||
|
|
||||||
this.currentSpeed += this.accelleration * deltaTime * this.direction;
|
|
||||||
if(this.currentSpeed > this.maxSpeed) {
|
|
||||||
this.currentSpeed = this.maxSpeed;
|
|
||||||
}
|
|
||||||
this.grain = (this.currentSpeed / 100.0);
|
|
||||||
|
|
||||||
this.currentPosition = this.spline.getPointAt(this.currentPathValue);
|
|
||||||
|
|
||||||
this.currentPathValue += this.grain;
|
|
||||||
|
|
||||||
if (this.currentPathValue >= 1) {
|
|
||||||
this.currentPathValue = this.currentPathValue - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.currentPathValue < 0) {
|
|
||||||
this.currentPathValue = 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.futurePosition = this.spline.getPointAt(this.currentPathValue);
|
|
||||||
|
|
||||||
this.raycaster.setPosition(
|
|
||||||
this.futurePosition
|
|
||||||
);
|
|
||||||
|
|
||||||
var normal = this.raycaster.getFaceNormal(this.raytraceMesh);
|
|
||||||
|
|
||||||
if (normal) {
|
|
||||||
this.up.x = this.mx(normal.x);
|
|
||||||
this.up.y = this.my(normal.y);
|
|
||||||
this.up.z = this.mz(normal.z);
|
|
||||||
|
|
||||||
this.up.updateInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.rotationMatrix.lookAt(
|
|
||||||
this.currentPosition,
|
|
||||||
this.futurePosition,
|
|
||||||
this.up
|
|
||||||
);
|
|
||||||
|
|
||||||
this.rotationVector.setFromRotationMatrix(this.rotationMatrix);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update Position
|
|
||||||
*
|
|
||||||
this.parentEntity.position.x = this.futurePosition.x;// + transformedOffset.x;
|
|
||||||
this.parentEntity.position.y = this.futurePosition.y;// + transformedOffset.y;
|
|
||||||
this.parentEntity.position.z = this.futurePosition.z;// + transformedOffset.z;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update Rotation
|
|
||||||
*
|
|
||||||
this.parentEntity.quaternion.x = this.rotationVector.x;
|
|
||||||
this.parentEntity.quaternion.y = this.rotationVector.y;
|
|
||||||
this.parentEntity.quaternion.z = this.rotationVector.z;
|
|
||||||
this.parentEntity.quaternion.w = this.rotationVector.w;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
TODO: lookat component code
|
TODO: lookat component code
|
||||||
|
|
||||||
|
@ -178,3 +123,6 @@ GameLib.System.prototype.update = function() {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.System.Animation.prototype.stop = function() {
|
||||||
|
};
|
|
@ -14,229 +14,51 @@ GameLib.System.Input = function(
|
||||||
GameLib.System.Input.prototype = Object.create(GameLib.System.prototype);
|
GameLib.System.Input.prototype = Object.create(GameLib.System.prototype);
|
||||||
GameLib.System.Input.prototype.constructor = GameLib.System.Input;
|
GameLib.System.Input.prototype.constructor = GameLib.System.Input;
|
||||||
|
|
||||||
|
GameLib.System.Input.prototype.start = function() {
|
||||||
|
|
||||||
|
var objects = this.entityManager.query([GameLib.D3.Input.Editor]);
|
||||||
|
|
||||||
|
objects.forEach(
|
||||||
|
function(object) {
|
||||||
|
if (!object.instance) {
|
||||||
|
object.createInstance();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
GameLib.System.prototype.update = function() {
|
GameLib.System.Input.prototype.update = function(deltaTime) {
|
||||||
|
|
||||||
var objects = this.entityManager.queryComponents([GameLib.D3.FlyControls, GameLib.D3.Input]);
|
//TODO: Fly controls (and some others) have an update function which need to get executed here
|
||||||
|
// var objects = this.entityManager.query([GameLib.D3.Input.Editor]);
|
||||||
|
//
|
||||||
|
// objects.forEach(
|
||||||
|
// function(object) {
|
||||||
|
// if (!object.instance) {
|
||||||
|
// object.instance = object.createInstance();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
|
||||||
objects.forEach(function(object) {
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO : flycontrols stuff
|
|
||||||
* this.mouseUpCallback = this.onMouseUp.bind(this);
|
|
||||||
this.mouseDownCallback = this.onMouseDown.bind(this);
|
|
||||||
this.mouseMoveCallback = this.onMouseMove.bind(this);
|
|
||||||
this.mouseWheelCallback = this.onMouseWheel.bind(this);
|
|
||||||
this.keyDownCallback = this.onKeyDown.bind(this);
|
|
||||||
this.keyUpCallback = this.onKeyUp.bind(this);
|
|
||||||
|
|
||||||
this.camera = camera;
|
|
||||||
|
|
||||||
this.canvas.addEventListener('keydown', this.keyDownCallback, false);
|
|
||||||
this.canvas.addEventListener('keyup', this.keyUpCallback, false);
|
|
||||||
this.canvas.addEventListener('mousedown', this.mouseDownCallback, false);
|
|
||||||
this.canvas.addEventListener('mouseup', this.mouseUpCallback, false);
|
|
||||||
this.canvas.addEventListener('mousewheel', this.mouseWheelCallback, false);
|
|
||||||
|
|
||||||
this.havePointerLock = 'pointerLockElement' in document || 'mozPointerLockElement' in document || 'webkitPointerLockElement' in document;
|
|
||||||
this.element = document.body;
|
|
||||||
|
|
||||||
if (this.havePointerLock) {
|
|
||||||
this.element.requestPointerLock = this.element.requestPointerLock || this.element.mozRequestPointerLock || this.element.webkitRequestPointerLock;
|
|
||||||
document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock || document.webkitExitPointerLock;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Go forward / backward on mouse wheel
|
|
||||||
* @param event
|
|
||||||
*
|
|
||||||
GameLib.D3.FlyControls.prototype.onMouseWheel = function(event) {
|
|
||||||
this.moveForward = true;
|
|
||||||
this.applyTranslation(event.wheelDelta * 0.001);
|
|
||||||
event.preventDefault();
|
|
||||||
this.moveForward = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start rotating the camera on mouse middle button down
|
|
||||||
* @param event
|
|
||||||
*
|
|
||||||
GameLib.D3.FlyControls.prototype.onMouseDown = function(event) {
|
|
||||||
if (event.button == 1) {
|
|
||||||
this.canRotate = true;
|
|
||||||
this.canvas.addEventListener('mousemove', this.mouseMoveCallback, false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop rotating on middle mouse button down
|
|
||||||
* @param event
|
|
||||||
*
|
|
||||||
GameLib.D3.FlyControls.prototype.onMouseUp = function(event) {
|
|
||||||
if (event.button == 1) {
|
|
||||||
this.canRotate = false;
|
|
||||||
this.canvas.removeEventListener('mousemove', this.mouseMoveCallback);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply current yaw and pitch to camera
|
|
||||||
*
|
|
||||||
GameLib.D3.FlyControls.prototype.applyRotation = function() {
|
|
||||||
this.camera.rotation.set(this.pitch, this.yaw, 0, "YXZ");
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply current position to camera
|
|
||||||
* @param deltaTime
|
|
||||||
*
|
|
||||||
GameLib.D3.FlyControls.prototype.applyTranslation = function(deltaTime) {
|
|
||||||
var direction = new this.THREE.Vector3(0, 0, -1);
|
|
||||||
var rotation = new this.THREE.Euler(0, 0, 0, "YXZ");
|
|
||||||
rotation.set(this.pitch, this.yaw, 0, "YXZ");
|
|
||||||
|
|
||||||
direction = direction.applyEuler(rotation);
|
|
||||||
|
|
||||||
var forward = direction.normalize();
|
|
||||||
var right = forward.cross(new this.THREE.Vector3(0, 1, 0));
|
|
||||||
|
|
||||||
if(this.moveForward) {
|
|
||||||
|
|
||||||
this.camera.position.x += forward.x * (deltaTime * this.flySpeed);
|
|
||||||
this.camera.position.y += forward.y * (deltaTime * this.flySpeed);
|
|
||||||
this.camera.position.z += forward.z * (deltaTime * this.flySpeed);
|
|
||||||
|
|
||||||
} else if(this.moveBackward) {
|
|
||||||
|
|
||||||
this.camera.position.x -= forward.x * (deltaTime * this.flySpeed);
|
|
||||||
this.camera.position.y -= forward.y * (deltaTime * this.flySpeed);
|
|
||||||
this.camera.position.z -= forward.z * (deltaTime * this.flySpeed);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.moveLeft) {
|
|
||||||
|
|
||||||
this.camera.position.x -= right.x * (deltaTime * this.flySpeed);
|
|
||||||
this.camera.position.y -= right.y * (deltaTime * this.flySpeed);
|
|
||||||
this.camera.position.z -= right.z * (deltaTime * this.flySpeed);
|
|
||||||
|
|
||||||
} else if(this.moveRight) {
|
|
||||||
|
|
||||||
this.camera.position.x += right.x * (deltaTime * this.flySpeed);
|
|
||||||
this.camera.position.y += right.y * (deltaTime * this.flySpeed);
|
|
||||||
this.camera.position.z += right.z * (deltaTime * this.flySpeed);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.moveUp) {
|
|
||||||
|
|
||||||
this.camera.position.y += (deltaTime * this.flySpeed);
|
|
||||||
|
|
||||||
} else if(this.moveDown) {
|
|
||||||
|
|
||||||
this.camera.position.y -= (deltaTime * this.flySpeed);
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This update function should be called from the animation function in order to apply the 'frame rate independent'
|
|
||||||
* movement to the camera
|
|
||||||
* @param deltaTime
|
|
||||||
*
|
|
||||||
GameLib.D3.FlyControls.prototype.update = function(deltaTime) {
|
|
||||||
this.applyRotation();
|
|
||||||
this.applyTranslation(deltaTime);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rotate on mouse move
|
|
||||||
* @param event
|
|
||||||
*
|
|
||||||
GameLib.D3.FlyControls.prototype.onMouseMove = function ( event ) {
|
|
||||||
if (this.canRotate) {
|
|
||||||
var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
|
|
||||||
var movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
|
|
||||||
|
|
||||||
this.yaw -= movementX * 0.002;
|
|
||||||
this.pitch -= movementY * 0.002;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Keyboard controls
|
|
||||||
* @param event
|
|
||||||
*
|
|
||||||
GameLib.D3.FlyControls.prototype.onKeyDown = function ( event ) {
|
|
||||||
switch ( event.keyCode ) {
|
|
||||||
|
|
||||||
case 87: // w
|
|
||||||
this.moveForward = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 65: // a
|
|
||||||
this.moveLeft = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 83: // s
|
|
||||||
this.moveBackward = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 68: // d
|
|
||||||
this.moveRight = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 104: // keypad up arrow
|
|
||||||
this.moveUp = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 98: // keypad down arrow
|
|
||||||
this.moveDown = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Keyboard controls
|
|
||||||
* @param event
|
|
||||||
*
|
|
||||||
GameLib.D3.FlyControls.prototype.onKeyUp = function ( event ) {
|
|
||||||
switch ( event.keyCode ) {
|
|
||||||
|
|
||||||
case 38: // up
|
|
||||||
case 87: // w
|
|
||||||
this.moveForward = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 37: // left
|
|
||||||
case 65: // a
|
|
||||||
this.moveLeft = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 40: // down
|
|
||||||
case 83: // s
|
|
||||||
this.moveBackward = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 39: // right
|
|
||||||
case 68: // d
|
|
||||||
this.moveRight = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 104: // keypad up arrow
|
|
||||||
this.moveUp = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 98: // keypad down arrow
|
|
||||||
this.moveDown = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.System.Input.prototype.stop = function() {
|
||||||
|
|
||||||
|
var objects = this.entityManager.query([GameLib.D3.Input.Editor]);
|
||||||
|
|
||||||
|
objects.forEach(
|
||||||
|
function (object) {
|
||||||
|
if (object.instance) {
|
||||||
|
object.instance.enabled = false;
|
||||||
|
delete object.instance;
|
||||||
|
object.instance = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
|
@ -3,40 +3,100 @@
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.System.Render = function(
|
GameLib.System.Render = function(
|
||||||
entityManager
|
entityManager,
|
||||||
|
domElement,
|
||||||
|
stats
|
||||||
) {
|
) {
|
||||||
GameLib.System.call(
|
GameLib.System.call(
|
||||||
this,
|
this,
|
||||||
entityManager
|
entityManager
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(domElement)) {
|
||||||
|
domElement = null;
|
||||||
|
}
|
||||||
|
this.domElement = domElement;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(stats)) {
|
||||||
|
stats = null;
|
||||||
|
}
|
||||||
|
this.stats = stats;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Render.prototype = Object.create(GameLib.System.prototype);
|
GameLib.System.Render.prototype = Object.create(GameLib.System.prototype);
|
||||||
GameLib.System.Render.prototype.constructor = GameLib.System.Render;
|
GameLib.System.Render.prototype.constructor = GameLib.System.Render;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
GameLib.System.Render.prototype.start = function() {
|
||||||
|
|
||||||
|
this.domElement.innerHTML = '';
|
||||||
|
this.domElement.appendChild(this.stats.dom);
|
||||||
|
|
||||||
|
var renderers = this.entityManager.query([GameLib.D3.Renderer]);
|
||||||
|
renderers.forEach(
|
||||||
|
function (renderer) {
|
||||||
|
|
||||||
|
if (!renderer.instance) {
|
||||||
|
renderer.createInstance();
|
||||||
|
} else {
|
||||||
|
renderer.updateInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.domElement.appendChild(renderer.instance.domElement);
|
||||||
|
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
GameLib.System.prototype.update = function() {
|
GameLib.System.Render.prototype.update = function(deltaTime) {
|
||||||
|
|
||||||
var objects = this.entityManager.queryComponents([GameLib.D3.Camera]);
|
var renderers = this.entityManager.query([GameLib.D3.Renderer]);
|
||||||
|
|
||||||
objects.forEach(function(object) {
|
renderers.forEach(
|
||||||
|
function (renderer) {
|
||||||
|
renderer.render(deltaTime);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
//TODO camera component stuff
|
// renderObjects.forEach(function(object) {
|
||||||
object.quaternion.x = this.parentEntity.quaternion.x;
|
//
|
||||||
object.quaternion.y = this.parentEntity.quaternion.y;
|
// //TODO camera component stuff
|
||||||
object.quaternion.z = this.parentEntity.quaternion.z;
|
// object.quaternion.x = this.parentEntity.quaternion.x;
|
||||||
object.quaternion.w = this.parentEntity.quaternion.w;
|
// object.quaternion.y = this.parentEntity.quaternion.y;
|
||||||
|
// object.quaternion.z = this.parentEntity.quaternion.z;
|
||||||
object.position.x = this.parentEntity.position.x;
|
// object.quaternion.w = this.parentEntity.quaternion.w;
|
||||||
object.position.y = this.parentEntity.position.y;
|
//
|
||||||
object.position.z = this.parentEntity.position.z;
|
// object.position.x = this.parentEntity.position.x;
|
||||||
|
// object.position.y = this.parentEntity.position.y;
|
||||||
object.updateInstance();
|
// object.position.z = this.parentEntity.position.z;
|
||||||
|
//
|
||||||
//TODO scene component stuff
|
// object.updateInstance();
|
||||||
renderer.render(this.instance, this.cameras[this.activeCameraIndex].instance);
|
//
|
||||||
});
|
// //TODO scene component stuff
|
||||||
|
// renderer.render(this.instance, this.cameras[this.activeCameraIndex].instance);
|
||||||
|
// });
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.System.Render.prototype.stop = function() {
|
||||||
|
|
||||||
|
this.domElement.innerHTML = '';
|
||||||
|
|
||||||
|
var renderers = this.entityManager.query([GameLib.D3.Renderer]);
|
||||||
|
renderers.forEach(
|
||||||
|
function (renderer) {
|
||||||
|
|
||||||
|
if (renderer.instance) {
|
||||||
|
delete renderer.instance;
|
||||||
|
renderer.instance = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
};
|
|
@ -10,6 +10,31 @@ GameLib.Utils.Extend = function(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// GameLib.Utils.ObjectFactory = function() {
|
||||||
|
//
|
||||||
|
// var promiseList = {};
|
||||||
|
//
|
||||||
|
// return function(objectId) {
|
||||||
|
//
|
||||||
|
// if (!objectId) {
|
||||||
|
// console.log('No Object ID specified ' + objectId);
|
||||||
|
// throw new Error('No Object ID specified ' + objectId);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (promiseList[objectId]) {
|
||||||
|
// return promiseList[objectId];
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// var defer = Q.defer();
|
||||||
|
//
|
||||||
|
// promiseList[objectId] = defer.promise;
|
||||||
|
//
|
||||||
|
// GameLib.Utils.ObjectFactory.Link(idToObject, objectId, defer);
|
||||||
|
//
|
||||||
|
// return promiseList[objectId];
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
GameLib.Utils.UndefinedOrNull = function (
|
GameLib.Utils.UndefinedOrNull = function (
|
||||||
variable
|
variable
|
||||||
) {
|
) {
|
||||||
|
|
Loading…
Reference in New Issue