From 296d7ca836c58897d3a12fd7b1e92a255b0014c5 Mon Sep 17 00:00:00 2001 From: "Theunis J. Botha" Date: Thu, 24 Nov 2016 19:18:00 +0100 Subject: [PATCH] runtime vectors --- src/game-lib-mesh.js | 8 ++++---- src/game-lib-scene.js | 18 ++++++++++++++++ src/game-lib-vector-3.js | 44 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/game-lib-mesh.js b/src/game-lib-mesh.js index d1bb499..0efb5d3 100644 --- a/src/game-lib-mesh.js +++ b/src/game-lib-mesh.js @@ -419,10 +419,10 @@ GameLib.D3.Mesh.prototype.createInstance = function(update) { instance.scale.y = this.scale.y; instance.scale.z = this.scale.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.quaternion.x = this.quaternion.x; + // instance.quaternion.y = this.quaternion.y; + // instance.quaternion.z = this.quaternion.z; + // instance.quaternion.w = this.quaternion.w; return instance; }; diff --git a/src/game-lib-scene.js b/src/game-lib-scene.js index 91aeca7..960f3e5 100644 --- a/src/game-lib-scene.js +++ b/src/game-lib-scene.js @@ -500,6 +500,24 @@ GameLib.D3.Scene.LoadScene = function( ) ); + gameLibMesh.position = new GameLib.D3.Vector3.Runtime( + graphics, + gameLibMesh, + gameLibMesh.position + ); + + gameLibMesh.rotation = new GameLib.D3.Vector3.Runtime( + graphics, + gameLibMesh, + gameLibMesh.rotation + ); + + gameLibMesh.scale = new GameLib.D3.Vector3.Runtime( + graphics, + gameLibMesh, + gameLibMesh.scale + ); + gameLibMeshes.push(gameLibMesh); } diff --git a/src/game-lib-vector-3.js b/src/game-lib-vector-3.js index 19fb1ff..5c1fb0c 100644 --- a/src/game-lib-vector-3.js +++ b/src/game-lib-vector-3.js @@ -4,6 +4,50 @@ GameLib.D3.Vector3 = function Vector3(x, y, z) { this.z = z || 0; }; +/** + * Runtime vector for updating instance objects + * @param graphics GameLib.D3.Graphics + * @param parentObject GameLib.D3.* + * @param apiVector GameLib.D3.Vector3 + * @constructor + */ +GameLib.D3.Vector3.Runtime = function RuntimeVector3(graphics, parentObject, apiVector) { + + for (var property in apiVector) { + if (apiVector.hasOwnProperty(property)) { + this[property] = apiVector[property]; + } + } + + this.apiVector = apiVector; + + this.graphics = graphics; + + this.graphics.isNotThreeThrow(); + + this.parentObject = parentObject; + + this.instance = this.createInstance(); +}; + +GameLib.D3.Vector3.Runtime.prototype.createInstance = function() { + return this.graphics.instance.Vector3(this.x, this.y, this.z); +}; + +GameLib.D3.Vector3.Runtime.prototype.updateInstance = function() { + + if (this.parentObject.updateInstance) { + this.parentObject.updateInstance(); + } + + this.apiVector.x = this.x; + this.apiVector.y = this.y; + this.apiVector.z = this.z; + +}; + + + GameLib.D3.Vector3.prototype.subtract = function (v) { return new GameLib.D3.Vector3( this.x - v.x,