whole runtime refactoring

beta.r3js.org
Theunis J. Botha 2016-12-02 13:00:56 +01:00
parent 46a00d4fb1
commit 6d3c30fee5
44 changed files with 971 additions and 883 deletions

View File

@ -4,7 +4,7 @@
* @param weight float
* @constructor
*/
GameLib.D3.BoneWeight = function BoneWeight(
GameLib.D3.API.BoneWeight = function BoneWeight(
boneIndex,
weight
) {

View File

@ -8,11 +8,11 @@
* @param quaternion
* @param position
* @param rotation
* @param scale GameLib.D3.Vector3
* @param scale GameLib.D3.API.Vector3
* @param up
* @constructor
*/
GameLib.D3.Bone = function Bone(
GameLib.D3.API.Bone = function Bone(
id,
boneId,
name,
@ -39,27 +39,27 @@ GameLib.D3.Bone = function Bone(
this.parentBoneId = parentBoneId;
if (typeof quaternion == 'undefined') {
quaternion = new GameLib.D3.Vector4();
quaternion = new GameLib.D3.API.Vector4();
}
this.quaternion = quaternion;
if (typeof position == 'undefined') {
position = new GameLib.D3.Vector3(0,0,0);
position = new GameLib.D3.API.Vector3(0,0,0);
}
this.position = position;
if (typeof rotation == 'undefined') {
rotation = new GameLib.D3.Vector3(0,0,0);
rotation = new GameLib.D3.API.Vector3(0,0,0);
}
this.rotation = rotation;
if (typeof scale == 'undefined') {
scale = new GameLib.D3.Vector3(1,1,1);
scale = new GameLib.D3.API.Vector3(1,1,1);
}
this.scale = scale;
if (typeof up == 'undefined') {
up = new GameLib.D3.Vector3(0,1,0);
up = new GameLib.D3.API.Vector3(0,1,0);
}
this.up = up;
};

View File

@ -7,8 +7,8 @@
* @param aspect
* @param near
* @param far
* @param position GameLib.D3.Vector3
* @param lookAt GameLib.D3.Vector3
* @param position GameLib.D3.API.Vector3
* @param lookAt GameLib.D3.API.Vector3
* @param minX
* @param maxX
* @param minY
@ -70,7 +70,7 @@ GameLib.D3.API.Camera = function(
this.far = far;
if (GameLib.D3.Utils.UndefinedOrNull(position)) {
position = new GameLib.D3.Vector3(
position = new GameLib.D3.API.Vector3(
15,
15,
15
@ -79,7 +79,7 @@ GameLib.D3.API.Camera = function(
this.position = position;
if (GameLib.D3.Utils.UndefinedOrNull(lookAt)) {
lookAt = new GameLib.D3.Vector3(
lookAt = new GameLib.D3.API.Vector3(
0,
0,
0

View File

@ -99,12 +99,12 @@ GameLib.D3.API.ComponentInterface = function(
this.camera = camera;
if (GameLib.D3.Utils.UndefinedOrNull(startColor)) {
startColor = new GameLib.D3.Vector3(0, 0, 0);
startColor = new GameLib.D3.API.Vector3(0, 0, 0);
}
this.startColor = startColor;
if (GameLib.D3.Utils.UndefinedOrNull(endColor)) {
endColor = new GameLib.D3.Vector3(1, 1, 1);
endColor = new GameLib.D3.API.Vector3(1, 1, 1);
}
this.endColor = endColor;
@ -119,7 +119,7 @@ GameLib.D3.API.ComponentInterface = function(
this.targetEntity = targetEntity;
if (GameLib.D3.Utils.UndefinedOrNull(targetOffset)) {
targetOffset = new GameLib.D3.Vector3(0, 0, 0);
targetOffset = new GameLib.D3.API.Vector3(0, 0, 0);
}
this.targetOffset = targetOffset;
@ -139,17 +139,17 @@ GameLib.D3.API.ComponentInterface = function(
this.rotationSpeed = rotationSpeed;
if (GameLib.D3.Utils.UndefinedOrNull(positionOffset)) {
positionOffset = new GameLib.D3.Vector3();
positionOffset = new GameLib.D3.API.Vector3();
}
this.positionOffset = positionOffset;
if (GameLib.D3.Utils.UndefinedOrNull(quaternionOffset)) {
quaternionOffset = new GameLib.D3.Vector4();
quaternionOffset = new GameLib.D3.API.Vector4();
}
this.quaternionOffset = quaternionOffset;
if (GameLib.D3.Utils.UndefinedOrNull(scaleOffset)) {
scaleOffset = new GameLib.D3.Vector3();
scaleOffset = new GameLib.D3.API.Vector3();
}
this.scaleOffset = scaleOffset;
@ -179,12 +179,12 @@ GameLib.D3.API.ComponentInterface = function(
this.maxSpeed = maxSpeed;
if (GameLib.D3.Utils.UndefinedOrNull(baseOffset)) {
baseOffset = new GameLib.D3.Vector3();
baseOffset = new GameLib.D3.API.Vector3();
}
this.baseOffset = baseOffset;
if (GameLib.D3.Utils.UndefinedOrNull(maxOffset)) {
maxOffset = new GameLib.D3.Vector3(10, 10, 10);
maxOffset = new GameLib.D3.API.Vector3(10, 10, 10);
}
this.maxOffset = maxOffset;

View File

@ -36,17 +36,17 @@ GameLib.D3.API.Entity = function Entity(
this.ids = ids;
if(GameLib.D3.Utils.UndefinedOrNull(position)) {
position = new GameLib.D3.Vector3();
position = new GameLib.D3.API.Vector3();
}
this.position = position;
if(GameLib.D3.Utils.UndefinedOrNull(quaternion)) {
quaternion = new GameLib.D3.Vector4();
quaternion = new GameLib.D3.API.Vector4();
}
this.quaternion = quaternion;
if(GameLib.D3.Utils.UndefinedOrNull(scale)) {
scale = new GameLib.D3.Vector3(1, 1, 1);
scale = new GameLib.D3.API.Vector3(1, 1, 1);
}
this.scale = scale;

View File

@ -50,7 +50,7 @@ GameLib.D3.API.Light = function(
this.name = name;
if (GameLib.D3.Utils.UndefinedOrNull(color)) {
color = new GameLib.D3.Color(1,1,1,1);
color = new GameLib.D3.API.Color(1,1,1,1);
}
this.color = color;
@ -60,27 +60,27 @@ GameLib.D3.API.Light = function(
this.intensity = intensity;
if (typeof position == 'undefined') {
position = new GameLib.D3.Vector3(0,10,0);
position = new GameLib.D3.API.Vector3(0,10,0);
}
this.position = position;
if (typeof targetPosition == 'undefined') {
targetPosition = new GameLib.D3.Vector3(0,0,0);
targetPosition = new GameLib.D3.API.Vector3(0,0,0);
}
this.targetPosition = targetPosition;
if (typeof quaternion == 'undefined'){
quaternion = new GameLib.D3.Vector4();
quaternion = new GameLib.D3.API.Vector4();
}
this.quaternion = quaternion;
if (typeof rotation == 'undefined'){
rotation = new GameLib.D3.Vector3(0,0,0);
rotation = new GameLib.D3.API.Vector3(0,0,0);
}
this.rotation = rotation;
if (typeof scale == 'undefined'){
scale = new GameLib.D3.Vector3(1,1,1);
scale = new GameLib.D3.API.Vector3(1,1,1);
}
this.scale = scale;

View File

@ -154,7 +154,7 @@ GameLib.D3.API.Material = function(
this.maps = maps;
if (GameLib.D3.Utils.UndefinedOrNull(specular)) {
specular = new GameLib.D3.Color(0.06, 0.06, 0.06, 0.06);
specular = new GameLib.D3.API.Color(0.06, 0.06, 0.06, 0.06);
}
this.specular = specular;
@ -169,12 +169,12 @@ GameLib.D3.API.Material = function(
this.aoMapIntensity = aoMapIntensity;
if (GameLib.D3.Utils.UndefinedOrNull(color)) {
color = new GameLib.D3.Color(1, 1, 1, 1)
color = new GameLib.D3.API.Color(1, 1, 1, 1)
}
this.color = color;
if (GameLib.D3.Utils.UndefinedOrNull(emissive)) {
emissive = new GameLib.D3.Color(0, 0, 0, 0);
emissive = new GameLib.D3.API.Color(0, 0, 0, 0);
}
this.emissive = emissive;

View File

@ -12,10 +12,10 @@
* @param skeleton
* @param skinIndices
* @param skinWeights
* @param position GameLib.D3.Vector3
* @param quaternion GameLib.D3.Vector4
* @param rotation GameLib.D3.Vector3
* @param scale GameLib.D3.Vector3
* @param position GameLib.D3.API.Vector3
* @param quaternion GameLib.D3.API.Vector4
* @param rotation GameLib.D3.API.Vector3
* @param scale GameLib.D3.API.Vector3
* @param up
* @constructor
*/
@ -99,27 +99,27 @@ GameLib.D3.API.Mesh = function(
this.materials = materials;
if (GameLib.D3.Utils.UndefinedOrNull(position)) {
position = new GameLib.D3.Vector3(0,0,0);
position = new GameLib.D3.API.Vector3(0,0,0);
}
this.position = position;
if (GameLib.D3.Utils.UndefinedOrNull(quaternion)) {
quaternion = new GameLib.D3.Vector4();
quaternion = new GameLib.D3.API.Vector4();
}
this.quaternion = quaternion;
if (GameLib.D3.Utils.UndefinedOrNull(rotation)) {
rotation = new GameLib.D3.Vector3(0,0,0);
rotation = new GameLib.D3.API.Vector3(0,0,0);
}
this.rotation = rotation;
if (GameLib.D3.Utils.UndefinedOrNull(scale)) {
scale = new GameLib.D3.Vector3(1,1,1);
scale = new GameLib.D3.API.Vector3(1,1,1);
}
this.scale = scale;
if (GameLib.D3.Utils.UndefinedOrNull(up)) {
up = new GameLib.D3.Vector3(0,1,0);
up = new GameLib.D3.API.Vector3(0,1,0);
}
this.up = up;
};

View File

@ -4,10 +4,10 @@
* @param path String
* @param name String
* @param meshes GameLib.D3.API.Mesh []
* @param quaternion GameLib.D3.Vector4
* @param position GameLib.D3.Vector3
* @param rotation GameLib.D3.Vector3
* @param scale GameLib.D3.Vector3
* @param quaternion GameLib.D3.API.Vector4
* @param position GameLib.D3.API.Vector3
* @param rotation GameLib.D3.API.Vector3
* @param scale GameLib.D3.API.Vector3
* @param parentSceneId
* @param lights GameLib.D3.API.Light[]
* @param worlds GameLib.D3.API.World[]
@ -58,22 +58,22 @@ GameLib.D3.API.Scene = function(
this.meshes = meshes;
if (GameLib.D3.Utils.UndefinedOrNull(quaternion)) {
quaternion = new GameLib.D3.Vector4();
quaternion = new GameLib.D3.API.Vector4();
}
this.quaternion = quaternion;
if (GameLib.D3.Utils.UndefinedOrNull(position)) {
position = new GameLib.D3.Vector3();
position = new GameLib.D3.API.Vector3();
}
this.position = position;
if (GameLib.D3.Utils.UndefinedOrNull(rotation)) {
rotation = new GameLib.D3.Vector3();
rotation = new GameLib.D3.API.Vector3();
}
this.rotation = rotation;
if (GameLib.D3.Utils.UndefinedOrNull(scale)) {
scale = new GameLib.D3.Vector3(1,1,1);
scale = new GameLib.D3.API.Vector3(1,1,1);
}
this.scale = scale;

View File

@ -77,7 +77,7 @@ GameLib.D3.API.Texture = function(
this.wrapT = wrapT;
if (typeof repeat == 'undefined') {
repeat = new GameLib.D3.Vector2(1, 1);
repeat = new GameLib.D3.API.Vector2(1, 1);
}
this.repeat = repeat;
@ -117,7 +117,7 @@ GameLib.D3.API.Texture = function(
this.anisotropy = anisotropy;
if (typeof offset == 'undefined') {
offset = new GameLib.D3.Vector2(0, 0);
offset = new GameLib.D3.API.Vector2(0, 0);
}
this.offset = offset;

View File

@ -24,9 +24,11 @@ GameLib.D3.Camera = function Camera(
this.position
);
this.offsetPosition = new GameLib.D3.Runtime.Vector3(graphics, this, new GameLib.D3.Vector3(0,5,5));
delete this.offsetPosition.updateInstance;
this.lookAt = new GameLib.D3.Runtime.Vector3(
graphics,
this,
this.lookAt
);
this.instance = this.createInstance();

View File

@ -1,27 +0,0 @@
/**
* Color Superset
* @param r
* @param g
* @param b
* @param a
* @constructor
*/
GameLib.D3.Color = function Color(r, g, b, a) {
this.r = r;
this.g = g;
this.b = b;
this.a = a;
};
/**
* Converts the current color to HTML hex format (ex. #ffffff)
* @returns {string}
*/
GameLib.D3.Color.prototype.toHex = function() {
var rf = Math.floor(this.r == 1? 255 : this.r * 256.0).toString(16);
var gf = Math.floor(this.g == 1? 255 : this.g * 256.0).toString(16);
var bf = Math.floor(this.b == 1? 255 : this.b * 256.0).toString(16);
return '#' + rf + gf + bf;
};

View File

@ -16,8 +16,8 @@ GameLib.D3.ComponentColorLerp = function(
// Todo: this should be executed somewhere in game-lib-z, so that we don't execute it on every construction of an object.
GameLib.D3.Utils.Extend(GameLib.D3.ComponentColorLerp, GameLib.D3.ComponentInterface);
this.startColor = startColor || new GameLib.D3.Vector3(0, 0, 0);
this.endColor = endColor || new GameLib.D3.Vector3(1, 1, 1);
this.startColor = startColor || new GameLib.D3.API.Vector3(0, 0, 0);
this.endColor = endColor || new GameLib.D3.API.Vector3(1, 1, 1);
this.lerpSpeed = lerpSpeed || 1.0;
this.lerpTarget = this.endColor;

View File

@ -19,7 +19,7 @@ GameLib.D3.ComponentEntityParent = function ComponentEntityParent(
this.parent = parent;
this.parentEntity = null;
this.originPosition = new GameLib.D3.Vector3(0, 0, 0);
this.originPosition = new GameLib.D3.API.Vector3(0, 0, 0);
// Todo: this should be executed somewhere in game-lib-z, so that we don't execute it on every construction of an object.
GameLib.D3.Utils.Extend(GameLib.D3.ComponentEntityParent, GameLib.D3.ComponentInterface);

View File

@ -23,9 +23,9 @@ GameLib.D3.ComponentEntityPermutation = function ComponentEntityPermutation(
this.parentEntity = null;
this.positionOffset = positionOffset || new GameLib.D3.Vector3(0, 0, 0);
this.quaternionOffset = quaternionOffset || new GameLib.D3.Vector4(0, 0, 0, 1);
this.scaleOffset = scaleOffset || new GameLib.D3.Vector3(0, 0, 0);
this.positionOffset = positionOffset || new GameLib.D3.API.Vector3(0, 0, 0);
this.quaternionOffset = quaternionOffset || new GameLib.D3.API.Vector4(0, 0, 0, 1);
this.scaleOffset = scaleOffset || new GameLib.D3.API.Vector3(0, 0, 0);
// Todo: this should be executed somewhere in game-lib-z, so that we don't execute it on every construction of an object.
GameLib.D3.Utils.Extend(GameLib.D3.ComponentEntityPermutation, GameLib.D3.ComponentInterface);

View File

@ -3,7 +3,7 @@
* @param id
* @param name
* @param targetEntity GameLib.D3.Entity
* @param targetOffset GameLib.D3.Vector3
* @param targetOffset GameLib.D3.API.Vector3
* @param minDistance
* @param moveSpeed
* @constructor
@ -34,7 +34,7 @@ GameLib.D3.ComponentFollow = function ComponentFollow(
this.targetEntity = targetEntity;
if(GameLib.D3.Utils.UndefinedOrNull(targetOffset)) {
targetOffset = new GameLib.D3.Vector3(0, 0, 0);
targetOffset = new GameLib.D3.API.Vector3(0, 0, 0);
}
this.targetOffset = targetOffset;

View File

@ -30,11 +30,11 @@ GameLib.D3.ComponentLookAt = function ComponentLookAt(
this.targetEntity = targetEntity;
if(GameLib.D3.Utils.UndefinedOrNull(targetOffset)) {
targetOffset = new GameLib.D3.Vector3(0, 0, 0);
targetOffset = new GameLib.D3.API.Vector3(0, 0, 0);
}
this.targetOffset = targetOffset;
this.lastTargetQuaternion = new GameLib.D3.Vector4(0, 0, 0, 1);
this.lastTargetQuaternion = new GameLib.D3.API.Vector4(0, 0, 0, 1);
this.rotationSpeed = rotationSpeed || 22.0;
};

View File

@ -23,9 +23,9 @@ GameLib.D3.ComponentMeshPermutation = function ComponentMeshPermutation(
this.parentEntity = null;
this.positionOffset = positionOffset || new GameLib.D3.Vector3(0, 0, 0);
this.quaternionOffset = quaternionOffset || new GameLib.D3.Vector4(0, 0, 0, 1);
this.scaleOffset = scaleOffset || new GameLib.D3.Vector3(0, 0, 0);
this.positionOffset = positionOffset || new GameLib.D3.API.Vector3(0, 0, 0);
this.quaternionOffset = quaternionOffset || new GameLib.D3.API.Vector4(0, 0, 0, 1);
this.scaleOffset = scaleOffset || new GameLib.D3.API.Vector3(0, 0, 0);
// Todo: this should be executed somewhere in game-lib-z, so that we don't execute it on every construction of an object.
GameLib.D3.Utils.Extend(GameLib.D3.ComponentMeshPermutation, GameLib.D3.ComponentInterface);

View File

@ -36,15 +36,15 @@ GameLib.D3.ComponentPathFollowing = function ComponentPathFollowing(
this.maxSpeed = maxSpeed || 10.0;
this.acceleration = acceleration || 2.0;
this.baseOffset = baseOffset || new GameLib.D3.Vector3();
this.maxOffset = maxOffset || new GameLib.D3.Vector3(10, 10, 10);
this.baseOffset = baseOffset || new GameLib.D3.API.Vector3();
this.maxOffset = maxOffset || new GameLib.D3.API.Vector3(10, 10, 10);
this.steeringSpeed = steeringSpeed || 1.0;
//#ifdef RUNTIME__
// runtime code
this.offset = new GameLib.D3.Vector3(); // this one is our destination offset
this.currentOffset = new GameLib.D3.Vector3();
this.offset = new GameLib.D3.API.Vector3(); // this one is our destination offset
this.currentOffset = new GameLib.D3.API.Vector3();
this.currentPathValue = 0.0;
this.currentSpeed = 0.0;
this.direction = 0;

View File

@ -548,10 +548,10 @@ GameLib.D3.ComponentVehicleAIObjectAvoidance.prototype.onUpdate = function(
var cos = avgMoveVector.dot(forward);
var angleRadians = Math.acos(cos);
var steerAngleModifier = GameLib.D3.Vector3.AngleDirection(
var steerAngleModifier = GameLib.D3.API.Vector3.AngleDirection(
forward,
avgMoveVector,
new GameLib.D3.Vector3(
new GameLib.D3.API.Vector3(
0,
1,
0

View File

@ -111,10 +111,10 @@ GameLib.D3.ComponentVehicleAIPathSteering.prototype.onUpdate = function(
var cos = v1v2cpy.dot(forwardcpy);
var angleRadians = Math.acos(cos);
var steerAngleModifier = GameLib.D3.Vector3.AngleDirection(
var steerAngleModifier = GameLib.D3.API.Vector3.AngleDirection(
forwardcpy,
v1v2cpy,
new GameLib.D3.Vector3(
new GameLib.D3.API.Vector3(
0,
1,
0

View File

@ -14,6 +14,37 @@ GameLib.D3.Light = function Light(
}
}
this.color = new GameLib.D3.Runtime.Color(
graphics,
this,
this.color,
0.01
);
this.position = new GameLib.D3.Runtime.Vector3(
graphics,
this,
this.position
);
this.targetPosition = new GameLib.D3.Runtime.Vector3(
graphics,
this,
this.targetPosition
);
this.scale = new GameLib.D3.Runtime.Vector3(
graphics,
this,
this.scale
);
this.quaternion = new GameLib.D3.Runtime.Vector4(
graphics,
this,
this.quaternion
);
this.graphics = graphics;
this.graphics.isNotThreeThrow();
@ -41,8 +72,7 @@ GameLib.D3.Light.prototype.createInstance = function(update) {
instance = this.instance;
}
if ((!instance) ||
(instance && instance.lightType != this.lightType)) {
if (!instance) {
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_AMBIENT) {
instance = new this.graphics.instance.AmbientLight(
@ -108,9 +138,24 @@ GameLib.D3.Light.prototype.createInstance = function(update) {
instance.position.y = this.position.y;
instance.position.z = this.position.z;
instance.rotation.x = this.rotation.x;
instance.rotation.y = this.rotation.y;
instance.rotation.z = this.rotation.z;
instance.scale.x = this.scale.x;
instance.scale.y = this.scale.y;
instance.scale.z = this.scale.z;
if (instance.target) {
instance.target.x = this.targetPosition.x;
instance.target.y = this.targetPosition.y;
instance.target.z = this.targetPosition.z;
}
instance.quaternion.x = this.quaternion.x;
instance.quaternion.y = this.quaternion.y;
instance.quaternion.z = this.quaternion.z;
instance.quaternion.w = this.quaternion.w;
instance.intensity = this.intensity;
instance.color.set(this.color.toHex());
return instance;
};

View File

@ -16,6 +16,24 @@ GameLib.D3.Material = function Material(
}
}
this.specular = new GameLib.D3.Runtime.Color(
graphics,
this,
this.specular
);
this.color = new GameLib.D3.Runtime.Color(
graphics,
this,
this.color
);
this.emissive = new GameLib.D3.Runtime.Color(
graphics,
this,
this.emissive
);
this.graphics = graphics;
this.graphics.isNotThreeThrow();

View File

@ -1,8 +1,8 @@
/**
* Matrix 3 Maths
* @param row0 GameLib.D3.Vector3
* @param row1 GameLib.D3.Vector3
* @param row2 GameLib.D3.Vector3
* @param row0 GameLib.D3.API.Vector3
* @param row1 GameLib.D3.API.Vector3
* @param row2 GameLib.D3.API.Vector3
* @constructor
*/
GameLib.D3.Matrix3 = function(
@ -30,8 +30,8 @@ GameLib.D3.Matrix3 = function(
*/
GameLib.D3.Matrix3.prototype.identity = function () {
this.rows = [
new GameLib.D3.Vector4(1, 0, 0),
new GameLib.D3.Vector4(0, 1, 0),
new GameLib.D3.Vector4(0, 0, 1)
new GameLib.D3.API.Vector4(1, 0, 0),
new GameLib.D3.API.Vector4(0, 1, 0),
new GameLib.D3.API.Vector4(0, 0, 1)
];
};

View File

@ -26,20 +26,20 @@ GameLib.D3.Matrix4 = function(
GameLib.D3.Matrix4.prototype.rotationMatrixX = function (radians) {
this.identity();
this.rows[1] = new GameLib.D3.Vector4(0, Math.cos(radians), -1 * Math.sin(radians), 0);
this.rows[2] = new GameLib.D3.Vector4(0, Math.sin(radians), Math.cos(radians), 0);
this.rows[1] = new GameLib.D3.API.Vector4(0, Math.cos(radians), -1 * Math.sin(radians), 0);
this.rows[2] = new GameLib.D3.API.Vector4(0, Math.sin(radians), Math.cos(radians), 0);
return this;
};
GameLib.D3.Matrix4.prototype.rotationMatrixY = function (radians) {
this.identity();
this.rows[0] = new GameLib.D3.Vector4(
this.rows[0] = new GameLib.D3.API.Vector4(
Math.cos(radians),
0,
Math.sin(radians),
0
);
this.rows[2] = new GameLib.D3.Vector4(
this.rows[2] = new GameLib.D3.API.Vector4(
-1 * Math.sin(radians),
0,
Math.cos(radians),
@ -50,8 +50,8 @@ GameLib.D3.Matrix4.prototype.rotationMatrixY = function (radians) {
GameLib.D3.Matrix4.prototype.rotationMatrixZ = function (radians) {
this.identity();
this.rows[0] = new GameLib.D3.Vector4(Math.cos(radians), -1 * Math.sin(radians), 0, 0);
this.rows[1] = new GameLib.D3.Vector4(Math.sin(radians), Math.cos(radians), 0, 0);
this.rows[0] = new GameLib.D3.API.Vector4(Math.cos(radians), -1 * Math.sin(radians), 0, 0);
this.rows[1] = new GameLib.D3.API.Vector4(Math.sin(radians), Math.cos(radians), 0, 0);
return this;
};
@ -74,15 +74,15 @@ GameLib.D3.Matrix4.prototype.rotateZ = function (radians, point) {
};
GameLib.D3.Matrix4.prototype.multiply = function (mvp) {
if (mvp instanceof GameLib.D3.Vector4) {
return new GameLib.D3.Vector4(
if (mvp instanceof GameLib.D3.API.Vector4) {
return new GameLib.D3.API.Vector4(
this.rows[0].x * mvp.x + this.rows[0].y * mvp.y + this.rows[0].z * mvp.z + this.rows[0].w * mvp.w,
this.rows[1].x * mvp.x + this.rows[1].y * mvp.y + this.rows[1].z * mvp.z + this.rows[1].w * mvp.w,
this.rows[2].x * mvp.x + this.rows[2].y * mvp.y + this.rows[2].z * mvp.z + this.rows[2].w * mvp.w,
this.rows[3].x * mvp.x + this.rows[3].y * mvp.y + this.rows[3].z * mvp.z + this.rows[3].w * mvp.w
);
} else if (mvp instanceof GameLib.D3.Vector3) {
return new GameLib.D3.Vector3(
} else if (mvp instanceof GameLib.D3.API.Vector3) {
return new GameLib.D3.API.Vector3(
this.rows[0].x * mvp.x + this.rows[0].y * mvp.y + this.rows[0].z * mvp.z,
this.rows[1].x * mvp.x + this.rows[1].y * mvp.y + this.rows[1].z * mvp.z,
this.rows[2].x * mvp.x + this.rows[2].y * mvp.y + this.rows[2].z * mvp.z
@ -92,16 +92,16 @@ GameLib.D3.Matrix4.prototype.multiply = function (mvp) {
GameLib.D3.Matrix4.prototype.identity = function () {
this.rows = [
new GameLib.D3.Vector4(1, 0, 0, 0),
new GameLib.D3.Vector4(0, 1, 0, 0),
new GameLib.D3.Vector4(0, 0, 1, 0),
new GameLib.D3.Vector4(0, 0, 0, 1)
new GameLib.D3.API.Vector4(1, 0, 0, 0),
new GameLib.D3.API.Vector4(0, 1, 0, 0),
new GameLib.D3.API.Vector4(0, 0, 1, 0),
new GameLib.D3.API.Vector4(0, 0, 0, 1)
];
};
GameLib.D3.Matrix4.prototype.lookAt = function (position, target, up) {
var pv = new GameLib.D3.Vector3(position.x, position.y, position.z);
var pv = new GameLib.D3.API.Vector3(position.x, position.y, position.z);
var z = pv.subtract(target).normalize();

View File

@ -26,15 +26,15 @@ GameLib.D3.Mesh = function Mesh(
this.needsUpdate = false;
this.offsetRotation = new GameLib.D3.Runtime.Vector3(graphics, this, new GameLib.D3.Vector3(0,0,0));
this.offsetRotation = new GameLib.D3.Runtime.Vector3(graphics, this, new GameLib.D3.API.Vector3(0,0,0));
delete this.offsetRotation.updateInstance;
// this.lookAtPoint = new GameLib.D3.Runtime.Vector3(graphics, this, new GameLib.D3.Vector3(0,0,0));
// this.lookAtPoint = new GameLib.D3.Runtime.Vector3(graphics, this, new GameLib.D3.API.Vector3(0,0,0));
//
// delete this.offsetRotation.updateInstance;
//
// this.offsetRotation = new GameLib.D3.Runtime.Vector3(graphics, this, new GameLib.D3.Vector3(0,0,0));
// this.offsetRotation = new GameLib.D3.Runtime.Vector3(graphics, this, new GameLib.D3.API.Vector3(0,0,0));
//
// delete this.offsetRotation.updateInstance;
@ -340,10 +340,10 @@ GameLib.D3.prototype.invertWindingOrder = function(triangles) {
*/
GameLib.D3.prototype.resetWindingOrder = function(faces, vertices) {
var vertexList = new GameLib.D3.Vector3.Points();
var vertexList = new GameLib.D3.API.Vector3.Points();
for (var v = 0; v < vertices.length; v++) {
vertexList.add(new GameLib.D3.Vector3(
vertexList.add(new GameLib.D3.API.Vector3(
vertices[v].position.x,
vertices[v].position.y,
vertices[v].position.z
@ -379,7 +379,7 @@ GameLib.D3.prototype.resetWindingOrder = function(faces, vertices) {
for (var i = 0; i < triangles.length; i++) {
if (
GameLib.D3.Vector3.clockwise(
GameLib.D3.API.Vector3.clockwise(
vertices[triangles[i].v0].position,
vertices[triangles[i].v1].position,
vertices[triangles[i].v2].position,
@ -420,7 +420,7 @@ GameLib.D3.prototype.resetWindingOrder = function(faces, vertices) {
* if neighbor_tria exists and neighbor_tria not in processed:
* to_process add (neighbor_tria, edge opposite oriented (BA))
* @param faces GameLib.D3.TriangleFace[]
* @param orientationEdge GameLib.D3.Vector2
* @param orientationEdge GameLib.D3.API.Vector2
* @returns {Array}
*/
GameLib.D3.fixWindingOrder = function(faces, orientationEdge) {
@ -444,7 +444,7 @@ GameLib.D3.fixWindingOrder = function(faces, orientationEdge) {
/**
* Returns a neighbouring triangle on a specific edge - preserving the edge orientation
* @param edge GameLib.D3.Vector2
* @param edge GameLib.D3.API.Vector2
* @param faces GameLib.D3.TriangleFace[]
* @param currentTriangle
* @returns {*}
@ -530,15 +530,15 @@ GameLib.D3.fixWindingOrder = function(faces, orientationEdge) {
processed.push(triangleEdge);
var edges = [
new GameLib.D3.Vector2(
new GameLib.D3.API.Vector2(
triangleEdge.triangle.v0,
triangleEdge.triangle.v1
),
new GameLib.D3.Vector2(
new GameLib.D3.API.Vector2(
triangleEdge.triangle.v1,
triangleEdge.triangle.v2
),
new GameLib.D3.Vector2(
new GameLib.D3.API.Vector2(
triangleEdge.triangle.v2,
triangleEdge.triangle.v0
)
@ -589,10 +589,10 @@ GameLib.D3.fixPolyZPlane = function(verticesFlat, grain) {
var vertices = [];
var points = new GameLib.D3.Vector4.Points();
var points = new GameLib.D3.API.Vector4.Points();
for (var i = 0; i < verticesFlat.length; i += 3) {
points.add(new GameLib.D3.Vector3(
points.add(new GameLib.D3.API.Vector3(
verticesFlat[i],
verticesFlat[i + 1],
verticesFlat[i + 2]

View File

@ -2,7 +2,7 @@
* Contains a Poly vertex data structure
* @param localIndex
* @param mvertIndex
* @param uv GameLib.D3.Vector2
* @param uv GameLib.D3.API.Vector2
* @param materialIndex
* @param edgeIndex
* @constructor

View File

@ -38,10 +38,10 @@ GameLib.D3.RigidBody = function(
shape
) {
this.id = GameLib.D3.Tools.RandomId();
this.position = position || new GameLib.D3.Vector3();
this.velocity = velocity || new GameLib.D3.Vector3();
this.angularVelocity = angularVelocity || new GameLib.D3.Vector3();
this.quaternion = quaternion || new GameLib.D3.Vector4(0, 0, 0, 1);
this.position = position || new GameLib.D3.API.Vector3();
this.velocity = velocity || new GameLib.D3.API.Vector3();
this.angularVelocity = angularVelocity || new GameLib.D3.API.Vector3();
this.quaternion = quaternion || new GameLib.D3.API.Vector4(0, 0, 0, 1);
this.mass = typeof mass == "undefined" ? 0 : mass;
this.friction = typeof friction == "undefined" ? 5 : friction;
this.linearDamping = typeof linearDamping == "undefined" ? 0.01 : linearDamping;
@ -111,8 +111,8 @@ GameLib.D3.RigidBody.prototype.createInstance = function() {
/**
* Adds a shape to this rigid body
* @param shape GameLib.D3.Shape
* @param offset GameLib.D3.Vector3
* @param orientation GameLib.D3.Vector4
* @param offset GameLib.D3.API.Vector3
* @param orientation GameLib.D3.API.Vector4
* @constructor
*/
GameLib.D3.RigidBody.prototype.addShape = function(
@ -121,11 +121,11 @@ GameLib.D3.RigidBody.prototype.addShape = function(
orientation
) {
if (!offset || typeof offset == 'undefined') {
offset = new GameLib.D3.Vector3(0,0,0);
offset = new GameLib.D3.API.Vector3(0,0,0);
}
if (!orientation || typeof orientation == 'undefined') {
orientation = new GameLib.D3.Vector4(0,0,0,1);
orientation = new GameLib.D3.API.Vector4(0,0,0,1);
}
this.instance.addShape(

View File

@ -1,9 +1,9 @@
/**
* Rigid Wheel superset
* @param body GameLib.D3.RigidBody
* @param position GameLib.D3.Vector3
* @param axis GameLib.D3.Vector3
* @param direction GameLib.D3.Vector3
* @param position GameLib.D3.API.Vector3
* @param axis GameLib.D3.API.Vector3
* @param direction GameLib.D3.API.Vector3
* @constructor
*/
GameLib.D3.RigidWheel = function(

View File

@ -2,7 +2,7 @@
* Runtime color for updating instance objects
* @param graphics GameLib.D3.Graphics
* @param parentObject GameLib.D3.*
* @param color GameLib.D3.Color
* @param color GameLib.D3.API.Color
* @param grain Number
* @constructor
*/
@ -14,7 +14,7 @@ GameLib.D3.Runtime.Color = function RuntimeColor(graphics, parentObject, color,
}
}
GameLib.D3.Utils.Extend(GameLib.D3.Runtime.Color, GameLib.D3.Color);
GameLib.D3.Utils.Extend(GameLib.D3.Runtime.Color, GameLib.D3.API.Color);
this.graphics = graphics;
@ -44,9 +44,8 @@ GameLib.D3.Runtime.Color.prototype.createInstance = function(update) {
instance.r = this.r;
instance.g = this.g;
instance.b = this.b;
instance.a = this.a;
} else {
instance = new this.graphics.instance.Color(this.r, this.g, this.b, this.a);
instance = new this.graphics.instance.Color(this.r, this.g, this.b);
}
return instance;
@ -75,4 +74,53 @@ GameLib.D3.Runtime.Color.prototype.toApiColor = function() {
this.b,
this.a
);
};
/**
* Converts the current color to HTML hex format (ex. #ffffff)
* @returns {string}
*/
GameLib.D3.Runtime.Color.prototype.toHex = function() {
if (this.r < 0) {
this.r = 0;
}
if (this.g < 0) {
this.g = 0;
}
if (this.b < 0) {
this.b = 0;
}
if (this.r > 1) {
this.r = 1;
}
if (this.g > 1) {
this.g = 1;
}
if (this.b > 1) {
this.b = 1;
}
var rf = Math.floor(this.r >= 1? 255 : this.r * 256.0).toString(16);
var gf = Math.floor(this.g >= 1? 255 : this.g * 256.0).toString(16);
var bf = Math.floor(this.b >= 1? 255 : this.b * 256.0).toString(16);
if (rf.length < 2) {
rf = '0' + rf;
}
if (gf.length < 2) {
gf = '0' + gf;
}
if (bf.length < 2) {
bf = '0' + bf;
}
return '#' + rf + gf + bf;
};

View File

@ -2,7 +2,7 @@
* Runtime vector2 for updating instance objects
* @param graphics GameLib.D3.Graphics
* @param parentObject GameLib.D3.*
* @param vector2 GameLib.D3.Vector2
* @param vector2 GameLib.D3.API.Vector2
* @param grain Number
* @constructor
*/
@ -14,7 +14,7 @@ GameLib.D3.Runtime.Vector2 = function RuntimeVector2(graphics, parentObject, vec
}
}
GameLib.D3.Utils.Extend(GameLib.D3.Runtime.Vector2, GameLib.D3.Vector2);
GameLib.D3.Utils.Extend(GameLib.D3.Runtime.Vector2, GameLib.D3.API.Vector2);
this.graphics = graphics;
@ -71,4 +71,109 @@ GameLib.D3.Runtime.Vector2.prototype.toApiVector = function() {
this.x,
this.y
);
};
GameLib.D3.Runtime.Vector2 = function Vector2(x, y) {
this.x = x || 0;
this.y = y || 0;
};
GameLib.D3.Runtime.Vector2.prototype.copy = function (v) {
if (!GameLib.D3.Utils.UndefinedOrNull(v)) {
this.x = v.x;
this.y = v.y;
return this;
} else {
return new GameLib.D3.Runtime.Vector2(
this.x,
this.y
);
}
};
GameLib.D3.Runtime.Vector2.prototype.equals = function(v) {
return (((this.x == v.x) &&
(this.y == v.y)) ||
((this.y == v.x) &&
(this.x == v.y)));
};
GameLib.D3.Runtime.Vector2.prototype.add = function(v) {
return new GameLib.D3.Runtime.Vector2(
this.x + v.x,
this.y + v.y
);
};
GameLib.D3.Runtime.Vector2.prototype.subtract = function(v) {
return new GameLib.D3.Runtime.Vector2(
this.x - v.x,
this.y - v.y
);
};
GameLib.D3.Runtime.Vector2.prototype.multiply = function(v) {
if (v instanceof GameLib.D3.Runtime.Vector2) {
return new GameLib.D3.Runtime.Vector2(
this.x * v.x,
this.y * v.y
);
} else if (isNumber(v)) {
return new GameLib.D3.Runtime.Vector2(
this.x * v,
this.y * v
);
}
};
GameLib.D3.Runtime.Vector2.prototype.divide = function(v) {
if (v instanceof GameLib.D3.Runtime.Vector2) {
return new GameLib.D3.Runtime.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.D3.Runtime.Vector2(
this.x * invS,
this.y * invS
);
}
};
GameLib.D3.Runtime.Vector2.prototype.set = function(x, y) {
this.x = x;
this.y = y;
};
GameLib.D3.Runtime.Vector2.prototype.clamp = function(min, max) {
return new GameLib.D3.Runtime.Vector2(
Math.max(min.x, Math.min(max.x, this.x)),
Math.max(min.y, Math.min(max.y, this.y))
);
};
GameLib.D3.Runtime.Vector2.prototype.length = function() {
return Math.sqrt(this.x * this.x + this.y * this.y);
};
GameLib.D3.Runtime.Vector2.prototype.dot = function(v) {
return this.x * v.x + this.y * v.y;
};
GameLib.D3.Runtime.Vector2.prototype.normalize = function() {
return this.multiply(1.0 / this.length());
};
GameLib.D3.Runtime.Vector2.prototype.angle = function() {
var angle = Math.atan2(this.y, this.x);
if ( angle < 0 ) angle += 2 * Math.PI;
return angle;
};
GameLib.D3.Runtime.Vector2.prototype.lerp = function ( v, alpha ) {
return new GameLib.D3.Runtime.Vector2(
this.x + ( v.x - this.x ) * alpha,
this.y + ( v.y - this.y ) * alpha
);
};

View File

@ -2,7 +2,7 @@
* Runtime vector3 for updating instance objects
* @param graphics GameLib.D3.Graphics
* @param parentObject GameLib.D3.*
* @param vector3 GameLib.D3.Vector3
* @param vector3 GameLib.D3.API.Vector3
* @param grain Number
* @constructor
*/
@ -14,7 +14,7 @@ GameLib.D3.Runtime.Vector3 = function RuntimeVector3(graphics, parentObject, vec
}
}
GameLib.D3.Utils.Extend(GameLib.D3.Runtime.Vector3, GameLib.D3.Vector3);
GameLib.D3.Utils.Extend(GameLib.D3.Runtime.Vector3, GameLib.D3.API.Vector3);
this.graphics = graphics;
@ -73,4 +73,238 @@ GameLib.D3.Runtime.Vector3.prototype.toApiVector = function() {
this.y,
this.z
);
};
GameLib.D3.Runtime.Vector3.prototype.subtract = function (v) {
return new GameLib.D3.Runtime.Vector3(
this.x - v.x,
this.y - v.y,
this.z - v.z
);
};
GameLib.D3.Runtime.Vector3.prototype.sub = function (v) {
return new GameLib.D3.Runtime.Vector3(
this.x - v.x,
this.y - v.y,
this.z - v.z
);
};
GameLib.D3.Runtime.Vector3.prototype.cross = function (v) {
return new GameLib.D3.Runtime.Vector3(
this.y * v.z - this.z * v.y,
this.z * v.x - this.x * v.z,
this.x * v.y - this.y * v.x
);
};
GameLib.D3.Runtime.Vector3.clockwise = function (u, v, w, viewPoint) {
var normal = GameLib.D3.Runtime.Vector3.normal(u, v, w);
var uv = u.copy();
var winding = normal.dot(uv.subtract(viewPoint));
return (winding > 0);
};
GameLib.D3.Runtime.Vector3.normal = function (u, v, w) {
var vv = v.copy();
var wv = w.copy();
return vv.subtract(u).cross(wv.subtract(u));
};
GameLib.D3.Runtime.Vector3.prototype.lookAt = function (at, up) {
var lookAtMatrix = GameLib.D3.Matrix4.lookAt(this, at, up);
return this.multiply(lookAtMatrix);
};
GameLib.D3.Runtime.Vector3.prototype.translate = function (v) {
this.x += v.x;
this.y += v.y;
this.z += v.z;
return this;
};
GameLib.D3.Runtime.Vector3.prototype.add = function (v) {
return new GameLib.D3.Runtime.Vector3(
this.x + v.x,
this.y + v.y,
this.z + v.z
);
};
GameLib.D3.Runtime.Vector3.prototype.squared = function () {
return this.x * this.x + this.y * this.y + this.z * this.z;
};
GameLib.D3.Runtime.Vector3.prototype.copy = function () {
return new GameLib.D3.Runtime.Vector3(
this.x,
this.y,
this.z
);
};
GameLib.D3.Runtime.Vector3.prototype.set = function (x, y, z) {
this.x = x;
this.y = y;
this.z = z;
};
GameLib.D3.Runtime.Vector3.prototype.lerp = function ( v, alpha ) {
return new GameLib.D3.Runtime.Vector3(
this.x + ( v.x - this.x ) * alpha,
this.y + ( v.y - this.y ) * alpha,
this.z + ( v.z - this.z ) * alpha
);
};
GameLib.D3.Runtime.Vector3.prototype.distanceTo = function(v) {
var dx = this.x - v.x,
dy = this.y - v.y,
dz = this.z - v.z;
return Math.sqrt(dx * dx + dy * dy + dz * dz);
};
/**
* @return {number}
*/
GameLib.D3.Runtime.Vector3.AngleDirection = function(forward, directionToCheck, up) {
var perp = forward.cross(directionToCheck);
var dir = perp.dot(up);
if (dir > 0.0) {
return 1.0;
} else if (dir < 0.0) {
return -1.0;
} else {
return 0.0;
}
};
GameLib.D3.Runtime.Vector3.prototype.multiply = function (s) {
if (s instanceof GameLib.D3.Runtime.Vector3) {
return new GameLib.D3.Runtime.Vector3(
this.x * s.x,
this.y * s.y,
this.z * s.z
)
} else if (s instanceof GameLib.D3.Matrix4) {
var x = s.rows[0].x * this.x + s.rows[0].y * this.y + s.rows[0].z * this.z + s.rows[0].w;
var y = s.rows[1].x * this.x + s.rows[1].y * this.y + s.rows[1].z * this.z + s.rows[1].w;
var z = s.rows[2].x * this.x + s.rows[2].y * this.y + s.rows[2].z * this.z + s.rows[2].w;
return new GameLib.D3.Runtime.Vector3(
x,
y,
z
);
} else if (s instanceof GameLib.D3.Matrix3) {
var x = s.rows[0].x * this.x + s.rows[0].y * this.y + s.rows[0].z * this.z;
var y = s.rows[1].x * this.x + s.rows[1].y * this.y + s.rows[1].z * this.z;
var z = s.rows[2].x * this.x + s.rows[2].y * this.y + s.rows[2].z * this.z;
return new GameLib.D3.Runtime.Vector3(
x,
y,
z
);
} else if(!isNaN(parseFloat(s)) && isFinite(s)) {
return new GameLib.D3.Runtime.Vector3(
this.x * s,
this.y * s,
this.z * s
);
} else {
console.log("functionality not implemented - please do this");
throw new Error("not implemented");
return this;
}
};
GameLib.D3.Runtime.Vector3.prototype.dot = function (v) {
return (this.x * v.x) + (this.y * v.y) + (this.z * v.z);
};
GameLib.D3.Runtime.Vector3.prototype.normalize = function () {
var EPSILON = 0.000001;
var v2 = this.squared();
if (v2 < EPSILON) {
return this; //do nothing for zero vector
}
var invLength = 1.0 / Math.sqrt(v2);
return new GameLib.D3.Runtime.Vector3(
this.x * invLength,
this.y * invLength,
this.z * invLength
);
};
GameLib.D3.Runtime.Vector3.prototype.clone = function () {
return new GameLib.D3.Runtime.Vector3(
this.x,
this.y,
this.z
);
};
GameLib.D3.Runtime.Vector3.prototype.applyQuaternion = function(q) {
var x = this.x, y = this.y, z = this.z;
var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
// calculate quat * vector
var ix = qw * x + qy * z - qz * y;
var iy = qw * y + qz * x - qx * z;
var iz = qw * z + qx * y - qy * x;
var iw = - qx * x - qy * y - qz * z;
// calculate result * inverse quat
return new GameLib.D3.Runtime.Vector3(
ix * qw + iw * - qx + iy * - qz - iz * - qy,
iy * qw + iw * - qy + iz * - qx - ix * - qz,
iz * qw + iw * - qz + ix * - qy - iy * - qx
);
};
GameLib.D3.Runtime.Vector3.prototype.clamp = function(min, max) {
this.x = Math.max( min.x, Math.min( max.x, this.x ) );
this.y = Math.max( min.y, Math.min( max.y, this.y ) );
this.z = Math.max( min.z, Math.min( max.z, this.z ) );
return this;
};
GameLib.D3.Runtime.Vector3.prototype.negate = function() {
this.x = -this.x;
this.y = -this.y;
this.z = -this.z;
return this;
};
GameLib.D3.Runtime.Vector3.prototype.length = function() {
return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
};
GameLib.D3.Runtime.Vector3.prototype.reflect = function(normal) {
return this.sub( v1.copy( normal ).multiply( 2 * this.dot( normal ) ) );
};
GameLib.D3.Runtime.Vector3.prototype.angleTo = function (v) {
var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
return Math.acos( exports.Math.clamp( theta, - 1, 1 ) );
};

View File

@ -2,7 +2,7 @@
* Runtime vector4 for updating instance objects
* @param graphics GameLib.D3.Graphics
* @param parentObject GameLib.D3.*
* @param vector4 GameLib.D3.Vector4
* @param vector4 GameLib.D3.API.Vector4
* @param grain Number
* @constructor
*/
@ -14,7 +14,7 @@ GameLib.D3.Runtime.Vector4 = function RuntimeVector4(graphics, parentObject, vec
}
}
GameLib.D3.Utils.Extend(GameLib.D3.Runtime.Vector4, GameLib.D3.Vector4);
GameLib.D3.Utils.Extend(GameLib.D3.Runtime.Vector4, GameLib.D3.API.Vector4);
this.graphics = graphics;
@ -75,4 +75,328 @@ GameLib.D3.Runtime.Vector4.prototype.toApiVector = function() {
this.z,
this.w
);
};
};
GameLib.D3.Runtime.Vector4 = function Vector4(x, y, z, w) {
this.x = 0;
this.y = 0;
this.z = 0;
this.w = 1;
if (x) {
this.x = x;
}
if (y) {
this.y = y;
}
if (z) {
this.z = z;
}
if (w) {
this.w = w;
}
};
GameLib.D3.Runtime.Vector4.prototype.translate = function (v) {
this.x += v.x;
this.y += v.y;
this.z += v.z;
return this;
};
GameLib.D3.Runtime.Vector4.prototype.copy = function () {
return new GameLib.D3.Runtime.Vector4(
this.x,
this.y,
this.z,
this.w
);
};
GameLib.D3.Runtime.Vector4.prototype.multiply = function (s) {
if (s instanceof GameLib.D3.API.Vector3) {
this.x *= s.x;
this.y *= s.y;
this.z *= s.z;
} else if (s instanceof GameLib.D3.Matrix4) {
var x = s.rows[0].x * this.x + s.rows[0].y * this.y + s.rows[0].z * this.z + s.rows[0].w * this.w;
var y = s.rows[1].x * this.x + s.rows[1].y * this.y + s.rows[1].z * this.z + s.rows[1].w * this.w;
var z = s.rows[2].x * this.x + s.rows[2].y * this.y + s.rows[2].z * this.z + s.rows[2].w * this.w;
var w = s.rows[3].x * this.x + s.rows[3].y * this.y + s.rows[3].z * this.z + s.rows[3].w * this.w;
this.x = x;
this.y = y;
this.z = z;
this.w = w;
} else {
console.log("functionality not implemented - please do this");
throw new Error("not implemented");
}
};
GameLib.D3.Runtime.Vector4.prototype.normalize = function () {
// note - leave w untouched
var EPSILON = 0.000001;
var v2 = this.x * this.x + this.y * this.y + this.z * this.z;
if (v2 < EPSILON) {
return this; //do nothing for zero vector
}
var invLength = 1 / Math.sqrt(v2);
this.x *= invLength;
this.y *= invLength;
this.z *= invLength;
return this;
};
GameLib.D3.Runtime.Vector4.prototype.subtract = function (v) {
if (v instanceof GameLib.D3.API.Vector3) {
this.x -= v.x;
this.y -= v.y;
this.z -= v.z;
}
if (v instanceof GameLib.D3.Runtime.Vector4) {
this.x -= v.x;
this.y -= v.y;
this.z -= v.z;
this.w -= v.w;
}
return this;
};
GameLib.D3.Runtime.Vector4.Points = function () {
this.vectors = [];
};
GameLib.D3.Runtime.Vector4.Points.prototype.add = function (vector) {
if (vector instanceof GameLib.D3.API.Vector3) {
vector = new GameLib.D3.Runtime.Vector4(
vector.x,
vector.y,
vector.z,
1
)
}
if (!vector instanceof GameLib.D3.Runtime.Vector4) {
console.warn("Vector needs to be of type Vector4");
throw new Error("Vector needs to be of type Vector4");
}
this.vectors.push(vector);
return this;
};
GameLib.D3.Runtime.Vector4.Points.prototype.copy = function () {
var vectors = [];
for (var i = 0; i < this.vectors.length; i++) {
vectors.push(this.vectors[i].copy());
}
return vectors;
};
GameLib.D3.Runtime.Vector4.Points.prototype.maximizeXDistance = function (grain) {
// console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2));
var multiplier = 0;
var rotationMatrixY = new GameLib.D3.Matrix4().rotationMatrixY(grain);
var totalRadians = 0;
var backupVectors = this.copy();
var maxXDistance = 0;
for (var i = 0; i < Math.PI * 2; i += grain) {
multiplier++;
for (var j = 0; j < this.vectors.length; j++) {
this.vectors[j] = rotationMatrixY.multiply(this.vectors[j]);
}
var distances = this.distances();
if (distances.x > maxXDistance) {
maxXDistance = distances.x;
totalRadians = multiplier * grain;
}
}
this.vectors = backupVectors;
// console.log("distance: " + maxXDistance + " radians : " + totalRadians);
var maxRotationMatrix = new GameLib.D3.Matrix4().rotationMatrixY(totalRadians);
for (var k = 0; k < this.vectors.length; k++) {
this.vectors[k] = maxRotationMatrix.multiply(this.vectors[k]);
}
// console.log("vectors (after): " + JSON.stringify(this.vectors, null, 2));
};
GameLib.D3.Runtime.Vector4.Points.prototype.maximizeYDistance = function (grain) {
// console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2));
var multiplier = 0;
var rotationMatrixX = new GameLib.D3.Matrix4().rotationMatrixX(grain);
var totalRadians = 0;
var backupVectors = this.copy();
var maxYDistance = 0;
for (var i = 0; i < Math.PI * 2; i += grain) {
multiplier++;
for (var j = 0; j < this.vectors.length; j++) {
this.vectors[j] = rotationMatrixX.multiply(this.vectors[j]);
}
var distances = this.distances();
if (distances.y > maxYDistance) {
maxYDistance = distances.y;
totalRadians = multiplier * grain;
}
}
this.vectors = backupVectors;
// console.log("distance: " + maxYDistance + " radians : " + totalRadians);
var maxRotationMatrix = new GameLib.D3.Matrix4().rotationMatrixX(totalRadians);
for (var k = 0; k < this.vectors.length; k++) {
this.vectors[k] = maxRotationMatrix.multiply(this.vectors[k]);
}
// console.log("vectors (after): " + JSON.stringify(this.vectors, null, 2));
};
GameLib.D3.Runtime.Vector4.Points.prototype.lookAt = function (at, up) {
var polyCenter = this.average();
console.log("poly center : " + JSON.stringify(polyCenter));
var lookAtMatrix = new GameLib.D3.Matrix4().lookAt(polyCenter, at, up);
lookAtMatrix.rows[0] = new GameLib.D3.Runtime.Vector4(1, 0, 0, 0);
lookAtMatrix.rows[1] = new GameLib.D3.Runtime.Vector4(0, 0, 1, 0);
lookAtMatrix.rows[2] = new GameLib.D3.Runtime.Vector4(0, 1, 0, 0);
console.log("look at matrix : " + JSON.stringify(lookAtMatrix, null, 2));
for (var i = 0; i < this.vectors.length; i++) {
console.log("vector " + i + " (before): " + JSON.stringify(this.vectors[i]));
this.vectors[i] = lookAtMatrix.multiply(this.vectors[i]);
console.log("vector " + i + " (after) : " + JSON.stringify(this.vectors[i]));
}
};
GameLib.D3.Runtime.Vector4.Points.prototype.distances = function () {
var minX = this.vectors[0].x;
var minY = this.vectors[0].y;
var minZ = this.vectors[0].z;
var maxX = this.vectors[0].x;
var maxY = this.vectors[0].y;
var maxZ = this.vectors[0].z;
for (var i = 0; i < this.vectors.length; i++) {
if (this.vectors[i].x < minX) {
minX = this.vectors[i].x;
}
if (this.vectors[i].y < minY) {
minY = this.vectors[i].y;
}
if (this.vectors[i].z < minZ) {
minZ = this.vectors[i].z;
}
if (this.vectors[i].x > maxX) {
maxX = this.vectors[i].x;
}
if (this.vectors[i].y > maxY) {
maxY = this.vectors[i].y;
}
if (this.vectors[i].z > maxZ) {
maxZ = this.vectors[i].z;
}
}
return new GameLib.D3.API.Vector3(
Math.abs(maxX - minX),
Math.abs(maxY - minY),
Math.abs(maxY - minZ)
)
};
GameLib.D3.Runtime.Vector4.Points.prototype.average = function () {
var averageX = 0;
var averageY = 0;
var averageZ = 0;
for (var i = 0; i < this.vectors.length; i++) {
averageX += this.vectors[i].x;
averageY += this.vectors[i].y;
averageZ += this.vectors[i].z;
}
return new GameLib.D3.API.Vector3(
averageX / this.vectors.length,
averageY / this.vectors.length,
averageZ / this.vectors.length
);
};
GameLib.D3.Runtime.Vector4.Points.prototype.negate = function () {
for (var i = 0; i < this.vectors.length; i++) {
this.vectors[i].x *= -1;
this.vectors[i].y *= -1;
this.vectors[i].z *= -1;
}
return this;
};
GameLib.D3.Runtime.Vector4.Points.prototype.toOrigin = function () {
var distanceFromOrigin = this.average().negate();
for (var i = 0; i < this.vectors.length; i++) {
this.vectors[i].translate(distanceFromOrigin);
}
};

View File

@ -131,35 +131,35 @@ GameLib.D3.Scene.LoadScene = function(
apiLight.id,
apiLight.lightType,
apiLight.name,
new GameLib.D3.Color(
new GameLib.D3.API.Color(
apiLight.color.r,
apiLight.color.g,
apiLight.color.b,
apiLight.color.a
),
apiLight.intensity,
new GameLib.D3.Vector3(
new GameLib.D3.API.Vector3(
apiLight.position.x,
apiLight.position.y,
apiLight.position.z
),
new GameLib.D3.Vector3(
new GameLib.D3.API.Vector3(
apiLight.targetPosition.x,
apiLight.targetPosition.y,
apiLight.targetPosition.z
),
new GameLib.D3.Vector4(
new GameLib.D3.API.Vector4(
apiLight.quaternion.x,
apiLight.quaternion.y,
apiLight.quaternion.z,
apiLight.quaternion.w
),
new GameLib.D3.Vector3(
new GameLib.D3.API.Vector3(
apiLight.rotation.x,
apiLight.rotation.y,
apiLight.rotation.z
),
new GameLib.D3.Vector3(
new GameLib.D3.API.Vector3(
apiLight.scale.x,
apiLight.scale.y,
apiLight.scale.z
@ -200,7 +200,7 @@ GameLib.D3.Scene.LoadScene = function(
apiMaterial.side,
apiMaterial.transparent,
GameLib.D3.API.TextureMapTemplate(),
new GameLib.D3.Color(
new GameLib.D3.API.Color(
apiMaterial.specular.r,
apiMaterial.specular.g,
apiMaterial.specular.b,
@ -208,13 +208,13 @@ GameLib.D3.Scene.LoadScene = function(
),
apiMaterial.lightMapIntensity,
apiMaterial.aoMapIntensity,
new GameLib.D3.Color(
new GameLib.D3.API.Color(
apiMaterial.color.r,
apiMaterial.color.g,
apiMaterial.color.b,
apiMaterial.color.a
),
new GameLib.D3.Color(
new GameLib.D3.API.Color(
apiMaterial.emissive.r,
apiMaterial.emissive.g,
apiMaterial.emissive.b,
@ -286,7 +286,7 @@ GameLib.D3.Scene.LoadScene = function(
apiTexture.imagePath,
apiTexture.wrapS,
apiTexture.wrapT,
new GameLib.D3.Vector2(
new GameLib.D3.API.Vector2(
apiTexture.repeat.x,
apiTexture.repeat.y
),
@ -297,7 +297,7 @@ GameLib.D3.Scene.LoadScene = function(
apiTexture.minFilter,
apiTexture.textureType,
apiTexture.anisotropy,
new GameLib.D3.Vector2(
new GameLib.D3.API.Vector2(
apiTexture.offset.x,
apiTexture.offset.y
),
@ -314,17 +314,6 @@ GameLib.D3.Scene.LoadScene = function(
imageFactory
);
texture.offset = new GameLib.D3.Runtime.Vector2(
graphics,
texture,
texture.offset
);
texture.repeat = new GameLib.D3.Runtime.Vector2(
graphics,
texture,
texture.repeat
);
gameLibTextureMap[map].texture = texture;
}
@ -343,7 +332,7 @@ GameLib.D3.Scene.LoadScene = function(
for (var bw = 0; bw < apiMesh.vertices[v].boneWeights.length; bw++) {
boneWeights.push(
new GameLib.D3.BoneWeight(
new GameLib.D3.API.BoneWeight(
apiMesh.vertices[v].boneWeights[bw].boneIndex,
apiMesh.vertices[v].boneWeights[bw].weight
)
@ -352,7 +341,7 @@ GameLib.D3.Scene.LoadScene = function(
gameLibVertices.push(
new GameLib.D3.Vertex(
new GameLib.D3.Vector3(
new GameLib.D3.API.Vector3(
apiMesh.vertices[v].position.x,
apiMesh.vertices[v].position.y,
apiMesh.vertices[v].position.z
@ -378,28 +367,28 @@ GameLib.D3.Scene.LoadScene = function(
apiMesh.skeleton,
apiMesh.skinIndices,
apiMesh.skinWeights,
new GameLib.D3.Vector3(
new GameLib.D3.API.Vector3(
apiMesh.position.x,
apiMesh.position.y,
apiMesh.position.z
),
new GameLib.D3.Vector4(
new GameLib.D3.API.Vector4(
apiMesh.quaternion.x,
apiMesh.quaternion.y,
apiMesh.quaternion.z,
apiMesh.quaternion.w
),
new GameLib.D3.Vector3(
new GameLib.D3.API.Vector3(
apiMesh.rotation.x,
apiMesh.rotation.y,
apiMesh.rotation.z
),
new GameLib.D3.Vector3(
new GameLib.D3.API.Vector3(
apiMesh.scale.x,
apiMesh.scale.y,
apiMesh.scale.z
),
new GameLib.D3.Vector3(
new GameLib.D3.API.Vector3(
apiMesh.up.x,
apiMesh.up.y,
apiMesh.up.z
@ -501,23 +490,23 @@ GameLib.D3.Scene.LoadScene = function(
scene.path,
scene.name,
gameLibMeshes,
new GameLib.D3.Vector4(
new GameLib.D3.API.Vector4(
scene.quaternion.x,
scene.quaternion.y,
scene.quaternion.z,
scene.quaternion.w
),
new GameLib.D3.Vector3(
new GameLib.D3.API.Vector3(
scene.position.x,
scene.position.y,
scene.position.z
),
new GameLib.D3.Vector3(
new GameLib.D3.API.Vector3(
scene.rotation.x,
scene.rotation.y,
scene.rotation.z
),
new GameLib.D3.Vector3(
new GameLib.D3.API.Vector3(
scene.scale.x,
scene.scale.y,
scene.scale.z

View File

@ -2,11 +2,11 @@
* Physics Shape Superset
* @param engine GameLib.D3.Engine
* @param shapeType
* @param scale GameLib.D3.Vector3
* @param scale GameLib.D3.API.Vector3
* @param vertices Number[]
* @param indices Number[]
* @param radius Number
* @param halfExtensions GameLib.D3.Vector3
* @param halfExtensions GameLib.D3.API.Vector3
* @param radiusTop Number
* @param radiusBottom Number
* @param height Number
@ -37,7 +37,7 @@ GameLib.D3.Shape = function(
this.shapeType = shapeType;
if (typeof scale == 'undefined') {
scale = new GameLib.D3.Vector3(1, 1, 1)
scale = new GameLib.D3.API.Vector3(1, 1, 1)
}
this.scale = scale;
@ -57,7 +57,7 @@ GameLib.D3.Shape = function(
this.radius = radius;
if (typeof halfExtensions == 'undefined') {
halfExtensions = new GameLib.D3.Vector3(1,1,1);
halfExtensions = new GameLib.D3.API.Vector3(1,1,1);
}
this.halfExtensions = halfExtensions;

View File

@ -1,7 +1,7 @@
/**
* Skeleton Superset
* @param id
* @param bones GameLib.D3.Bone
* @param bones GameLib.D3.API.Bone
* @param boneInverses
* @param useVertexTexture
* @param boneTextureWidth

View File

@ -21,6 +21,18 @@ GameLib.D3.Texture = function Texture(
}
}
this.offset = new GameLib.D3.Runtime.Vector2(
graphics,
this,
this.offset
);
this.repeat = new GameLib.D3.Runtime.Vector2(
graphics,
this,
this.repeat
);
this.graphics = graphics;
this.graphics.isNotThreeThrow();

View File

@ -34,30 +34,30 @@ GameLib.D3.TriangleFace = function TriangleFace(
this.v1uv = v1uv;
this.v2uv = v2uv;
if (!color) {
color = new GameLib.D3.Color(0xff, 0xff, 0xff, 0xff);
color = new GameLib.D3.API.Color(0xff, 0xff, 0xff, 0xff);
}
this.color = color;
if (!vertexColors) {
vertexColors = [
new GameLib.D3.Color(0xff, 0xff, 0xff, 0xff),
new GameLib.D3.Color(0xff, 0xff, 0xff, 0xff),
new GameLib.D3.Color(0xff, 0xff, 0xff, 0xff)
new GameLib.D3.API.Color(0xff, 0xff, 0xff, 0xff),
new GameLib.D3.API.Color(0xff, 0xff, 0xff, 0xff),
new GameLib.D3.API.Color(0xff, 0xff, 0xff, 0xff)
];
}
this.vertexColors = vertexColors;
if (!vertexNormals) {
vertexNormals = [
new GameLib.D3.Vector3(),
new GameLib.D3.Vector3(),
new GameLib.D3.Vector3()
new GameLib.D3.API.Vector3(),
new GameLib.D3.API.Vector3(),
new GameLib.D3.API.Vector3()
]
}
this.vertexNormals = vertexNormals;
if (!normal) {
normal = new GameLib.D3.Vector3(0);
normal = new GameLib.D3.API.Vector3(0);
}
this.normal = normal;

View File

@ -1,104 +0,0 @@
GameLib.D3.Vector2 = function Vector2(x, y) {
this.x = x || 0;
this.y = y || 0;
};
GameLib.D3.Vector2.prototype.copy = function (v) {
if (!GameLib.D3.Utils.UndefinedOrNull(v)) {
this.x = v.x;
this.y = v.y;
return this;
} else {
return new GameLib.D3.Vector2(
this.x,
this.y
);
}
};
GameLib.D3.Vector2.prototype.equals = function(v) {
return (((this.x == v.x) &&
(this.y == v.y)) ||
((this.y == v.x) &&
(this.x == v.y)));
};
GameLib.D3.Vector2.prototype.add = function(v) {
return new GameLib.D3.Vector2(
this.x + v.x,
this.y + v.y
);
};
GameLib.D3.Vector2.prototype.subtract = function(v) {
return new GameLib.D3.Vector2(
this.x - v.x,
this.y - v.y
);
};
GameLib.D3.Vector2.prototype.multiply = function(v) {
if (v instanceof GameLib.D3.Vector2) {
return new GameLib.D3.Vector2(
this.x * v.x,
this.y * v.y
);
} else if (isNumber(v)) {
return new GameLib.D3.Vector2(
this.x * v,
this.y * v
);
}
};
GameLib.D3.Vector2.prototype.divide = function(v) {
if (v instanceof GameLib.D3.Vector2) {
return new GameLib.D3.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.D3.Vector2(
this.x * invS,
this.y * invS
);
}
};
GameLib.D3.Vector2.prototype.set = function(x, y) {
this.x = x;
this.y = y;
};
GameLib.D3.Vector2.prototype.clamp = function(min, max) {
return new GameLib.D3.Vector2(
Math.max(min.x, Math.min(max.x, this.x)),
Math.max(min.y, Math.min(max.y, this.y))
);
};
GameLib.D3.Vector2.prototype.length = function() {
return Math.sqrt(this.x * this.x + this.y * this.y);
};
GameLib.D3.Vector2.prototype.dot = function(v) {
return this.x * v.x + this.y * v.y;
};
GameLib.D3.Vector2.prototype.normalize = function() {
return this.multiply(1.0 / this.length());
};
GameLib.D3.Vector2.prototype.angle = function() {
var angle = Math.atan2(this.y, this.x);
if ( angle < 0 ) angle += 2 * Math.PI;
return angle;
};
GameLib.D3.Vector2.prototype.lerp = function ( v, alpha ) {
return new GameLib.D3.Vector2(
this.x + ( v.x - this.x ) * alpha,
this.y + ( v.y - this.y ) * alpha
);
};

View File

@ -1,235 +0,0 @@
GameLib.D3.Vector3 = GameLib.D3.API.Vector3;
GameLib.D3.Vector3.prototype.subtract = function (v) {
return new GameLib.D3.Vector3(
this.x - v.x,
this.y - v.y,
this.z - v.z
);
};
GameLib.D3.Vector3.prototype.sub = function (v) {
return new GameLib.D3.Vector3(
this.x - v.x,
this.y - v.y,
this.z - v.z
);
};
GameLib.D3.Vector3.prototype.cross = function (v) {
return new GameLib.D3.Vector3(
this.y * v.z - this.z * v.y,
this.z * v.x - this.x * v.z,
this.x * v.y - this.y * v.x
);
};
GameLib.D3.Vector3.clockwise = function (u, v, w, viewPoint) {
var normal = GameLib.D3.Vector3.normal(u, v, w);
var uv = u.copy();
var winding = normal.dot(uv.subtract(viewPoint));
return (winding > 0);
};
GameLib.D3.Vector3.normal = function (u, v, w) {
var vv = v.copy();
var wv = w.copy();
return vv.subtract(u).cross(wv.subtract(u));
};
GameLib.D3.Vector3.prototype.lookAt = function (at, up) {
var lookAtMatrix = GameLib.D3.Matrix4.lookAt(this, at, up);
return this.multiply(lookAtMatrix);
};
GameLib.D3.Vector3.prototype.translate = function (v) {
this.x += v.x;
this.y += v.y;
this.z += v.z;
return this;
};
GameLib.D3.Vector3.prototype.add = function (v) {
return new GameLib.D3.Vector3(
this.x + v.x,
this.y + v.y,
this.z + v.z
);
};
GameLib.D3.Vector3.prototype.squared = function () {
return this.x * this.x + this.y * this.y + this.z * this.z;
};
GameLib.D3.Vector3.prototype.copy = function () {
return new GameLib.D3.Vector3(
this.x,
this.y,
this.z
);
};
GameLib.D3.Vector3.prototype.set = function (x, y, z) {
this.x = x;
this.y = y;
this.z = z;
};
GameLib.D3.Vector3.prototype.lerp = function ( v, alpha ) {
return new GameLib.D3.Vector3(
this.x + ( v.x - this.x ) * alpha,
this.y + ( v.y - this.y ) * alpha,
this.z + ( v.z - this.z ) * alpha
);
};
GameLib.D3.Vector3.prototype.distanceTo = function(v) {
var dx = this.x - v.x,
dy = this.y - v.y,
dz = this.z - v.z;
return Math.sqrt(dx * dx + dy * dy + dz * dz);
};
/**
* @return {number}
*/
GameLib.D3.Vector3.AngleDirection = function(forward, directionToCheck, up) {
var perp = forward.cross(directionToCheck);
var dir = perp.dot(up);
if (dir > 0.0) {
return 1.0;
} else if (dir < 0.0) {
return -1.0;
} else {
return 0.0;
}
};
GameLib.D3.Vector3.prototype.multiply = function (s) {
if (s instanceof GameLib.D3.Vector3) {
return new GameLib.D3.Vector3(
this.x * s.x,
this.y * s.y,
this.z * s.z
)
} else if (s instanceof GameLib.D3.Matrix4) {
var x = s.rows[0].x * this.x + s.rows[0].y * this.y + s.rows[0].z * this.z + s.rows[0].w;
var y = s.rows[1].x * this.x + s.rows[1].y * this.y + s.rows[1].z * this.z + s.rows[1].w;
var z = s.rows[2].x * this.x + s.rows[2].y * this.y + s.rows[2].z * this.z + s.rows[2].w;
return new GameLib.D3.Vector3(
x,
y,
z
);
} else if (s instanceof GameLib.D3.Matrix3) {
var x = s.rows[0].x * this.x + s.rows[0].y * this.y + s.rows[0].z * this.z;
var y = s.rows[1].x * this.x + s.rows[1].y * this.y + s.rows[1].z * this.z;
var z = s.rows[2].x * this.x + s.rows[2].y * this.y + s.rows[2].z * this.z;
return new GameLib.D3.Vector3(
x,
y,
z
);
} else if(!isNaN(parseFloat(s)) && isFinite(s)) {
return new GameLib.D3.Vector3(
this.x * s,
this.y * s,
this.z * s
);
} else {
console.log("functionality not implemented - please do this");
throw new Error("not implemented");
return this;
}
};
GameLib.D3.Vector3.prototype.dot = function (v) {
return (this.x * v.x) + (this.y * v.y) + (this.z * v.z);
};
GameLib.D3.Vector3.prototype.normalize = function () {
var EPSILON = 0.000001;
var v2 = this.squared();
if (v2 < EPSILON) {
return this; //do nothing for zero vector
}
var invLength = 1.0 / Math.sqrt(v2);
return new GameLib.D3.Vector3(
this.x * invLength,
this.y * invLength,
this.z * invLength
);
};
GameLib.D3.Vector3.prototype.clone = function () {
return new GameLib.D3.Vector3(
this.x,
this.y,
this.z
);
};
GameLib.D3.Vector3.prototype.applyQuaternion = function(q) {
var x = this.x, y = this.y, z = this.z;
var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
// calculate quat * vector
var ix = qw * x + qy * z - qz * y;
var iy = qw * y + qz * x - qx * z;
var iz = qw * z + qx * y - qy * x;
var iw = - qx * x - qy * y - qz * z;
// calculate result * inverse quat
return new GameLib.D3.Vector3(
ix * qw + iw * - qx + iy * - qz - iz * - qy,
iy * qw + iw * - qy + iz * - qx - ix * - qz,
iz * qw + iw * - qz + ix * - qy - iy * - qx
);
};
GameLib.D3.Vector3.prototype.clamp = function(min, max) {
this.x = Math.max( min.x, Math.min( max.x, this.x ) );
this.y = Math.max( min.y, Math.min( max.y, this.y ) );
this.z = Math.max( min.z, Math.min( max.z, this.z ) );
return this;
};
GameLib.D3.Vector3.prototype.negate = function() {
this.x = -this.x;
this.y = -this.y;
this.z = -this.z;
return this;
};
GameLib.D3.Vector3.prototype.length = function() {
return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
};
GameLib.D3.Vector3.prototype.reflect = function(normal) {
return this.sub( v1.copy( normal ).multiply( 2 * this.dot( normal ) ) );
};
GameLib.D3.Vector3.prototype.angleTo = function (v) {
var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
return Math.acos( exports.Math.clamp( theta, - 1, 1 ) );
};

View File

@ -1,323 +0,0 @@
GameLib.D3.Vector4 = function Vector4(x, y, z, w) {
this.x = 0;
this.y = 0;
this.z = 0;
this.w = 1;
if (x) {
this.x = x;
}
if (y) {
this.y = y;
}
if (z) {
this.z = z;
}
if (w) {
this.w = w;
}
};
GameLib.D3.Vector4.prototype.translate = function (v) {
this.x += v.x;
this.y += v.y;
this.z += v.z;
return this;
};
GameLib.D3.Vector4.prototype.copy = function () {
return new GameLib.D3.Vector4(
this.x,
this.y,
this.z,
this.w
);
};
GameLib.D3.Vector4.prototype.multiply = function (s) {
if (s instanceof GameLib.D3.Vector3) {
this.x *= s.x;
this.y *= s.y;
this.z *= s.z;
} else if (s instanceof GameLib.D3.Matrix4) {
var x = s.rows[0].x * this.x + s.rows[0].y * this.y + s.rows[0].z * this.z + s.rows[0].w * this.w;
var y = s.rows[1].x * this.x + s.rows[1].y * this.y + s.rows[1].z * this.z + s.rows[1].w * this.w;
var z = s.rows[2].x * this.x + s.rows[2].y * this.y + s.rows[2].z * this.z + s.rows[2].w * this.w;
var w = s.rows[3].x * this.x + s.rows[3].y * this.y + s.rows[3].z * this.z + s.rows[3].w * this.w;
this.x = x;
this.y = y;
this.z = z;
this.w = w;
} else {
console.log("functionality not implemented - please do this");
throw new Error("not implemented");
}
};
GameLib.D3.Vector4.prototype.normalize = function () {
// note - leave w untouched
var EPSILON = 0.000001;
var v2 = this.x * this.x + this.y * this.y + this.z * this.z;
if (v2 < EPSILON) {
return this; //do nothing for zero vector
}
var invLength = 1 / Math.sqrt(v2);
this.x *= invLength;
this.y *= invLength;
this.z *= invLength;
return this;
};
GameLib.D3.Vector4.prototype.subtract = function (v) {
if (v instanceof GameLib.D3.Vector3) {
this.x -= v.x;
this.y -= v.y;
this.z -= v.z;
}
if (v instanceof GameLib.D3.Vector4) {
this.x -= v.x;
this.y -= v.y;
this.z -= v.z;
this.w -= v.w;
}
return this;
};
GameLib.D3.Vector4.Points = function () {
this.vectors = [];
};
GameLib.D3.Vector4.Points.prototype.add = function (vector) {
if (vector instanceof GameLib.D3.Vector3) {
vector = new GameLib.D3.Vector4(
vector.x,
vector.y,
vector.z,
1
)
}
if (!vector instanceof GameLib.D3.Vector4) {
console.warn("Vector needs to be of type Vector4");
throw new Error("Vector needs to be of type Vector4");
}
this.vectors.push(vector);
return this;
};
GameLib.D3.Vector4.Points.prototype.copy = function () {
var vectors = [];
for (var i = 0; i < this.vectors.length; i++) {
vectors.push(this.vectors[i].copy());
}
return vectors;
};
GameLib.D3.Vector4.Points.prototype.maximizeXDistance = function (grain) {
// console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2));
var multiplier = 0;
var rotationMatrixY = new GameLib.D3.Matrix4().rotationMatrixY(grain);
var totalRadians = 0;
var backupVectors = this.copy();
var maxXDistance = 0;
for (var i = 0; i < Math.PI * 2; i += grain) {
multiplier++;
for (var j = 0; j < this.vectors.length; j++) {
this.vectors[j] = rotationMatrixY.multiply(this.vectors[j]);
}
var distances = this.distances();
if (distances.x > maxXDistance) {
maxXDistance = distances.x;
totalRadians = multiplier * grain;
}
}
this.vectors = backupVectors;
// console.log("distance: " + maxXDistance + " radians : " + totalRadians);
var maxRotationMatrix = new GameLib.D3.Matrix4().rotationMatrixY(totalRadians);
for (var k = 0; k < this.vectors.length; k++) {
this.vectors[k] = maxRotationMatrix.multiply(this.vectors[k]);
}
// console.log("vectors (after): " + JSON.stringify(this.vectors, null, 2));
};
GameLib.D3.Vector4.Points.prototype.maximizeYDistance = function (grain) {
// console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2));
var multiplier = 0;
var rotationMatrixX = new GameLib.D3.Matrix4().rotationMatrixX(grain);
var totalRadians = 0;
var backupVectors = this.copy();
var maxYDistance = 0;
for (var i = 0; i < Math.PI * 2; i += grain) {
multiplier++;
for (var j = 0; j < this.vectors.length; j++) {
this.vectors[j] = rotationMatrixX.multiply(this.vectors[j]);
}
var distances = this.distances();
if (distances.y > maxYDistance) {
maxYDistance = distances.y;
totalRadians = multiplier * grain;
}
}
this.vectors = backupVectors;
// console.log("distance: " + maxYDistance + " radians : " + totalRadians);
var maxRotationMatrix = new GameLib.D3.Matrix4().rotationMatrixX(totalRadians);
for (var k = 0; k < this.vectors.length; k++) {
this.vectors[k] = maxRotationMatrix.multiply(this.vectors[k]);
}
// console.log("vectors (after): " + JSON.stringify(this.vectors, null, 2));
};
GameLib.D3.Vector4.Points.prototype.lookAt = function (at, up) {
var polyCenter = this.average();
console.log("poly center : " + JSON.stringify(polyCenter));
var lookAtMatrix = new GameLib.D3.Matrix4().lookAt(polyCenter, at, up);
lookAtMatrix.rows[0] = new GameLib.D3.Vector4(1, 0, 0, 0);
lookAtMatrix.rows[1] = new GameLib.D3.Vector4(0, 0, 1, 0);
lookAtMatrix.rows[2] = new GameLib.D3.Vector4(0, 1, 0, 0);
console.log("look at matrix : " + JSON.stringify(lookAtMatrix, null, 2));
for (var i = 0; i < this.vectors.length; i++) {
console.log("vector " + i + " (before): " + JSON.stringify(this.vectors[i]));
this.vectors[i] = lookAtMatrix.multiply(this.vectors[i]);
console.log("vector " + i + " (after) : " + JSON.stringify(this.vectors[i]));
}
};
GameLib.D3.Vector4.Points.prototype.distances = function () {
var minX = this.vectors[0].x;
var minY = this.vectors[0].y;
var minZ = this.vectors[0].z;
var maxX = this.vectors[0].x;
var maxY = this.vectors[0].y;
var maxZ = this.vectors[0].z;
for (var i = 0; i < this.vectors.length; i++) {
if (this.vectors[i].x < minX) {
minX = this.vectors[i].x;
}
if (this.vectors[i].y < minY) {
minY = this.vectors[i].y;
}
if (this.vectors[i].z < minZ) {
minZ = this.vectors[i].z;
}
if (this.vectors[i].x > maxX) {
maxX = this.vectors[i].x;
}
if (this.vectors[i].y > maxY) {
maxY = this.vectors[i].y;
}
if (this.vectors[i].z > maxZ) {
maxZ = this.vectors[i].z;
}
}
return new GameLib.D3.Vector3(
Math.abs(maxX - minX),
Math.abs(maxY - minY),
Math.abs(maxY - minZ)
)
};
GameLib.D3.Vector4.Points.prototype.average = function () {
var averageX = 0;
var averageY = 0;
var averageZ = 0;
for (var i = 0; i < this.vectors.length; i++) {
averageX += this.vectors[i].x;
averageY += this.vectors[i].y;
averageZ += this.vectors[i].z;
}
return new GameLib.D3.Vector3(
averageX / this.vectors.length,
averageY / this.vectors.length,
averageZ / this.vectors.length
);
};
GameLib.D3.Vector4.Points.prototype.negate = function () {
for (var i = 0; i < this.vectors.length; i++) {
this.vectors[i].x *= -1;
this.vectors[i].y *= -1;
this.vectors[i].z *= -1;
}
return this;
};
GameLib.D3.Vector4.Points.prototype.toOrigin = function () {
var distanceFromOrigin = this.average().negate();
for (var i = 0; i < this.vectors.length; i++) {
this.vectors[i].translate(distanceFromOrigin);
}
};

View File

@ -1,7 +1,7 @@
/**
* The normal gets assigned when the face calculates its normal
* @param position
* @param boneWeights GameLib.D3.BoneWeight[]
* @param boneWeights GameLib.D3.API.BoneWeight[]
* @constructor
*/
GameLib.D3.Vertex = function Vertex(

View File

@ -24,7 +24,7 @@ GameLib.D3.World = function(
this.name = name;
if (typeof gravity == 'undefined') {
gravity = new GameLib.D3.Vector3(0, -9.81, 0);
gravity = new GameLib.D3.API.Vector3(0, -9.81, 0);
}
this.gravity = gravity;
@ -146,7 +146,7 @@ GameLib.D3.World.prototype.GetIndexedVertices = function(
/**
* @param triangleMeshShape GameLib.D3.Shape
* @param normalLength Number
* @param scale GameLib.D3.Vector3
* @param scale GameLib.D3.API.Vector3
* @param opacity Number
* @param wireframeColor HexCode
* @param graphics THREE
@ -253,7 +253,7 @@ GameLib.D3.World.prototype.generateWireframeViewTriangleMesh = function(
/**
* @param convexPolyMeshShape GameLib.D3.Shape
* @param normalLength Number
* @param scale GameLib.D3.Vector3
* @param scale GameLib.D3.API.Vector3
* @param opacity Number
* @param wireframeColor HexCode
* @param graphics THREE

View File

@ -7,10 +7,10 @@ if (typeof GameLib.D3 === 'undefined') {
}
if (typeof require != 'undefined') {
GameLib.D3.Bone = require('./game-lib-bone.js');
GameLib.D3.BoneWeight = require('./game-lib-bone-weight');
GameLib.D3.API.Bone = require('./game-lib-bone.js');
GameLib.D3.API.BoneWeight = require('./game-lib-bone-weight');
GameLib.D3.Broadphase = require('./game-lib-broadphase');
GameLib.D3.Color = require('./game-lib-color');
GameLib.D3.API.Color = require('./game-lib-color');
GameLib.D3.FlyControls = require('./game-lib-fly-controls');
GameLib.D3.Engine = require('./game-lib-engine');
GameLib.D3.Game = require('./game-lib-game');
@ -34,10 +34,10 @@ if (typeof require != 'undefined') {
GameLib.D3.Texture = require('./game-lib-texture');
GameLib.D3.TriangleEdge = require('./game-lib-triangle-edge');
GameLib.D3.TriangleFace = require('./game-lib-triangle-face');
GameLib.D3.Vector2 = require('./game-lib-vector-2');
GameLib.D3.Vector3 = require('./game-lib-vector-3');
GameLib.D3.Vector4 = require('./game-lib-vector-4');
GameLib.D3.Vector4.Points = require('./game-lib-vector-4-points');
GameLib.D3.API.Vector2 = require('./game-lib-vector-2');
GameLib.D3.API.Vector3 = require('./game-lib-vector-3');
GameLib.D3.API.Vector4 = require('./game-lib-vector-4');
GameLib.D3.API.Vector4.Points = require('./game-lib-vector-4-points');
GameLib.D3.Vertex = require('./game-lib-vertex');
GameLib.D3.World = require('./game-lib-world');
}