constructor updates - inheritance getting stable
parent
c98c75bd6e
commit
d0ac06f2b6
|
@ -56,6 +56,40 @@ GameLib.API.Matrix4 = function ApiMatrix4(
|
|||
this.up = new GameLib.API.Vector4();
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an API matrix from an Object matrix
|
||||
* @param objectMatrix
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Matrix4.FromObjectMatrix = function(objectMatrix) {
|
||||
return new GameLib.API.Matrix4(
|
||||
new GameLib.API.Vector4(
|
||||
objectMatrix.rows[0].x,
|
||||
objectMatrix.rows[0].y,
|
||||
objectMatrix.rows[0].z,
|
||||
objectMatrix.rows[0].w
|
||||
),
|
||||
new GameLib.API.Vector4(
|
||||
objectMatrix.rows[1].x,
|
||||
objectMatrix.rows[1].y,
|
||||
objectMatrix.rows[1].z,
|
||||
objectMatrix.rows[1].w
|
||||
),
|
||||
new GameLib.API.Vector4(
|
||||
objectMatrix.rows[2].x,
|
||||
objectMatrix.rows[2].y,
|
||||
objectMatrix.rows[2].z,
|
||||
objectMatrix.rows[2].w
|
||||
),
|
||||
new GameLib.API.Vector4(
|
||||
objectMatrix.rows[3].x,
|
||||
objectMatrix.rows[3].y,
|
||||
objectMatrix.rows[3].z,
|
||||
objectMatrix.rows[3].w
|
||||
)
|
||||
)
|
||||
};
|
||||
|
||||
GameLib.API.Matrix4.prototype.rotationMatrixX = function (radians) {
|
||||
this.identity();
|
||||
this.rows[1] = new GameLib.API.Vector4(0, Math.cos(radians), -1 * Math.sin(radians), 0);
|
||||
|
@ -130,37 +164,3 @@ GameLib.API.Matrix4.prototype.identity = function () {
|
|||
new GameLib.API.Vector4(0, 0, 0, 1)
|
||||
];
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an API matrix from an Object matrix
|
||||
* @param objectMatrix
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Matrix4.FromObjectMatrix = function(objectMatrix) {
|
||||
return new GameLib.API.Matrix4(
|
||||
new GameLib.API.Vector4(
|
||||
objectMatrix.rows[0].x,
|
||||
objectMatrix.rows[0].y,
|
||||
objectMatrix.rows[0].z,
|
||||
objectMatrix.rows[0].w
|
||||
),
|
||||
new GameLib.API.Vector4(
|
||||
objectMatrix.rows[1].x,
|
||||
objectMatrix.rows[1].y,
|
||||
objectMatrix.rows[1].z,
|
||||
objectMatrix.rows[1].w
|
||||
),
|
||||
new GameLib.API.Vector4(
|
||||
objectMatrix.rows[2].x,
|
||||
objectMatrix.rows[2].y,
|
||||
objectMatrix.rows[2].z,
|
||||
objectMatrix.rows[2].w
|
||||
),
|
||||
new GameLib.API.Vector4(
|
||||
objectMatrix.rows[3].x,
|
||||
objectMatrix.rows[3].y,
|
||||
objectMatrix.rows[3].z,
|
||||
objectMatrix.rows[3].w
|
||||
)
|
||||
)
|
||||
};
|
||||
|
|
|
@ -1,4 +1,21 @@
|
|||
GameLib.API.Quaternion = function (x, y, z, w, axis, angle) {
|
||||
/**
|
||||
* Quaternion
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param w
|
||||
* @param axis
|
||||
* @param angle
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Quaternion = function (
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
w,
|
||||
axis,
|
||||
angle
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(x)) {
|
||||
x = 0;
|
||||
|
@ -202,16 +219,19 @@ GameLib.API.Quaternion.prototype.slerp = function (quaternion, t) {
|
|||
* @constructor
|
||||
*/
|
||||
GameLib.API.Quaternion.FromObjectQuaternion = function (objectQuaternion) {
|
||||
|
||||
var apiAxis = null;
|
||||
|
||||
if (objectQuaternion.axis) {
|
||||
apiAxis = GameLib.API.Vector3.FromObjectVector(objectQuaternion.axis);
|
||||
}
|
||||
|
||||
return new GameLib.API.Quaternion(
|
||||
objectQuaternion.x,
|
||||
objectQuaternion.y,
|
||||
objectQuaternion.z,
|
||||
objectQuaternion.w,
|
||||
new GameLib.API.Vector3(
|
||||
objectQuaternion.axis.x,
|
||||
objectQuaternion.axis.y,
|
||||
objectQuaternion.axis.z
|
||||
),
|
||||
apiAxis,
|
||||
objectQuaternion.angle
|
||||
)
|
||||
};
|
|
@ -1,4 +1,4 @@
|
|||
GameLib.API.Vector2 = function ApiVector2(x, y) {
|
||||
GameLib.API.Vector2 = function (x, y) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(x)) {
|
||||
x = 0;
|
||||
|
|
|
@ -6,11 +6,20 @@
|
|||
* @param grain Number
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Color = function (graphics, parentObject, apiColor, grain) {
|
||||
GameLib.Color = function (
|
||||
graphics,
|
||||
apiColor,
|
||||
parentObject,
|
||||
grain
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiColor)) {
|
||||
apiColor = {};
|
||||
}
|
||||
|
||||
GameLib.API.Color.call(
|
||||
this,
|
||||
apiColor.r,
|
||||
|
@ -19,6 +28,9 @@ GameLib.Color = function (graphics, parentObject, apiColor, grain) {
|
|||
apiColor.a
|
||||
);
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||
parentObject = null;
|
||||
}
|
||||
this.parentObject = parentObject;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||
|
@ -60,7 +72,8 @@ GameLib.Color.prototype.updateInstance = function() {
|
|||
|
||||
this.createInstance(true);
|
||||
|
||||
if (this.parentObject.updateInstance) {
|
||||
if (this.parentObject &&
|
||||
this.parentObject.updateInstance) {
|
||||
this.parentObject.updateInstance();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
* @param heightOffset
|
||||
* @param containerWidthOffset
|
||||
* @param containerHeightOffset
|
||||
* @param selectDelayMs
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
|
@ -24,6 +25,7 @@ GameLib.D3.API.Input.Editor = function (
|
|||
heightOffset,
|
||||
containerWidthOffset,
|
||||
containerHeightOffset,
|
||||
selectDelayMs,
|
||||
parentEntity
|
||||
) {
|
||||
GameLib.Component.call(
|
||||
|
@ -86,6 +88,11 @@ GameLib.D3.API.Input.Editor = function (
|
|||
containerHeightOffset = 80;
|
||||
}
|
||||
this.containerHeightOffset = containerHeightOffset;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(selectDelayMs)) {
|
||||
selectDelayMs = 300;
|
||||
}
|
||||
this.selectDelayMs = selectDelayMs;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Input.Editor.prototype = Object.create(GameLib.Component.prototype);
|
||||
|
@ -109,6 +116,7 @@ GameLib.D3.API.Input.Editor.FromObjectComponent = function(objectComponent) {
|
|||
objectComponent.heightOffset,
|
||||
objectComponent.containerWidthOffset,
|
||||
objectComponent.containerHeightOffset,
|
||||
objectComponent.selectDelayMs,
|
||||
objectComponent.parentEntity
|
||||
);
|
||||
};
|
||||
|
|
|
@ -29,26 +29,26 @@ GameLib.D3.Bone = function (
|
|||
|
||||
this.position = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.position
|
||||
this.position,
|
||||
this
|
||||
);
|
||||
|
||||
this.quaternion = new GameLib.Quaternion(
|
||||
graphics,
|
||||
this,
|
||||
this.quaternion
|
||||
this.quaternion,
|
||||
this
|
||||
);
|
||||
|
||||
this.scale = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.scale
|
||||
this.scale,
|
||||
this
|
||||
);
|
||||
|
||||
this.up = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.up
|
||||
this.up,
|
||||
this
|
||||
);
|
||||
|
||||
this.instance = this.createInstance();
|
||||
|
|
|
@ -41,20 +41,20 @@ GameLib.D3.Camera = function(
|
|||
|
||||
this.position = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.position
|
||||
this.position,
|
||||
this
|
||||
);
|
||||
|
||||
this.quaternion = new GameLib.Quaternion(
|
||||
graphics,
|
||||
this,
|
||||
this.quaternion
|
||||
this.quaternion,
|
||||
this
|
||||
);
|
||||
|
||||
this.lookAt = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.lookAt
|
||||
this.lookAt,
|
||||
this
|
||||
);
|
||||
|
||||
this.instance = this.createInstance();
|
||||
|
|
|
@ -29,32 +29,32 @@ GameLib.D3.Follow = function (
|
|||
|
||||
this.targetPositionOffset = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.targetPositionOffset
|
||||
this.targetPositionOffset,
|
||||
this
|
||||
);
|
||||
|
||||
this.target = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.target
|
||||
this.target,
|
||||
this
|
||||
);
|
||||
|
||||
this.targetToParent = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.targetToParent
|
||||
this.targetToParent,
|
||||
this
|
||||
);
|
||||
|
||||
this.rotatedTargetOffset = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.rotatedTargetOffset
|
||||
this.rotatedTargetOffset,
|
||||
this
|
||||
);
|
||||
|
||||
this.rotated = new GameLib.Quaternion(
|
||||
this.graphics,
|
||||
this,
|
||||
this.rotated
|
||||
this.rotated,
|
||||
this
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ GameLib.D3.Input.Editor = function (
|
|||
apiInputEditor.heightOffset,
|
||||
apiInputEditor.containerWidthOffset,
|
||||
apiInputEditor.containerHeightOffset,
|
||||
apiInputEditor.selectDelayMs,
|
||||
apiInputEditor.parentEntity
|
||||
);
|
||||
|
||||
|
@ -58,6 +59,10 @@ GameLib.D3.Input.Editor = function (
|
|||
this.keyPress = this.onKeyPress.bind(this);
|
||||
this.contextMenu = this.onContextMenu.bind(this);
|
||||
|
||||
this.raycaster = new GameLib.D3.Raycaster(
|
||||
this.graphics
|
||||
);
|
||||
|
||||
this.instance = this.createInstance();
|
||||
};
|
||||
|
||||
|
@ -145,6 +150,7 @@ GameLib.D3.Input.Editor.prototype.toApiComponent = function() {
|
|||
this.heightOffset,
|
||||
this.containerWidthOffset,
|
||||
this.containerHeightOffset,
|
||||
this.selectDelayMs,
|
||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
|
||||
|
@ -206,8 +212,9 @@ GameLib.D3.Input.Editor.prototype.onKeyPress = function(event) {
|
|||
|
||||
this.editor.allSelected = !this.editor.allSelected;
|
||||
|
||||
if (this.editor.allSelected) {
|
||||
this.editor.selectedObjects = [];
|
||||
|
||||
if (this.editor.allSelected) {
|
||||
this.editor.games.map(
|
||||
function(game) {
|
||||
|
||||
|
@ -224,13 +231,10 @@ GameLib.D3.Input.Editor.prototype.onKeyPress = function(event) {
|
|||
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
} else {
|
||||
this.editor.selectedObjects = [];
|
||||
}
|
||||
|
||||
if (this.editor.onSelectionChange) {
|
||||
this.editor.onSelectionChange(this.editor);
|
||||
if (this.editor.onSelectionChanged) {
|
||||
this.editor.onSelectionChanged(this.editor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -300,20 +304,27 @@ GameLib.D3.Input.Editor.prototype.onMouseDown = function(event) {
|
|||
event.stopPropagation();
|
||||
}
|
||||
|
||||
var meshInstances = [];
|
||||
var meshCollections = this.editor.game.scenes.map(
|
||||
function(scene) {
|
||||
return scene.meshes;
|
||||
}
|
||||
);
|
||||
|
||||
for (var m = 0; m < this.scene.meshes.length; m++) {
|
||||
meshInstances.push(this.scene.meshes[m].instance);
|
||||
}
|
||||
var meshes = meshCollections.reduce(
|
||||
function(result, meshCollection) {
|
||||
return result.concat(meshCollection);
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
var intersects = this.scene.raycaster.instance.intersectObjects(meshInstances);
|
||||
var intersects = this.raycaster.getIntersectedObjects(meshes);
|
||||
|
||||
if (intersects.length > 0) {
|
||||
|
||||
var index = -1;
|
||||
|
||||
for (var s = 0; s < this.selectedObjects.length; s++) {
|
||||
if (this.selectedObjects[s].object.instance == intersects[0].object) {
|
||||
for (var s = 0; s < this.editor.selectedObjects.length; s++) {
|
||||
if (this.editor.selectedObjects[s].object == intersects[0]) {
|
||||
index = s;
|
||||
break;
|
||||
}
|
||||
|
@ -323,26 +334,21 @@ GameLib.D3.Input.Editor.prototype.onMouseDown = function(event) {
|
|||
/**
|
||||
* The object is not selected, select it
|
||||
*/
|
||||
this.selectObject(intersects[0].object.gameLibObject);
|
||||
|
||||
this.buildSelectedObjects();
|
||||
|
||||
this.buildGUI();
|
||||
this.selectObject(intersects[0]);
|
||||
|
||||
} else {
|
||||
/**
|
||||
* De-select the objec
|
||||
*/
|
||||
var delta = Date.now() - this.selectedObjects[index].lastUpdate;
|
||||
if (delta > 300) {
|
||||
|
||||
this.unselectObject(intersects[0].object.gameLibObject);
|
||||
|
||||
this.buildSelectedObjects();
|
||||
|
||||
this.buildGUI();
|
||||
var delta = Date.now() - this.editor.selectedObjects[index].lastUpdate;
|
||||
if (delta > this.selectDelayMs) {
|
||||
this.unselectObject(intersects[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.editor.onSelectionChanged) {
|
||||
this.editor.onSelectionChanged(this.editor);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -363,9 +369,10 @@ GameLib.D3.Input.Editor.prototype.onMouseDown = function(event) {
|
|||
* @param event
|
||||
*/
|
||||
GameLib.D3.Input.Editor.prototype.onMouseMove = function(event) {
|
||||
var clientX = event.clientX - 400;
|
||||
|
||||
this.scene.mouse.x = ((clientX/ (window.innerWidth - 400))) * 2 - 1;
|
||||
var clientX = event.clientX - this.widthOffset;
|
||||
|
||||
this.scene.mouse.x = ((clientX / (window.innerWidth - this.widthOffset))) * 2 - 1;
|
||||
this.scene.mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
|
||||
|
||||
this.scene.raycaster.instance.setFromCamera(
|
||||
|
|
|
@ -11,6 +11,10 @@ GameLib.D3.Light = function Light(
|
|||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiLight)) {
|
||||
apiLight = {};
|
||||
}
|
||||
|
||||
GameLib.D3.API.Light.call(
|
||||
this,
|
||||
apiLight.id,
|
||||
|
@ -33,33 +37,32 @@ GameLib.D3.Light = function Light(
|
|||
|
||||
this.color = new GameLib.Color(
|
||||
graphics,
|
||||
this,
|
||||
this.color,
|
||||
0.01
|
||||
this
|
||||
);
|
||||
|
||||
this.position = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.position
|
||||
this.position,
|
||||
this
|
||||
);
|
||||
|
||||
this.targetPosition = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.targetPosition
|
||||
this.targetPosition,
|
||||
this
|
||||
);
|
||||
|
||||
this.scale = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.scale
|
||||
this.scale,
|
||||
this
|
||||
);
|
||||
|
||||
this.quaternion = new GameLib.Quaternion(
|
||||
graphics,
|
||||
this,
|
||||
this.quaternion
|
||||
this.quaternion,
|
||||
this
|
||||
);
|
||||
|
||||
this.instance = this.createInstance();
|
||||
|
@ -92,21 +95,21 @@ GameLib.D3.Light.prototype.createInstance = function(update) {
|
|||
if (!instance) {
|
||||
|
||||
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_AMBIENT) {
|
||||
instance = new this.graphics.instance.AmbientLight(
|
||||
instance = new THREE.AmbientLight(
|
||||
this.color.instance,
|
||||
this.intensity
|
||||
);
|
||||
}
|
||||
|
||||
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL) {
|
||||
instance = new this.graphics.instance.DirectionalLight(
|
||||
instance = new THREE.DirectionalLight(
|
||||
this.color.instance,
|
||||
this.intensity
|
||||
);
|
||||
}
|
||||
|
||||
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_POINT) {
|
||||
instance = new this.graphics.instance.PointLight(
|
||||
instance = new THREE.PointLight(
|
||||
this.color.instance,
|
||||
this.intensity
|
||||
);
|
||||
|
@ -115,7 +118,7 @@ GameLib.D3.Light.prototype.createInstance = function(update) {
|
|||
}
|
||||
|
||||
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_SPOT ) {
|
||||
instance = new this.graphics.instance.SpotLight(
|
||||
instance = new THREE.SpotLight(
|
||||
this.color.instance,
|
||||
this.intensity
|
||||
);
|
||||
|
|
|
@ -11,6 +11,10 @@ GameLib.D3.LookAt = function (
|
|||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiLookAt)) {
|
||||
apiLookAt = {};
|
||||
}
|
||||
|
||||
GameLib.D3.API.LookAt.call(
|
||||
this,
|
||||
apiLookAt.id,
|
||||
|
@ -24,32 +28,32 @@ GameLib.D3.LookAt = function (
|
|||
|
||||
this.targetPositionOffset = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.targetPositionOffset
|
||||
this.targetPositionOffset,
|
||||
this
|
||||
);
|
||||
|
||||
this.lookAtMatrix = new GameLib.Matrix4(
|
||||
this.graphics,
|
||||
this,
|
||||
this.lookAtMatrix
|
||||
this.lookAtMatrix,
|
||||
this
|
||||
);
|
||||
|
||||
this.up = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.up
|
||||
this.up,
|
||||
this
|
||||
);
|
||||
|
||||
this.currentRotation = new GameLib.Quaternion(
|
||||
this.graphics,
|
||||
this,
|
||||
this.currentRotation
|
||||
this.currentRotation,
|
||||
this
|
||||
);
|
||||
|
||||
this.targetPosition = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.targetPosition
|
||||
this.targetPosition,
|
||||
this
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -15,7 +15,16 @@ GameLib.D3.Material = function Material(
|
|||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiMaterial)) {
|
||||
apiMaterial = {};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
|
||||
console.warn('Cannot create a material without specifying an ImageFactory');
|
||||
throw new Error('Cannot create a material without specifying an ImageFactory');
|
||||
}
|
||||
|
||||
GameLib.D3.API.Material.call(
|
||||
this,
|
||||
apiMaterial.id,
|
||||
|
|
|
@ -15,6 +15,20 @@ GameLib.D3.Mesh = function (
|
|||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiMesh)) {
|
||||
apiMesh = {};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(computeNormals)) {
|
||||
computeNormals = true;
|
||||
}
|
||||
this.computeNormals = computeNormals;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
|
||||
console.warn('Cannot create a mesh without specifying an ImageFactory');
|
||||
throw new Error('Cannot create a mesh without specifying an ImageFactory');
|
||||
}
|
||||
|
||||
GameLib.D3.API.Mesh.call(
|
||||
this,
|
||||
apiMesh.id,
|
||||
|
@ -43,11 +57,18 @@ GameLib.D3.Mesh = function (
|
|||
|
||||
this.materials = this.materials.map(
|
||||
function (apiMaterial) {
|
||||
return new GameLib.D3.Material(
|
||||
this.graphics,
|
||||
apiMaterial,
|
||||
imageFactory
|
||||
)
|
||||
|
||||
if (apiMaterial instanceof GameLib.D3.API.Material) {
|
||||
return new GameLib.D3.Material(
|
||||
this.graphics,
|
||||
apiMaterial,
|
||||
imageFactory
|
||||
)
|
||||
} else {
|
||||
console.warn('API material not of instance API.Material');
|
||||
throw new Error('API material not of instance API.Material');
|
||||
}
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
|
@ -70,57 +91,52 @@ GameLib.D3.Mesh = function (
|
|||
|
||||
this.position = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.position,
|
||||
0.001
|
||||
this
|
||||
);
|
||||
|
||||
this.scale = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.scale,
|
||||
0.001
|
||||
this
|
||||
);
|
||||
|
||||
this.up = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.up,
|
||||
0.001
|
||||
this
|
||||
);
|
||||
|
||||
this.quaternion = new GameLib.Quaternion(
|
||||
this.graphics,
|
||||
this,
|
||||
this.quaternion
|
||||
this.quaternion,
|
||||
this
|
||||
);
|
||||
|
||||
this.localPosition = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.localPosition
|
||||
this.localPosition,
|
||||
this
|
||||
);
|
||||
|
||||
this.localRotation = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.localRotation
|
||||
this.localRotation,
|
||||
this
|
||||
);
|
||||
|
||||
this.localScale = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.localScale
|
||||
this.localScale,
|
||||
this
|
||||
);
|
||||
|
||||
this.modelMatrix = new GameLib.Matrix4(
|
||||
this.graphics,
|
||||
this,
|
||||
this.modelMatrix
|
||||
this.modelMatrix,
|
||||
this
|
||||
);
|
||||
|
||||
this.computeNormals = computeNormals;
|
||||
|
||||
this.instance = this.createInstance(false);
|
||||
|
||||
this.instance.geometry.computeBoundingBox();
|
||||
|
|
|
@ -12,6 +12,10 @@ GameLib.D3.Pass = function (
|
|||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiPass)) {
|
||||
apiPass = {};
|
||||
}
|
||||
|
||||
GameLib.D3.API.Pass.call(
|
||||
this,
|
||||
apiPass.id,
|
||||
|
|
|
@ -12,6 +12,10 @@ GameLib.D3.PathFollowing = function (
|
|||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiPathFollowing)) {
|
||||
apiPathFollowing = {};
|
||||
}
|
||||
|
||||
GameLib.D3.API.PathFollowing.call(
|
||||
this,
|
||||
apiPathFollowing.id,
|
||||
|
@ -40,26 +44,26 @@ GameLib.D3.PathFollowing = function (
|
|||
|
||||
this.baseOffset = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.baseOffset
|
||||
this.baseOffset,
|
||||
this
|
||||
);
|
||||
|
||||
this.maxOffset = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.maxOffset
|
||||
this.maxOffset,
|
||||
this
|
||||
);
|
||||
|
||||
this.targetOffset = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.targetOffset
|
||||
this.targetOffset,
|
||||
this
|
||||
);
|
||||
|
||||
this.currentOffset = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.currentOffset
|
||||
this.currentOffset,
|
||||
this
|
||||
);
|
||||
|
||||
this.raycaster = new GameLib.D3.Raycaster(
|
||||
|
@ -69,42 +73,38 @@ GameLib.D3.PathFollowing = function (
|
|||
|
||||
this.currentPosition = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.currentPosition
|
||||
this.currentPosition,
|
||||
this
|
||||
);
|
||||
|
||||
this.futurePosition = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.futurePosition
|
||||
this.futurePosition,
|
||||
this
|
||||
);
|
||||
|
||||
this.up = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.up
|
||||
this.up,
|
||||
this
|
||||
);
|
||||
|
||||
this.rotationMatrix = new GameLib.Matrix4(
|
||||
this.graphics,
|
||||
this,
|
||||
this.rotationMatrix
|
||||
this.rotationMatrix,
|
||||
this
|
||||
);
|
||||
|
||||
this.rotationVector = new GameLib.Quaternion(
|
||||
this.graphics,
|
||||
this,
|
||||
this.rotationVector
|
||||
this.rotationVector,
|
||||
this
|
||||
);
|
||||
|
||||
this.mx = new GameLib.Utils.MovingAverage(10);
|
||||
this.my = new GameLib.Utils.MovingAverage(10);
|
||||
this.mz = new GameLib.Utils.MovingAverage(10);
|
||||
|
||||
this.posx = new GameLib.Utils.MovingAverage(10);
|
||||
this.posy = new GameLib.Utils.MovingAverage(10);
|
||||
this.posz = new GameLib.Utils.MovingAverage(10);
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.PathFollowing.prototype = Object.create(GameLib.D3.API.PathFollowing.prototype);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/**
|
||||
* Raycaster for GameLib.D3
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param parentObject
|
||||
* @param apiRaycaster
|
||||
* @constructor
|
||||
*/
|
||||
|
@ -13,6 +12,10 @@ GameLib.D3.Raycaster = function(
|
|||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiRaycaster)) {
|
||||
apiRaycaster = {};
|
||||
}
|
||||
|
||||
GameLib.D3.API.Raycaster.call(
|
||||
this,
|
||||
apiRaycaster.id,
|
||||
|
@ -23,14 +26,14 @@ GameLib.D3.Raycaster = function(
|
|||
|
||||
this.position = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.position
|
||||
this.position,
|
||||
this
|
||||
);
|
||||
|
||||
this.direction = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.direction
|
||||
this.direction,
|
||||
this
|
||||
);
|
||||
|
||||
this.instance = this.createInstance();
|
||||
|
@ -61,6 +64,10 @@ GameLib.D3.Raycaster.prototype.createInstance = function(update) {
|
|||
return instance;
|
||||
};
|
||||
|
||||
GameLib.D3.Raycaster.prototype.updateInstance = function() {
|
||||
this.instance = this.createInstance(true);
|
||||
};
|
||||
|
||||
GameLib.D3.Raycaster.prototype.toApiRaycaster = function() {
|
||||
return new GameLib.D3.API.Raycaster(
|
||||
this.id,
|
||||
|
@ -76,7 +83,6 @@ GameLib.D3.Raycaster.FromObjectRaycaster = function(graphics, parentObject, obje
|
|||
|
||||
var raycaster = new GameLib.D3.Raycaster(
|
||||
graphics,
|
||||
parentObject,
|
||||
apiRaycaster
|
||||
);
|
||||
|
||||
|
@ -102,8 +108,6 @@ GameLib.D3.Raycaster.prototype.set = function(
|
|||
|
||||
this.position.updateInstance();
|
||||
this.direction.updateInstance();
|
||||
|
||||
this.createInstance(true);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -118,8 +122,6 @@ GameLib.D3.Raycaster.prototype.setDirection = function(
|
|||
this.direction.z = direction.z;
|
||||
|
||||
this.direction.updateInstance();
|
||||
|
||||
this.createInstance(true);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -134,10 +136,36 @@ GameLib.D3.Raycaster.prototype.setPosition = function(
|
|||
this.position.z = position.z;
|
||||
|
||||
this.position.updateInstance();
|
||||
|
||||
this.createInstance(true);
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets all interesected GameLib.D3.Mesh objects
|
||||
* @param meshes [GameLib.D3.Mesh]
|
||||
*/
|
||||
GameLib.D3.Raycaster.prototype.getIntersectedObjects = function(meshes) {
|
||||
|
||||
var meshInstances = meshes.map(
|
||||
function (mesh) {
|
||||
return mesh.instance;
|
||||
}
|
||||
);
|
||||
|
||||
var instanceIdToMesh = meshes.reduce(
|
||||
function (result, mesh) {
|
||||
result[mesh.instance.id] = mesh;
|
||||
},
|
||||
{}
|
||||
);
|
||||
|
||||
var intersects = this.instance.intersectObjects(meshInstances);
|
||||
|
||||
return intersects.map(function (intersect) {
|
||||
return instanceIdToMesh[intersect.object.id];
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns the face normal (if any) of an intersection between current ray position, direction and a provided mesh
|
||||
* @param mesh GameLib.D3.Mesh
|
||||
|
@ -152,14 +180,15 @@ GameLib.D3.Raycaster.prototype.getFaceNormal = function(mesh) {
|
|||
);
|
||||
|
||||
if (intersect && intersect.length > 0) {
|
||||
|
||||
normal = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
new GameLib.API.Vector3(
|
||||
intersect[0].face.normal.x,
|
||||
intersect[0].face.normal.y,
|
||||
intersect[0].face.normal.z
|
||||
)
|
||||
),
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -182,12 +211,12 @@ GameLib.D3.Raycaster.prototype.getIntersectPoint = function(mesh) {
|
|||
if (intersect && intersect.length > 0) {
|
||||
point = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
new GameLib.API.Vector3(
|
||||
intersect[0].point.x,
|
||||
intersect[0].point.y,
|
||||
intersect[0].point.z
|
||||
)
|
||||
),
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,10 @@ GameLib.D3.RenderTarget = function (
|
|||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiRenderTarget)) {
|
||||
apiRenderTarget = {};
|
||||
}
|
||||
|
||||
GameLib.D3.API.RenderTarget.call(
|
||||
this,
|
||||
apiRenderTarget.id,
|
||||
|
|
|
@ -12,6 +12,10 @@ GameLib.D3.Renderer = function (
|
|||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiRenderer)) {
|
||||
apiRenderer = {};
|
||||
}
|
||||
|
||||
GameLib.D3.API.Renderer.call(
|
||||
this,
|
||||
apiRenderer.id,
|
||||
|
|
|
@ -16,6 +16,23 @@ GameLib.D3.Scene = function Scene(
|
|||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiScene)) {
|
||||
apiScene = {};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
|
||||
imageFactory = GameLib.D3.ImageFactory(
|
||||
this.graphics,
|
||||
this.baseUrl
|
||||
);
|
||||
}
|
||||
this.imageFactory = imageFactory;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(computeNormals)) {
|
||||
computeNormals = true;
|
||||
}
|
||||
this.computeNormals = computeNormals;
|
||||
|
||||
GameLib.D3.API.Scene.call(
|
||||
this,
|
||||
apiScene.id,
|
||||
|
@ -33,14 +50,6 @@ GameLib.D3.Scene = function Scene(
|
|||
apiScene.parentEntity
|
||||
);
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
|
||||
imageFactory = GameLib.D3.ImageFactory(
|
||||
this.graphics,
|
||||
this.baseUrl
|
||||
);
|
||||
}
|
||||
this.imageFactory = imageFactory;
|
||||
|
||||
this.idToObject = {};
|
||||
|
||||
this.meshes = this.meshes.map(
|
||||
|
@ -49,7 +58,7 @@ GameLib.D3.Scene = function Scene(
|
|||
var mesh = new GameLib.D3.Mesh(
|
||||
this.graphics,
|
||||
apiMesh,
|
||||
computeNormals,
|
||||
this.computeNormals,
|
||||
imageFactory
|
||||
);
|
||||
|
||||
|
@ -72,62 +81,78 @@ GameLib.D3.Scene = function Scene(
|
|||
);
|
||||
|
||||
this.position = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.position
|
||||
this.graphics,
|
||||
this.position,
|
||||
this
|
||||
);
|
||||
|
||||
this.quaternion = new GameLib.Quaternion(
|
||||
graphics,
|
||||
this,
|
||||
this.quaternion
|
||||
this.graphics,
|
||||
this.quaternion,
|
||||
this
|
||||
);
|
||||
|
||||
this.scale = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.scale
|
||||
this.graphics,
|
||||
this.scale,
|
||||
this
|
||||
);
|
||||
|
||||
this.lights = this.lights.map(
|
||||
function(apiLight) {
|
||||
var light = new GameLib.D3.Light(
|
||||
this.graphics,
|
||||
apiLight
|
||||
);
|
||||
|
||||
this.idToObject[light.id] = light;
|
||||
if (apiLight instanceof GameLib.D3.API.Light) {
|
||||
var light = new GameLib.D3.Light(
|
||||
this.graphics,
|
||||
apiLight
|
||||
);
|
||||
|
||||
this.idToObject[light.id] = light;
|
||||
|
||||
return light;
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
return light;
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.materials = this.materials.map(
|
||||
function(apiMaterial) {
|
||||
var material = new GameLib.D3.Material(
|
||||
this.graphics,
|
||||
apiMaterial,
|
||||
this.imageFactory
|
||||
);
|
||||
if (apiMaterial instanceof GameLib.D3.API.Material) {
|
||||
var material = new GameLib.D3.Material(
|
||||
this.graphics,
|
||||
apiMaterial,
|
||||
this.imageFactory
|
||||
);
|
||||
|
||||
this.idToObject[material.id] = material;
|
||||
this.idToObject[material.id] = material;
|
||||
|
||||
return material;
|
||||
return material;
|
||||
} else {
|
||||
console.warn('apiMaterial not an instance of API.Material');
|
||||
throw new Error('apiMaterial not an instance of API.Material');
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
|
||||
this.textures = this.textures.map(
|
||||
function(apiTexture) {
|
||||
var texture = new GameLib.D3.Texture(
|
||||
this.graphics,
|
||||
apiTexture,
|
||||
this.imageFactory
|
||||
);
|
||||
if (apiTexture instanceof GameLib.D3.API.Texture) {
|
||||
var texture = new GameLib.D3.Texture(
|
||||
this.graphics,
|
||||
apiTexture,
|
||||
this.imageFactory
|
||||
);
|
||||
|
||||
this.idToObject[texture.id] = texture;
|
||||
this.idToObject[texture.id] = texture;
|
||||
|
||||
return texture;
|
||||
return texture;
|
||||
} else {
|
||||
console.warn('apiTexture not an instance of API.Texture');
|
||||
throw new Error('apiTexture not an instance of API.Texture');
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
|
|
|
@ -10,7 +10,11 @@ GameLib.D3.Skeleton = function Skeleton(
|
|||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiSkeleton)) {
|
||||
apiSkeleton = {};
|
||||
}
|
||||
|
||||
GameLib.D3.API.Skeleton.call(
|
||||
this,
|
||||
apiSkeleton.id,
|
||||
|
@ -26,31 +30,51 @@ GameLib.D3.Skeleton = function Skeleton(
|
|||
|
||||
this.bones = this.bones.map(
|
||||
function(apiBone) {
|
||||
return new GameLib.D3.Bone(
|
||||
this.graphics,
|
||||
apiBone
|
||||
)
|
||||
|
||||
if (apiBone instanceof GameLib.D3.API.Bone) {
|
||||
return new GameLib.D3.Bone(
|
||||
this.graphics,
|
||||
apiBone
|
||||
)
|
||||
} else {
|
||||
console.warn('apiBone not an instance of API.Bone');
|
||||
throw new Error('apiBone not an instance of API.Bone');
|
||||
}
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.boneInverses = this.boneInverses.map(
|
||||
function(boneInverse) {
|
||||
return new GameLib.Matrix4(
|
||||
this.graphics,
|
||||
this,
|
||||
boneInverse
|
||||
);
|
||||
|
||||
if (boneInverse instanceof GameLib.API.Matrix4) {
|
||||
return new GameLib.Matrix4(
|
||||
this.graphics,
|
||||
boneInverse,
|
||||
this
|
||||
);
|
||||
} else {
|
||||
console.warn('boneInverse not an instance of API.Matrix4');
|
||||
throw new Error('boneInverse not an instance of API.Matrix4');
|
||||
}
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
|
||||
this.boneMatrices = this.boneMatrices.map(
|
||||
function(boneMatrices) {
|
||||
return new GameLib.Matrix4(
|
||||
this.graphics,
|
||||
this,
|
||||
boneMatrices
|
||||
);
|
||||
if (boneMatrices instanceof GameLib.API.Matrix4) {
|
||||
return new GameLib.Matrix4(
|
||||
this.graphics,
|
||||
boneMatrices,
|
||||
this
|
||||
);
|
||||
} else {
|
||||
console.warn('boneMatrices not an instance of API.Matrix4');
|
||||
throw new Error('boneMatrices not an instance of API.Matrix4');
|
||||
}
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
|
|
|
@ -11,6 +11,10 @@ GameLib.D3.Spline = function (
|
|||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiSpline)) {
|
||||
apiSpline = {};
|
||||
}
|
||||
|
||||
GameLib.D3.API.Spline.call(
|
||||
this,
|
||||
apiSpline.id,
|
||||
|
@ -23,8 +27,8 @@ GameLib.D3.Spline = function (
|
|||
function (vertex) {
|
||||
return new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
vertex
|
||||
vertex,
|
||||
this
|
||||
)
|
||||
}
|
||||
);
|
||||
|
@ -108,8 +112,8 @@ GameLib.D3.Spline.prototype.getPointAt = function(proper) {
|
|||
var point = this.instance.getPointAt(proper);
|
||||
return new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
new GameLib.API.Vector3(point.x, point.y, point.z),
|
||||
this,
|
||||
0.1
|
||||
);
|
||||
};
|
||||
|
|
|
@ -15,7 +15,16 @@ GameLib.D3.Texture = function Texture(
|
|||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiTexture)) {
|
||||
apiTexture = {};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
|
||||
console.warn('Cannot create a material without specifying an ImageFactory');
|
||||
throw new Error('Cannot create a material without specifying an ImageFactory');
|
||||
}
|
||||
|
||||
GameLib.D3.API.Texture.call(
|
||||
this,
|
||||
apiTexture.id,
|
||||
|
@ -43,14 +52,14 @@ GameLib.D3.Texture = function Texture(
|
|||
|
||||
this.offset = new GameLib.Vector2(
|
||||
graphics,
|
||||
this,
|
||||
this.offset
|
||||
this.offset,
|
||||
this
|
||||
);
|
||||
|
||||
this.repeat = new GameLib.Vector2(
|
||||
graphics,
|
||||
this,
|
||||
this.repeat
|
||||
this.repeat,
|
||||
this
|
||||
);
|
||||
|
||||
// this.parentMaterial = parentMaterial;
|
||||
|
|
|
@ -11,6 +11,10 @@ GameLib.D3.Vertex = function Vertex(
|
|||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiVertex)) {
|
||||
apiVertex = {};
|
||||
}
|
||||
|
||||
GameLib.D3.API.Vertex.call(
|
||||
this,
|
||||
apiVertex.position,
|
||||
|
@ -19,8 +23,8 @@ GameLib.D3.Vertex = function Vertex(
|
|||
|
||||
this.position = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
null,
|
||||
this.position
|
||||
this.position,
|
||||
null
|
||||
);
|
||||
|
||||
this.boneWeights = this.boneWeights.map(
|
||||
|
|
|
@ -11,7 +11,11 @@ GameLib.D3.Viewport = function (
|
|||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiViewport)) {
|
||||
apiViewport = {};
|
||||
}
|
||||
|
||||
GameLib.D3.API.Viewport.call(
|
||||
this,
|
||||
apiViewport.id,
|
||||
|
|
|
@ -12,6 +12,10 @@ GameLib.EntityManager = function(
|
|||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiEntityManager)) {
|
||||
apiEntityManager = {};
|
||||
}
|
||||
|
||||
GameLib.API.EntityManager.call(
|
||||
this,
|
||||
apiEntityManager.entities
|
||||
|
|
|
@ -12,6 +12,10 @@ GameLib.Entity = function (
|
|||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiEntity)) {
|
||||
apiEntity = {};
|
||||
}
|
||||
|
||||
GameLib.API.Entity.call(
|
||||
this,
|
||||
apiEntity.id,
|
||||
|
|
|
@ -8,11 +8,18 @@
|
|||
*/
|
||||
GameLib.Matrix4 = function(
|
||||
graphics,
|
||||
parentObject,
|
||||
apiMatrix4,
|
||||
parentObject,
|
||||
grain
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiMatrix4)) {
|
||||
apiMatrix4 = {};
|
||||
}
|
||||
|
||||
GameLib.API.Matrix4.call(
|
||||
this,
|
||||
apiMatrix4.rows[0],
|
||||
|
@ -21,10 +28,9 @@ GameLib.Matrix4 = function(
|
|||
apiMatrix4.rows[3]
|
||||
);
|
||||
|
||||
this.graphics = graphics;
|
||||
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||
parentObject = null;
|
||||
}
|
||||
this.parentObject = parentObject;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||
|
@ -32,53 +38,41 @@ GameLib.Matrix4 = function(
|
|||
}
|
||||
this.grain = grain;
|
||||
|
||||
this.rows[0] = new GameLib.Vector4(
|
||||
this.graphics,
|
||||
this,
|
||||
this.rows[0],
|
||||
grain
|
||||
);
|
||||
|
||||
this.rows[1] = new GameLib.Vector4(
|
||||
this.graphics,
|
||||
this,
|
||||
this.rows[1],
|
||||
grain
|
||||
);
|
||||
|
||||
this.rows[2] = new GameLib.Vector4(
|
||||
this.graphics,
|
||||
this,
|
||||
this.rows[2],
|
||||
grain
|
||||
);
|
||||
|
||||
this.rows[3] = new GameLib.Vector4(
|
||||
this.graphics,
|
||||
this,
|
||||
this.rows[3],
|
||||
grain
|
||||
this.rows = this.rows.map(
|
||||
function(row) {
|
||||
if (row instanceof GameLib.API.Vector4) {
|
||||
return new GameLib.Vector4(
|
||||
this.graphics,
|
||||
row,
|
||||
this,
|
||||
this.grain
|
||||
);
|
||||
} else {
|
||||
console.warn('Attempted conversion of wrong instance');
|
||||
throw new Error('Attempted conversion of wrong instance');
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.forward = new GameLib.Vector4(
|
||||
this.graphics,
|
||||
this,
|
||||
this.forward,
|
||||
grain
|
||||
this,
|
||||
this.grain
|
||||
);
|
||||
|
||||
this.left = new GameLib.Vector4(
|
||||
this.graphics,
|
||||
this,
|
||||
this.left,
|
||||
grain
|
||||
this,
|
||||
this.grain
|
||||
);
|
||||
|
||||
this.up = new GameLib.Vector4(
|
||||
this.graphics,
|
||||
this,
|
||||
this.up,
|
||||
grain
|
||||
this,
|
||||
this.grain
|
||||
);
|
||||
|
||||
this.instance = this.createInstance();
|
||||
|
@ -136,10 +130,9 @@ GameLib.Matrix4.prototype.updateInstance = function() {
|
|||
|
||||
this.createInstance(true);
|
||||
|
||||
if (this.parentObject) {
|
||||
if (this.parentObject.updateInstance) {
|
||||
this.parentObject.updateInstance();
|
||||
}
|
||||
if (this.parentObject &&
|
||||
this.parentObject.updateInstance) {
|
||||
this.parentObject.updateInstance();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -148,12 +141,18 @@ GameLib.Matrix4.prototype.updateInstance = function() {
|
|||
* @returns {*}
|
||||
*/
|
||||
GameLib.Matrix4.prototype.toApiMatrix = function () {
|
||||
return new GameLib.API.Matrix4(
|
||||
this.rows[0].toApiVector(),
|
||||
this.rows[1].toApiVector(),
|
||||
this.rows[2].toApiVector(),
|
||||
this.rows[3].toApiVector()
|
||||
)
|
||||
|
||||
return this.rows.map(
|
||||
function(row) {
|
||||
if (row instanceof GameLib.Vector4) {
|
||||
return row.toApiVector();
|
||||
} else {
|
||||
console.warn('Incompatible conversion to API matrix for vector: ', row);
|
||||
throw new Error('Incompatible conversion to API matrix for a vector');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -166,40 +165,7 @@ GameLib.Matrix4.prototype.toApiMatrix = function () {
|
|||
*/
|
||||
GameLib.Matrix4.FromObjectMatrix = function(graphics, objectMatrix, parentObject) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(objectMatrix)) {
|
||||
return new GameLib.Matrix4(
|
||||
graphics,
|
||||
parentObject,
|
||||
new GameLib.API.Matrix4()
|
||||
)
|
||||
}
|
||||
|
||||
var apiMatrix = new GameLib.API.Matrix4(
|
||||
new GameLib.API.Vector4(
|
||||
objectMatrix.rows[0].x,
|
||||
objectMatrix.rows[0].y,
|
||||
objectMatrix.rows[0].z,
|
||||
objectMatrix.rows[0].w
|
||||
),
|
||||
new GameLib.API.Vector4(
|
||||
objectMatrix.rows[1].x,
|
||||
objectMatrix.rows[1].y,
|
||||
objectMatrix.rows[1].z,
|
||||
objectMatrix.rows[1].w
|
||||
),
|
||||
new GameLib.API.Vector4(
|
||||
objectMatrix.rows[2].x,
|
||||
objectMatrix.rows[2].y,
|
||||
objectMatrix.rows[2].z,
|
||||
objectMatrix.rows[2].w
|
||||
),
|
||||
new GameLib.API.Vector4(
|
||||
objectMatrix.rows[3].x,
|
||||
objectMatrix.rows[3].y,
|
||||
objectMatrix.rows[3].z,
|
||||
objectMatrix.rows[3].w
|
||||
)
|
||||
);
|
||||
var apiMatrix = new GameLib.API.Matrix4.FromObjectMatrix(objectMatrix);
|
||||
|
||||
return new GameLib.Matrix4(
|
||||
graphics,
|
||||
|
@ -208,6 +174,13 @@ GameLib.Matrix4.FromObjectMatrix = function(graphics, objectMatrix, parentObject
|
|||
)
|
||||
};
|
||||
|
||||
/**
|
||||
* Lookat
|
||||
* @param position
|
||||
* @param target
|
||||
* @param up
|
||||
* @returns {GameLib.Matrix4}
|
||||
*/
|
||||
GameLib.Matrix4.prototype.lookAt = function (position, target, up) {
|
||||
|
||||
var pv = new GameLib.API.Vector3(position.x, position.y, position.z);
|
||||
|
@ -256,35 +229,42 @@ GameLib.Matrix4.prototype.lookAt = function (position, target, up) {
|
|||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Identity
|
||||
*/
|
||||
GameLib.Matrix4.prototype.identity = function () {
|
||||
this.rows = [
|
||||
new GameLib.Vector4(
|
||||
this.graphics,
|
||||
this,
|
||||
new GameLib.API.Vector4(1,0,0,0),
|
||||
this,
|
||||
this.grain
|
||||
),
|
||||
new GameLib.Vector4(
|
||||
this.graphics,
|
||||
this,
|
||||
new GameLib.API.Vector4(0,1,0,0),
|
||||
this,
|
||||
this.grain
|
||||
),
|
||||
new GameLib.Vector4(
|
||||
this.graphics,
|
||||
this,
|
||||
new GameLib.API.Vector4(0,0,1,0),
|
||||
this,
|
||||
this.grain
|
||||
),
|
||||
new GameLib.Vector4(
|
||||
this.graphics,
|
||||
this,
|
||||
new GameLib.API.Vector4(0,0,0,1),
|
||||
this,
|
||||
this.grain
|
||||
)
|
||||
];
|
||||
};
|
||||
|
||||
/**
|
||||
* Transpose
|
||||
* @returns {GameLib.Matrix4}
|
||||
*/
|
||||
GameLib.Matrix4.prototype.transpose = function () {
|
||||
|
||||
this.temp[0].x = this.rows[0].x;
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
/**
|
||||
* Runtime mouse for updating instance objects
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param parentObject GameLib.D3.*
|
||||
* @param apiMouse GameLib.API.Mouse
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Mouse = function (graphics, parentObject, apiMouse) {
|
||||
GameLib.Mouse = function (graphics, apiMouse) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
|
||||
|
||||
GameLib.API.Mouse.call(
|
||||
this,
|
||||
apiMouse.id,
|
||||
|
|
|
@ -8,39 +8,39 @@
|
|||
*/
|
||||
GameLib.Quaternion = function (
|
||||
graphics,
|
||||
parentObject,
|
||||
apiQuaternion,
|
||||
parentObject,
|
||||
grain
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiQuaternion)) {
|
||||
apiQuaternion = {};
|
||||
}
|
||||
|
||||
GameLib.API.Quaternion.call(
|
||||
this,
|
||||
apiQuaternion.x,
|
||||
apiQuaternion.y,
|
||||
apiQuaternion.z,
|
||||
apiQuaternion.w,
|
||||
new GameLib.API.Vector3(
|
||||
apiQuaternion.axis.x,
|
||||
apiQuaternion.axis.y,
|
||||
apiQuaternion.axis.z
|
||||
),
|
||||
apiQuaternion.axis,
|
||||
apiQuaternion.angle
|
||||
);
|
||||
|
||||
this.axis = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.axis,
|
||||
0.001
|
||||
);
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||
parentObject = null;
|
||||
}
|
||||
this.parentObject = parentObject;
|
||||
|
||||
this.axis = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this.axis,
|
||||
this,
|
||||
this.grain
|
||||
);
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||
grain = 0.001;
|
||||
}
|
||||
|
@ -68,7 +68,12 @@ GameLib.Quaternion.prototype.createInstance = function(update) {
|
|||
instance.z = this.z;
|
||||
instance.w = this.w;
|
||||
} else {
|
||||
instance = new THREE.Quaternion(this.x, this.y, this.z, this.w);
|
||||
instance = new THREE.Quaternion(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z,
|
||||
this.w
|
||||
);
|
||||
}
|
||||
|
||||
return instance;
|
||||
|
@ -81,7 +86,8 @@ GameLib.Quaternion.prototype.updateInstance = function() {
|
|||
|
||||
this.createInstance(true);
|
||||
|
||||
if (this.parentObject.updateInstance) {
|
||||
if (this.parentObject &&
|
||||
this.parentObject.updateInstance) {
|
||||
this.parentObject.updateInstance();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -6,20 +6,28 @@
|
|||
* @param grain Number
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Vector2 = function (graphics, parentObject, apiVector2, grain) {
|
||||
|
||||
for (var property in apiVector2) {
|
||||
if (apiVector2.hasOwnProperty(property)) {
|
||||
this[property] = apiVector2[property];
|
||||
}
|
||||
}
|
||||
|
||||
GameLib.Utils.Extend(GameLib.Vector2, GameLib.API.Vector2);
|
||||
|
||||
GameLib.Vector2 = function (
|
||||
graphics,
|
||||
apiVector2,
|
||||
parentObject,
|
||||
grain
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiVector2)) {
|
||||
apiVector2 = {};
|
||||
}
|
||||
|
||||
GameLib.Vector2.call(
|
||||
this,
|
||||
apiVector2.x,
|
||||
apiVector2.y
|
||||
);
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||
parentObject = null;
|
||||
}
|
||||
this.parentObject = parentObject;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||
|
@ -30,6 +38,10 @@ GameLib.Vector2 = function (graphics, parentObject, apiVector2, grain) {
|
|||
this.instance = this.createInstance();
|
||||
};
|
||||
|
||||
GameLib.Vector2.prototype = Object.create(GameLib.API.Vector2.prototype);
|
||||
GameLib.Vector2.prototype.constructor = GameLib.Vector2;
|
||||
|
||||
|
||||
/**
|
||||
* Creates an instance vector2
|
||||
* @param update
|
||||
|
@ -44,7 +56,7 @@ GameLib.Vector2.prototype.createInstance = function(update) {
|
|||
instance.x = this.x;
|
||||
instance.y = this.y;
|
||||
} else {
|
||||
instance = new this.graphics.instance.Vector2(this.x, this.y);
|
||||
instance = new THREE.Vector2(this.x, this.y);
|
||||
}
|
||||
|
||||
return instance;
|
||||
|
@ -57,7 +69,8 @@ GameLib.Vector2.prototype.updateInstance = function() {
|
|||
|
||||
this.createInstance(true);
|
||||
|
||||
if (this.parentObject.updateInstance) {
|
||||
if (this.parentObject &&
|
||||
this.parentObject.updateInstance) {
|
||||
this.parentObject.updateInstance();
|
||||
}
|
||||
};
|
||||
|
@ -73,99 +86,209 @@ GameLib.Vector2.prototype.toApiVector = function() {
|
|||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Copy
|
||||
* TODO: Test
|
||||
* @param v optional
|
||||
* @returns {GameLib.Vector2}
|
||||
*/
|
||||
GameLib.Vector2.prototype.copy = function (v) {
|
||||
if (!GameLib.Utils.UndefinedOrNull(v)) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(v)) {
|
||||
|
||||
return new GameLib.Vector2(
|
||||
this.graphics,
|
||||
new GameLib.API.Vector2(
|
||||
this.x,
|
||||
this.y
|
||||
),
|
||||
this.parentObject,
|
||||
this.grain
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
this.x = v.x;
|
||||
this.y = v.y;
|
||||
|
||||
return this;
|
||||
} else {
|
||||
return new GameLib.Vector2(
|
||||
this.x,
|
||||
this.y
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Equals
|
||||
* TODO: Test
|
||||
* @param v
|
||||
* @returns {boolean}
|
||||
*/
|
||||
GameLib.Vector2.prototype.equals = function(v) {
|
||||
return (((this.x == v.x) &&
|
||||
(this.y == v.y)) ||
|
||||
((this.y == v.x) &&
|
||||
(this.x == v.y)));
|
||||
|
||||
if ((this.x == v.x) &&
|
||||
(this.y == v.y)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Add
|
||||
* TODO: Test
|
||||
* @param v
|
||||
*/
|
||||
GameLib.Vector2.prototype.add = function(v) {
|
||||
return new GameLib.Vector2(
|
||||
this.x + v.x,
|
||||
this.y + v.y
|
||||
);
|
||||
|
||||
if (
|
||||
v instanceof GameLib.API.Vector2 ||
|
||||
v instanceof GameLib.API.Vector3 ||
|
||||
v instanceof GameLib.API.Vector4 ||
|
||||
v instanceof GameLib.API.Quaternion
|
||||
) {
|
||||
this.x += v.x;
|
||||
this.y += v.y;
|
||||
} else {
|
||||
console.warn('Could not add Vector2');
|
||||
throw new Error('Could not add Vector2');
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Subtract
|
||||
* TODO: Test
|
||||
* @param v
|
||||
*/
|
||||
GameLib.Vector2.prototype.subtract = function(v) {
|
||||
return new GameLib.Vector2(
|
||||
this.x - v.x,
|
||||
this.y - v.y
|
||||
);
|
||||
|
||||
if (
|
||||
v instanceof GameLib.API.Vector2 ||
|
||||
v instanceof GameLib.API.Vector3 ||
|
||||
v instanceof GameLib.API.Vector4 ||
|
||||
v instanceof GameLib.API.Quaternion
|
||||
) {
|
||||
this.x -= v.x;
|
||||
this.y -= v.y;
|
||||
} else {
|
||||
console.warn('Could not subtract Vector2');
|
||||
throw new Error('Could not subtract Vector2');
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Multiply
|
||||
* TODO: Test
|
||||
* @param v
|
||||
*/
|
||||
GameLib.Vector2.prototype.multiply = function(v) {
|
||||
if (v instanceof GameLib.Vector2) {
|
||||
return new GameLib.Vector2(
|
||||
this.x * v.x,
|
||||
this.y * v.y
|
||||
);
|
||||
} else if (isNumber(v)) {
|
||||
return new GameLib.Vector2(
|
||||
this.x * v,
|
||||
this.y * v
|
||||
);
|
||||
|
||||
if (
|
||||
v instanceof GameLib.API.Vector2 ||
|
||||
v instanceof GameLib.API.Vector3 ||
|
||||
v instanceof GameLib.API.Vector4 ||
|
||||
v instanceof GameLib.API.Quaternion
|
||||
) {
|
||||
this.x *= v.x;
|
||||
this.y *= v.y;
|
||||
} else if (typeof v == 'number') {
|
||||
this.x *= v;
|
||||
this.y *= v;
|
||||
} else {
|
||||
console.warn('Could not multiply Vector2');
|
||||
throw new Error('Could not multiply Vector2');
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Divide
|
||||
* TODO: Test
|
||||
* @param v
|
||||
*/
|
||||
GameLib.Vector2.prototype.divide = function(v) {
|
||||
if (v instanceof GameLib.Vector2) {
|
||||
return new GameLib.Vector2(
|
||||
this.x * (1.0 / v.x),
|
||||
this.y * (1.0 / v.y)
|
||||
);
|
||||
} else if (isNumber(v)) {
|
||||
var invS = 1.0 / v;
|
||||
return new GameLib.Vector2(
|
||||
this.x * invS,
|
||||
this.y * invS
|
||||
);
|
||||
|
||||
if (
|
||||
v instanceof GameLib.API.Vector2 ||
|
||||
v instanceof GameLib.API.Vector3 ||
|
||||
v instanceof GameLib.API.Vector4 ||
|
||||
v instanceof GameLib.API.Quaternion
|
||||
) {
|
||||
this.x *= (1.0 / v.x);
|
||||
this.y *= (1.0 / v.y);
|
||||
} else if (typeof v == 'number') {
|
||||
this.x *= 1.0 / v;
|
||||
this.y *= 1.0 / v;
|
||||
} else {
|
||||
console.warn('Could not divide Vector2');
|
||||
throw new Error('Could not divide Vector2');
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
GameLib.Vector2.prototype.set = function(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
};
|
||||
|
||||
/**
|
||||
* Clamp
|
||||
* TODO: Test
|
||||
* @param min GameLib.API.Vector2
|
||||
* @param max GameLib.API.Vector2
|
||||
* @returns {GameLib.Vector2}
|
||||
*/
|
||||
GameLib.Vector2.prototype.clamp = function(min, max) {
|
||||
return new GameLib.Vector2(
|
||||
Math.max(min.x, Math.min(max.x, this.x)),
|
||||
Math.max(min.y, Math.min(max.y, this.y))
|
||||
|
||||
this.x = Math.max(min.x, Math.min(max.x, this.x));
|
||||
this.y = Math.max(min.y, Math.min(max.y, this.y));
|
||||
|
||||
return this;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Length
|
||||
* TODO: Test
|
||||
* @returns {number}
|
||||
*/
|
||||
GameLib.Vector2.prototype.length = function() {
|
||||
return Math.sqrt(
|
||||
this.x * this.x + this.y * this.y
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.Vector2.prototype.length = function() {
|
||||
return Math.sqrt(this.x * this.x + this.y * this.y);
|
||||
};
|
||||
|
||||
/**
|
||||
* Dot product
|
||||
* TODO: Test
|
||||
* @param v
|
||||
* @returns {number}
|
||||
*/
|
||||
GameLib.Vector2.prototype.dot = function(v) {
|
||||
return this.x * v.x + this.y * v.y;
|
||||
};
|
||||
|
||||
/**
|
||||
* Normalize
|
||||
* TODO: Test
|
||||
*/
|
||||
GameLib.Vector2.prototype.normalize = function() {
|
||||
return this.multiply(1.0 / this.length());
|
||||
};
|
||||
|
||||
/**
|
||||
* TODO: Test
|
||||
* Angle between this vector and origin
|
||||
* @returns {number}
|
||||
*/
|
||||
GameLib.Vector2.prototype.angle = function() {
|
||||
var angle = Math.atan2(this.y, this.x);
|
||||
if ( angle < 0 ) angle += 2 * Math.PI;
|
||||
return angle;
|
||||
};
|
||||
|
||||
/**
|
||||
* Interpolate to v from here
|
||||
* TODO: Test
|
||||
* @param v
|
||||
* @param alpha
|
||||
* @returns {GameLib.Vector2}
|
||||
*/
|
||||
GameLib.Vector2.prototype.lerp = function ( v, alpha ) {
|
||||
return new GameLib.Vector2(
|
||||
this.x + ( v.x - this.x ) * alpha,
|
||||
|
|
|
@ -1,25 +1,34 @@
|
|||
/**
|
||||
* Runtime apiVector3 for updating instance objects
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param parentObject GameLib.D3.*
|
||||
* @param apiVector3 GameLib.API.Vector3
|
||||
* @param parentObject GameLib.*
|
||||
* @param grain Number
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Vector3 = function (graphics, parentObject, apiVector3, grain) {
|
||||
|
||||
for (var property in apiVector3) {
|
||||
if (apiVector3.hasOwnProperty(property)) {
|
||||
this[property] = apiVector3[property];
|
||||
}
|
||||
}
|
||||
|
||||
GameLib.Utils.Extend(GameLib.Vector3, GameLib.API.Vector3);
|
||||
|
||||
GameLib.Vector3 = function (
|
||||
graphics,
|
||||
apiVector3,
|
||||
parentObject,
|
||||
grain
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiVector3)) {
|
||||
apiVector3 = {};
|
||||
}
|
||||
|
||||
GameLib.Vector3.call(
|
||||
this,
|
||||
apiVector3.x,
|
||||
apiVector3.y,
|
||||
apiVector3.z
|
||||
);
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||
parentObject = null;
|
||||
}
|
||||
this.parentObject = parentObject;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||
|
@ -30,6 +39,9 @@ GameLib.Vector3 = function (graphics, parentObject, apiVector3, grain) {
|
|||
this.instance = this.createInstance();
|
||||
};
|
||||
|
||||
GameLib.Vector3.prototype = Object.create(GameLib.API.Vector3.prototype);
|
||||
GameLib.Vector3.prototype.constructor = GameLib.Vector3;
|
||||
|
||||
/**
|
||||
* Creates an instance vector3
|
||||
* @param update
|
||||
|
@ -45,7 +57,11 @@ GameLib.Vector3.prototype.createInstance = function(update) {
|
|||
instance.y = this.y;
|
||||
instance.z = this.z;
|
||||
} else {
|
||||
instance = new THREE.Vector3(this.x, this.y, this.z);
|
||||
instance = new THREE.Vector3(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z
|
||||
);
|
||||
}
|
||||
|
||||
return instance;
|
||||
|
@ -58,7 +74,8 @@ GameLib.Vector3.prototype.updateInstance = function() {
|
|||
|
||||
this.createInstance(true);
|
||||
|
||||
if (this.parentObject.updateInstance) {
|
||||
if (this.parentObject &&
|
||||
this.parentObject.updateInstance) {
|
||||
this.parentObject.updateInstance();
|
||||
}
|
||||
};
|
||||
|
@ -75,17 +92,17 @@ GameLib.Vector3.prototype.toApiVector = function() {
|
|||
};
|
||||
|
||||
/**
|
||||
* Converts runtime vector to API Vector
|
||||
* Creates a new copy of this Vector3
|
||||
*/
|
||||
GameLib.Vector3.prototype.copy = function() {
|
||||
return new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this.parentObject,
|
||||
new GameLib.API.Vector3(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z
|
||||
),
|
||||
this.parentObject,
|
||||
this.grain
|
||||
)
|
||||
};
|
||||
|
|
|
@ -1,12 +1,24 @@
|
|||
/**
|
||||
* Runtime apiVector4 for updating instance objects
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param parentObject GameLib.D3.*
|
||||
* @param apiVector4 GameLib.API.Vector4
|
||||
* @param parentObject GameLib.*
|
||||
* @param grain Number
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Vector4 = function (graphics, parentObject, apiVector4, grain) {
|
||||
GameLib.Vector4 = function (
|
||||
graphics,
|
||||
apiVector4,
|
||||
parentObject,
|
||||
grain
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiVector4)) {
|
||||
apiVector4 = {};
|
||||
}
|
||||
|
||||
GameLib.API.Vector4.call(
|
||||
this,
|
||||
|
@ -16,10 +28,9 @@ GameLib.Vector4 = function (graphics, parentObject, apiVector4, grain) {
|
|||
apiVector4.w
|
||||
);
|
||||
|
||||
this.graphics = graphics;
|
||||
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||
parentObject = null;
|
||||
}
|
||||
this.parentObject = parentObject;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||
|
@ -62,7 +73,8 @@ GameLib.Vector4.prototype.updateInstance = function() {
|
|||
|
||||
this.createInstance(true);
|
||||
|
||||
if (this.parentObject.updateInstance) {
|
||||
if (this.parentObject &&
|
||||
this.parentObject.updateInstance) {
|
||||
this.parentObject.updateInstance();
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue