follow component - starting to get stable

beta.r3js.org
Theunis J. Botha 2016-12-20 17:27:36 +01:00
parent 846bdba6c4
commit 063d88f920
18 changed files with 393 additions and 252 deletions

View File

@ -110,37 +110,3 @@ GameLib.API.Matrix4.prototype.identity = function () {
];
};
GameLib.API.Matrix4.prototype.lookAt = function (position, target, up) {
var pv = new GameLib.API.Vector3(position.x, position.y, position.z);
var z = pv.subtract(target).normalize();
if (z.squared() === 0) {
z.z = 1;
}
var x = up.cross(z).normalize();
if (x.squared() === 0) {
z.x += 0.0001;
x = up.cross(z).normalize();
}
var y = z.cross(x);
this.rows[0].x = x.x;
this.rows[0].y = x.y;
this.rows[0].z = x.z;
this.rows[1].x = y.x;
this.rows[1].y = y.y;
this.rows[1].z = y.z;
this.rows[2].x = z.x;
this.rows[2].y = z.y;
this.rows[2].z = z.z;
return this;
};

View File

@ -5,7 +5,7 @@ GameLib.Component = function(
this.componentType = componentType;
if (GameLib.Utils.UndefinedOrNull(linkedObjects)) {
linkedObjects = [];
linkedObjects = {};
}
this.linkedObjects = linkedObjects;
};
@ -15,6 +15,9 @@ GameLib.Component.COMPONENT_RENDERABLE = 0x2;
GameLib.Component.COMPONENT_RENDERER = 0x3;
GameLib.Component.COMPONENT_EDITOR_INPUT = 0x4;
GameLib.Component.COMPONENT_LOOK_AT = 0x5;
GameLib.Component.COMPONENT_CAMERA = 0x6;
GameLib.Component.COMPONENT_FOLLOW = 0x7;
GameLib.Component.COMPONENT_MESH = 0x8;
GameLib.Component.prototype.toApiComponent = function() {
return this.id;

View File

@ -36,6 +36,11 @@ GameLib.D3.API.Camera = function(
maxZ,
quaternion
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_CAMERA
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -123,4 +128,7 @@ GameLib.D3.API.Camera = function(
maxZ = 100;
}
this.maxZ = maxZ;
};
};
GameLib.D3.API.Camera.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.Camera.prototype.constructor = GameLib.D3.API.Camera;

View File

@ -2,29 +2,32 @@
* Follow Component
* @param id
* @param name
* @param targetPosition GameLib.API.Vector3
* @param targetOffset GameLib.API.Vector3
* @param currentComponent GameLib.Component
* @param targetComponent GameLib.Component
* @param targetPositionOffset GameLib.API.Vector3
* @param minDistance
* @param moveSpeed
* @param target GameLib.API.Vector3
* @param targetToParent GameLib.API.Vector3
* @param rotatedTargetOffset GameLib.API.Vector3
* @param rotated GameLib.API.Quaternion
* @constructor
*/
GameLib.D3.API.Follow = function (
id,
name,
targetPosition,
targetOffset,
currentComponent,
targetComponent,
targetPositionOffset,
minDistance,
moveSpeed,
target,
targetToParent,
rotatedTargetOffset,
rotated
moveSpeed
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_FOLLOW,
{
'currentComponent': GameLib.Component,
'targetComponent': GameLib.Component
}
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -35,18 +38,23 @@ GameLib.D3.API.Follow = function (
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(targetPosition)) {
targetPosition = null;
if (GameLib.Utils.UndefinedOrNull(currentComponent)) {
currentComponent = null;
}
this.targetPosition = targetPosition;
this.currentComponent = currentComponent;
if(GameLib.Utils.UndefinedOrNull(targetOffset)) {
targetOffset = new GameLib.API.Vector3(0, 0, 0);
if (GameLib.Utils.UndefinedOrNull(targetComponent)) {
targetComponent = null;
}
this.targetOffset = targetOffset;
this.targetComponent = targetComponent;
if(GameLib.Utils.UndefinedOrNull(targetPositionOffset)) {
targetPositionOffset = new GameLib.API.Vector3(0, 0, 0);
}
this.targetPositionOffset = targetPositionOffset;
if (GameLib.Utils.UndefinedOrNull(minDistance)) {
minDistance = 0;
minDistance = 2;
}
this.minDistance = minDistance;
@ -55,23 +63,14 @@ GameLib.D3.API.Follow = function (
}
this.moveSpeed = moveSpeed;
if(GameLib.Utils.UndefinedOrNull(target)) {
target = new GameLib.API.Vector3(0, 0, 0);
}
this.target = target;
this.target = new GameLib.API.Vector3(0, 0, 0);
if(GameLib.Utils.UndefinedOrNull(targetToParent)) {
targetToParent = new GameLib.API.Vector3(0, 0, 0);
}
this.targetToParent = targetToParent;
this.targetToParent = new GameLib.API.Vector3(0, 0, 0);
if(GameLib.Utils.UndefinedOrNull(rotatedTargetOffset)) {
rotatedTargetOffset = new GameLib.API.Vector3(0, 0, 0);
}
this.rotatedTargetOffset = rotatedTargetOffset;
this.rotatedTargetOffset = new GameLib.API.Vector3(0, 0, 0);
if (GameLib.Utils.UndefinedOrNull(rotated)) {
rotated = new GameLib.API.Quaternion();
}
this.rotated = rotated;
this.rotated = new GameLib.API.Quaternion();
};
GameLib.D3.API.Follow.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.Follow.prototype.constructor = GameLib.D3.API.Follow;

View File

@ -15,9 +15,9 @@ GameLib.D3.API.Input.Editor = function (
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_EDITOR_INPUT,
[
'camera'
]
{
'camera' : GameLib.D3.Camera
}
);
if (GameLib.Utils.UndefinedOrNull(id)) {

View File

@ -15,9 +15,9 @@ GameLib.D3.API.Input.Fly = function (
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_FLY_INPUT,
[
'camera'
]
{
'camera' : GameLib.D3.Camera
}
);
if (GameLib.Utils.UndefinedOrNull(id)) {

View File

@ -20,10 +20,10 @@ GameLib.D3.API.LookAt = function (
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_LOOK_AT,
[
'currentComponent',
'targetComponent'
]
{
'currentComponent' : GameLib.Component,
'targetComponent' : GameLib.Component
}
);
if (GameLib.Utils.UndefinedOrNull(id)) {
@ -61,6 +61,8 @@ GameLib.D3.API.LookAt = function (
this.up = new GameLib.API.Vector3(0, 1, 0);
this.currentRotation = new GameLib.API.Quaternion();
this.targetPosition = new GameLib.API.Vector3();
};
GameLib.D3.API.LookAt.prototype = Object.create(GameLib.Component.prototype);

View File

@ -7,8 +7,8 @@
* @param faces GameLib.D3.TriangleFace[]
* @param faceVertexUvs
* @param materials GameLib.D3.API.Material[]
* @param parentMeshId
* @param parentSceneId
* @param parentMesh
* @param parentScene
* @param skeleton
* @param skinIndices
* @param skinWeights
@ -29,8 +29,8 @@ GameLib.D3.API.Mesh = function(
faces,
faceVertexUvs,
materials,
parentMeshId,
parentSceneId,
parentMesh,
parentScene,
skeleton,
skinIndices,
skinWeights,
@ -44,7 +44,11 @@ GameLib.D3.API.Mesh = function(
) {
GameLib.Component.call(
this,
GameLib.D3.API.Mesh
GameLib.Component.COMPONENT_MESH,
{
'parentMesh' : GameLib.D3.Mesh,
'parentScene' : GameLib.D3.Scene
}
);
if (GameLib.Utils.UndefinedOrNull(id)) {
@ -72,15 +76,15 @@ GameLib.D3.API.Mesh = function(
}
this.faces = faces;
if (GameLib.Utils.UndefinedOrNull(parentMeshId)) {
parentMeshId = null;
if (GameLib.Utils.UndefinedOrNull(parentMesh)) {
parentMesh = null;
}
this.parentMeshId = parentMeshId;
this.parentMesh = parentMesh;
if (GameLib.Utils.UndefinedOrNull(parentSceneId)) {
parentSceneId = null;
if (GameLib.Utils.UndefinedOrNull(parentScene)) {
parentScene = null;
}
this.parentSceneId = parentSceneId;
this.parentScene = parentScene;
if (GameLib.Utils.UndefinedOrNull(skeleton)) {
skeleton = null;

View File

@ -50,11 +50,11 @@ GameLib.D3.API.PathFollowing = function (
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_TYPE_PATH_FOLLOWING,
[
'spline',
'mesh',
'raytraceMesh'
]
{
'spline': GameLib.D3.Spline,
'mesh' : GameLib.D3.Mesh,
'raytraceMesh' : GameLib.D3.Mesh
}
);
if (GameLib.Utils.UndefinedOrNull(id)) {

View File

@ -24,10 +24,10 @@ GameLib.D3.API.Renderer = function (
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_RENDERER,
[
'scene',
'camera'
]
{
'scene' : GameLib.D3.Scene,
'camera' : GameLib.D3.Camera
}
);
if (GameLib.Utils.UndefinedOrNull(id)) {

View File

@ -8,16 +8,30 @@ GameLib.D3.Camera = function Camera(
graphics,
apiCamera
) {
for (var property in apiCamera) {
if (apiCamera.hasOwnProperty(property)) {
this[property] = apiCamera[property];
}
}
this.graphics = graphics;
this.graphics.isNotThreeThrow();
GameLib.D3.API.Camera.call(
this,
apiCamera.id,
apiCamera.cameraType,
apiCamera.name,
apiCamera.fov,
apiCamera.aspect,
apiCamera.near,
apiCamera.far,
apiCamera.position,
apiCamera.lookAt,
apiCamera.minX,
apiCamera.maxX,
apiCamera.minY,
apiCamera.maxY,
apiCamera.minZ,
apiCamera.maxZ,
apiCamera.quaternion
);
this.position = new GameLib.Vector3(
graphics,
this,
@ -41,6 +55,9 @@ GameLib.D3.Camera = function Camera(
this.needsUpdate = false;
} ;
GameLib.D3.Camera.prototype = Object.create(GameLib.D3.API.Camera.prototype);
GameLib.D3.Camera.prototype.constructor = GameLib.D3.Camera;
/**
* Camera types
* @type {number}

View File

@ -15,28 +15,19 @@ GameLib.D3.Follow = function RuntimeFollow(
GameLib.D3.API.Follow.call(
this,
apiFollow.id,
apiFollow.name,
apiFollow.targetPosition,
apiFollow.targetOffset,
apiFollow.minDistance,
apiFollow.moveSpeed,
apiFollow.target,
apiFollow.targetToParent,
apiFollow.rotatedTargetOffset,
apiFollow.rotated
apiFollow.id,
apiFollow.name,
apiFollow.currentComponent,
apiFollow.targetComponent,
apiFollow.targetPositionOffset,
apiFollow.minDistance,
apiFollow.moveSpeed
);
this.targetPosition = new GameLib.Vector3(
this.targetPositionOffset = new GameLib.Vector3(
this.graphics,
this,
this.targetPosition
);
this.targetOffset = new GameLib.Vector3(
this.graphics,
this,
this.targetOffset
this.targetPositionOffset
);
this.target = new GameLib.Vector3(
@ -66,3 +57,103 @@ GameLib.D3.Follow = function RuntimeFollow(
GameLib.D3.Follow.prototype = Object.create(GameLib.D3.API.Follow.prototype);
GameLib.D3.Follow.prototype.constructor = GameLib.D3.Follow;
GameLib.D3.Follow.prototype.toApiComponent = function() {
var apiFollow = new GameLib.D3.API.Follow(
this.id,
this.name,
GameLib.Utils.IdOrNull(this.currentComponent),
GameLib.Utils.IdOrNull(this.targetComponent),
this.targetPositionOffset.toApiVector(),
this.minDistance,
this.moveSpeed
);
return apiFollow;
};
GameLib.D3.Follow.FromObjectComponent = function(graphics, objectComponent) {
var apiFollow = new GameLib.D3.API.Follow(
objectComponent.id,
objectComponent.name,
objectComponent.currentComponent,
objectComponent.targetComponent,
new GameLib.API.Vector3(
objectComponent.targetPositionOffset.x,
objectComponent.targetPositionOffset.y,
objectComponent.targetPositionOffset.z
),
objectComponent.minDistance,
objectComponent.moveSpeed
);
return new GameLib.D3.Follow(
graphics,
this,
apiFollow
);
};
/**
* Updates the component
* @param deltaTime
*/
GameLib.D3.Follow.prototype.update = function(deltaTime) {
if (this.currentComponent && this.targetComponent) {
this.rotated.x = this.targetComponent.quaternion.x;
this.rotated.y = this.targetComponent.quaternion.y;
this.rotated.z = this.targetComponent.quaternion.z;
this.rotated.w = this.targetComponent.quaternion.w;
this.rotated.updateInstance();
this.rotatedTargetOffset.x = this.targetPositionOffset.x;
this.rotatedTargetOffset.y = this.targetPositionOffset.y;
this.rotatedTargetOffset.z = this.targetPositionOffset.z;
this.rotatedTargetOffset.applyQuaternion(this.rotated);
this.rotatedTargetOffset.updateInstance();
this.target.x = this.targetComponent.position.x + this.rotatedTargetOffset.x;
this.target.y = this.targetComponent.position.y + this.rotatedTargetOffset.y;
this.target.z = this.targetComponent.position.z + this.rotatedTargetOffset.z;
this.target.updateInstance();
this.targetToParent.x = this.currentComponent.position.x - this.targetComponent.position.x;
this.targetToParent.y = this.currentComponent.position.y - this.targetComponent.position.y;
this.targetToParent.z = this.currentComponent.position.z - this.targetComponent.position.z;
this.targetToParent.normalize();
this.targetToParent.x *= this.minDistance;
this.targetToParent.y *= this.minDistance;
this.targetToParent.z *= this.minDistance;
this.targetToParent.updateInstance();
this.target.x = this.target.x + this.targetToParent.x;
this.target.y = this.target.y + this.targetToParent.y;
this.target.z = this.target.z + this.targetToParent.z;
this.target.updateInstance();
var t = deltaTime * this.moveSpeed;
//t = t * t * t * (t * (6.0 * t - 15.0) + 10.0);
var lerp = this.currentComponent.position.lerp(this.target, t);
this.currentComponent.position.x = lerp.x;
this.currentComponent.position.y = lerp.y;
this.currentComponent.position.z = lerp.z;
this.currentComponent.position.updateInstance();
}
};

View File

@ -51,6 +51,12 @@ GameLib.D3.LookAt = function RuntimeLookAt(
this,
this.currentRotation
);
this.targetPosition = new GameLib.Vector3(
this.graphics,
this,
this.targetPosition
);
};
GameLib.D3.LookAt.prototype = Object.create(GameLib.D3.API.LookAt.prototype);
@ -94,4 +100,45 @@ GameLib.D3.LookAt.FromObjectComponent = function(graphics, objectComponent) {
*/
GameLib.D3.LookAt.prototype.update = function(deltaTime) {
if (this.currentComponent && this.targetComponent) {
this.targetPosition.x = this.targetComponent.position.x + this.targetPositionOffset.x;
this.targetPosition.y = this.targetComponent.position.y + this.targetPositionOffset.y;
this.targetPosition.z = this.targetComponent.position.z + this.targetPositionOffset.z;
this.targetPosition.updateInstance();
//
// this.currentComponent.instance.lookAt(this.targetPosition);
//
// this.currentComponent.instance.updateProjectionMatrix();
//
// // this.currentComponent.updateInstance();
// return;
this.lookAtMatrix.lookAt(
this.currentComponent.position,
this.targetPosition,
this.up
);
this.currentRotation = new GameLib.Quaternion(this.graphics, this, new GameLib.API.Quaternion());
this.currentRotation.setFromRotationMatrix(this.lookAtMatrix);
// var t = deltaTime * this.rotationSpeed;
// t = t * t * t * (t * (6.0 * t - 15.0) + 10.0);
// this.currentRotation.slerp(this.currentRotation, t);
this.currentRotation.normalize();
this.currentComponent.quaternion.x = this.currentRotation.x;
this.currentComponent.quaternion.y = this.currentRotation.y;
this.currentComponent.quaternion.z = this.currentRotation.z;
this.currentComponent.quaternion.w = this.currentRotation.w;
this.currentComponent.quaternion.updateInstance();
}
};

View File

@ -22,8 +22,8 @@ GameLib.D3.Mesh = function RuntimeMesh(
apiMesh.faces,
apiMesh.faceVertexUvs,
apiMesh.materials,
apiMesh.parentMeshId,
apiMesh.parentSceneId,
apiMesh.parentMesh,
apiMesh.parentScene,
apiMesh.skeleton,
apiMesh.skinIndices,
apiMesh.skinWeights,
@ -343,6 +343,17 @@ GameLib.D3.Mesh.prototype.createInstance = function(update) {
instance.gameLibObject = this;
if (this.parentMesh && this.parentMesh.position) {
this.position.x = this.parentMesh.position.x;
this.position.y = this.parentMesh.position.y;
this.position.z = this.parentMesh.position.z;
this.quaternion.x = this.parentMesh.quaternion.x;
this.quaternion.y = this.parentMesh.quaternion.y;
this.quaternion.z = this.parentMesh.quaternion.z;
this.quaternion.w = this.parentMesh.quaternion.w;
}
instance.position.x = this.position.x + this.localPosition.x;
instance.position.y = this.position.y + this.localPosition.y;
instance.position.z = this.position.z + this.localPosition.z;
@ -396,8 +407,8 @@ GameLib.D3.Mesh.prototype.toApiMesh = function() {
this.faces,
this.faceVertexUvs,
this.materials.map(function(material){return material.toApiMaterial()}),
this.parentMeshId,
this.parentSceneId,
GameLib.Utils.IdOrNull(this.parentMesh),
GameLib.Utils.IdOrNull(this.parentScene),
this.skeleton,
this.skinIndices,
this.skinWeights,
@ -455,8 +466,8 @@ GameLib.D3.Mesh.FromObjectMesh = function(graphics, objectMesh, computeNormals,
);
}
),
objectMesh.parentMeshId,
objectMesh.parentSceneId,
objectMesh.parentMesh,
objectMesh.parentScene,
objectMesh.skeleton,
objectMesh.skinIndices,
objectMesh.skinWeights,
@ -510,4 +521,4 @@ GameLib.D3.Mesh.FromObjectMesh = function(graphics, objectMesh, computeNormals,
apiMesh
);
};
};

View File

@ -51,6 +51,11 @@ GameLib.D3.Renderer.prototype.createInstance = function(update) {
instance.setSize(this.width, this.height);
instance.autoClear = this.autoClear;
if (this.camera && this.camera.instance) {
this.camera.instance.aspect = this.width / this.height;
this.camera.instance.updateProjectionMatrix();
}
this.instance = instance;
return instance;
@ -67,7 +72,10 @@ GameLib.D3.Renderer.prototype.toApiComponent = function() {
this.name,
GameLib.Utils.IdOrNull(this.scene),
GameLib.Utils.IdOrNull(this.camera),
this.autoClear
this.autoClear,
this.localClipping,
this.width,
this.height
);
return apiRenderer;
@ -80,7 +88,10 @@ GameLib.D3.Renderer.FromObjectComponent = function(graphics, objectComponent) {
objectComponent.name,
objectComponent.scene,
objectComponent.camera,
objectComponent.autoClear
objectComponent.autoClear,
objectComponent.localClipping,
objectComponent.width,
objectComponent.height
);
return new GameLib.D3.Renderer(

View File

@ -181,6 +181,10 @@ GameLib.EntityManager.FromObjectEntityManager = function(graphics, objectEntitie
return GameLib.D3.Input.Editor.FromObjectComponent(graphics, component);
} else if (component.componentType === GameLib.Component.COMPONENT_LOOK_AT) {
return GameLib.D3.LookAt.FromObjectComponent(graphics, component);
} else if (component.componentType === GameLib.Component.COMPONENT_FOLLOW) {
return GameLib.D3.Follow.FromObjectComponent(graphics, component);
} else if (component.componentType === GameLib.Component.COMPONENT_MESH) {
return GameLib.D3.Mesh.FromObjectComponent(graphics, component);
} else {
console.warn('no component was associated with this object');
throw new Error('no component was associated with this object');
@ -237,7 +241,7 @@ GameLib.EntityManager.prototype.linkObjects = function(idToObject) {
array[index] = idToObject[componentId];
}
array[index].linkedObjects.map(
Object.keys(array[index].linkedObjects).map(
function (propertyName) {
array[index][propertyName] = idToObject[array[index][propertyName]];
}

View File

@ -115,31 +115,31 @@ GameLib.Matrix4.prototype.updateInstance = function() {
}
};
GameLib.Matrix4.prototype.lookAt = function (position, target, up) {
this.instance.lookAt(position.instance, target.instance, up.instance);
this.rows[0].x = this.instance.elements[0];
this.rows[0].y = this.instance.elements[1];
this.rows[0].z = this.instance.elements[2];
this.rows[0].w = this.instance.elements[3];
this.rows[1].x = this.instance.elements[4];
this.rows[1].y = this.instance.elements[5];
this.rows[1].z = this.instance.elements[6];
this.rows[1].w = this.instance.elements[7];
this.rows[2].x = this.instance.elements[8];
this.rows[2].y = this.instance.elements[9];
this.rows[2].z = this.instance.elements[10];
this.rows[2].w = this.instance.elements[11];
this.rows[3].x = this.instance.elements[12];
this.rows[3].y = this.instance.elements[13];
this.rows[3].z = this.instance.elements[14];
this.rows[3].w = this.instance.elements[15];
};
// GameLib.Matrix4.prototype.lookAt = function (position, target, up) {
//
// this.instance.lookAt(position.instance, target.instance, up.instance);
//
// this.rows[0].x = this.instance.elements[0];
// this.rows[0].y = this.instance.elements[1];
// this.rows[0].z = this.instance.elements[2];
// this.rows[0].w = this.instance.elements[3];
//
// this.rows[1].x = this.instance.elements[4];
// this.rows[1].y = this.instance.elements[5];
// this.rows[1].z = this.instance.elements[6];
// this.rows[1].w = this.instance.elements[7];
//
// this.rows[2].x = this.instance.elements[8];
// this.rows[2].y = this.instance.elements[9];
// this.rows[2].z = this.instance.elements[10];
// this.rows[2].w = this.instance.elements[11];
//
// this.rows[3].x = this.instance.elements[12];
// this.rows[3].y = this.instance.elements[13];
// this.rows[3].z = this.instance.elements[14];
// this.rows[3].w = this.instance.elements[15];
//
// };
/**
* GameLib.Matrix4 to GameLib.API.Matrix4
@ -195,4 +195,63 @@ GameLib.Matrix4.FromObjectMatrix = function(graphics, objectMatrix, parentObject
parentObject,
apiMatrix
)
};
};
GameLib.Matrix4.prototype.lookAt = function (position, target, up) {
this.instance.lookAt(position.instance, target.instance, up.instance);
this.rows[0].x = this.instance.elements[0];
this.rows[0].y = this.instance.elements[1];
this.rows[0].z = this.instance.elements[2];
this.rows[0].w = this.instance.elements[3];
this.rows[1].x = this.instance.elements[4];
this.rows[1].y = this.instance.elements[5];
this.rows[1].z = this.instance.elements[6];
this.rows[1].w = this.instance.elements[7];
this.rows[2].x = this.instance.elements[8];
this.rows[2].y = this.instance.elements[9];
this.rows[2].z = this.instance.elements[10];
this.rows[2].w = this.instance.elements[11];
this.rows[3].x = this.instance.elements[12];
this.rows[3].y = this.instance.elements[13];
this.rows[3].z = this.instance.elements[14];
this.rows[3].w = this.instance.elements[15];
// var pv = new GameLib.API.Vector3(position.x, position.y, position.z);
//
// var z = pv.subtract(target).normalize();
//
// if (z.squared() === 0) {
// z.z = 1;
// }
//
// var x = up.cross(z).normalize();
//
// if (x.squared() === 0) {
// z.x += 0.0001;
// x = up.cross(z).normalize();
// }
//
// var y = z.cross(x);
//
// this.rows[0].x = x.x;
// this.rows[0].y = x.y;
// this.rows[0].z = x.z;
//
// this.rows[1].x = y.x;
// this.rows[1].y = y.y;
// this.rows[1].z = y.z;
//
// this.rows[2].x = z.x;
// this.rows[2].y = z.y;
// this.rows[2].z = z.z;
//
// this.updateInstance();
return this;
};

View File

@ -15,6 +15,7 @@ GameLib.System.Animation.prototype = Object.create(GameLib.System.prototype);
GameLib.System.Animation.prototype.constructor = GameLib.System.Animation;
GameLib.System.Animation.prototype.start = function() {
};
/**
@ -28,99 +29,17 @@ GameLib.System.Animation.prototype.update = function(deltaTime) {
object.update(deltaTime);
});
/**
* TODO: PathFollowingComponent Stuff
*
*
*
objects = this.entityManager.query([GameLib.D3.Follow]);
TODO: lookat component code
objects.forEach(function(object) {
object.update(deltaTime);
});
objects = this.entityManager.query([GameLib.D3.LookAt]);
if (this.targetEntity && this.parentEntity) {
this.targetPosition.x = this.targetEntity.position.x + this.targetOffset.x;
this.targetPosition.y = this.targetEntity.position.y + this.targetOffset.y;
this.targetPosition.z = this.targetEntity.position.z + this.targetOffset.z;
this.targetPosition.updateInstance();
this.lookAtMatrix.lookAt(
this.parentEntity.position,
this.targetPosition,
this.up
);
this.currentRotation.setFromRotationMatrix(this.lookAtMatrix);
var t = deltaTime * this.rotationSpeed;
t = t * t * t * (t * (6.0 * t - 15.0) + 10.0);
this.currentRotation.slerp(this.currentRotation, t);
this.parentEntity.quaternion.x = this.currentRotation.x;
this.parentEntity.quaternion.y = this.currentRotation.y;
this.parentEntity.quaternion.z = this.currentRotation.z;
this.parentEntity.quaternion.w = this.currentRotation.w;
this.parentEntity.quaternion.updateInstance();
}
TODO: entity follow component stuff
if (this.parentEntity && this.targetEntity) {
this.rotated.x = this.targetEntity.quaternion.x;
this.rotated.y = this.targetEntity.quaternion.y;
this.rotated.z = this.targetEntity.quaternion.z;
this.rotated.w = this.targetEntity.quaternion.w;
this.rotated.updateInstance();
this.rotatedTargetOffset.x = this.targetOffset.x;
this.rotatedTargetOffset.y = this.targetOffset.y;
this.rotatedTargetOffset.z = this.targetOffset.z;
this.rotatedTargetOffset.applyQuaternion(this.rotated);
this.rotatedTargetOffset.updateInstance();
this.target.x = this.targetEntity.position.x + this.rotatedTargetOffset.x;
this.target.y = this.targetEntity.position.y + this.rotatedTargetOffset.y;
this.target.z = this.targetEntity.position.z + this.rotatedTargetOffset.z;
this.target.updateInstance();
this.targetToParent.x = this.parentEntity.position.x - this.targetEntity.position.x;
this.targetToParent.y = this.parentEntity.position.y - this.targetEntity.position.y;
this.targetToParent.z = this.parentEntity.position.z - this.targetEntity.position.z;
this.targetToParent.normalize();
this.targetToParent.x *= this.minDistance;
this.targetToParent.y *= this.minDistance;
this.targetToParent.z *= this.minDistance;
this.targetToParent.updateInstance();
this.target.x = this.target.x + this.targetToParent.x;
this.target.y = this.target.y + this.targetToParent.y;
this.target.z = this.target.z + this.targetToParent.z;
this.target.updateInstance();
var t = deltaTime * this.moveSpeed;
//t = t * t * t * (t * (6.0 * t - 15.0) + 10.0);
var lerp = this.parentEntity.position.lerp(this.target, t);
this.parentEntity.position.x = lerp.x;
this.parentEntity.position.y = lerp.y;
this.parentEntity.position.z = lerp.z;
this.parentEntity.position.updateInstance();
}
*/
objects.forEach(function(object) {
object.update(deltaTime);
});
};