diff --git a/src/game-lib-a-2-utils.js b/src/game-lib-a-2-utils.js index 6876cf4..a9b2498 100644 --- a/src/game-lib-a-2-utils.js +++ b/src/game-lib-a-2-utils.js @@ -84,7 +84,7 @@ GameLib.Utils.LoadIdsFromArrayToIdObject = function(array, idToObject) { } } else if (typeof object === 'string') { - console.warn('Linked object found:' + object); + // console.warn('Linked object found:' + object); } else { console.warn('Unhandled type of object: ', object); } @@ -115,7 +115,7 @@ GameLib.Utils.LoadIdsFromObjectToIdObject = function(object, idToObject) { console.warn('Object with no ID passed: ' + object) } } else if (typeof object === 'string') { - console.warn('Linked object found:' + object); + // console.warn('Linked object found:' + object); } else { console.warn('Unhandled type of object: ', object); } @@ -178,6 +178,35 @@ GameLib.Utils.IdOrNull = function (object) { } }; +/** + * Limit a property to values between -pi and +pi + * @param property + * @param objectProperty + * @returns {{configurable?: boolean, enumerable?: boolean, value?, writable?: boolean, get?: Function, set?: Function}} + * @constructor + */ +GameLib.Utils.LimitToPI = function(property, objectProperty) { + + var store = objectProperty; + + return { + get : function() { + return store; + }, + set : function(value) { + while (value > Math.PI) { + value -= (Math.PI * 2); + } + + while (value < -(Math.PI)) { + value += (Math.PI * 2); + } + + store = value; + } + }; +}; + /** * Returns an array of IDs representing the objects * @param array diff --git a/src/game-lib-d3-mesh-0.js b/src/game-lib-d3-mesh-0.js index e95c64b..9504356 100644 --- a/src/game-lib-d3-mesh-0.js +++ b/src/game-lib-d3-mesh-0.js @@ -125,44 +125,22 @@ GameLib.D3.Mesh = function ( this ); - var limitToPI = function(property, objectProperty) { - - var store = objectProperty; - - return { - get : function() { - return store; - }, - set : function(value) { - while (value > Math.PI) { - value -= (Math.PI * 2); - } - - while (value < -(Math.PI)) { - value += (Math.PI * 2); - } - - store = value; - } - }; - }; - Object.defineProperty( this.localRotation, 'x', - limitToPI('x', this.localRotation.x) + GameLib.Utils.LimitToPI('x', this.localRotation.x) ); Object.defineProperty( this.localRotation, 'y', - limitToPI('y', this.localRotation.y) + GameLib.Utils.LimitToPI('y', this.localRotation.y) ); Object.defineProperty( this.localRotation, 'z', - limitToPI('z', this.localRotation.z) + GameLib.Utils.LimitToPI('z', this.localRotation.z) ); this.localScale = new GameLib.Vector3( diff --git a/src/game-lib-entity-manager.js b/src/game-lib-entity-manager.js index 3c17f64..3998743 100644 --- a/src/game-lib-entity-manager.js +++ b/src/game-lib-entity-manager.js @@ -61,29 +61,29 @@ GameLib.EntityManager.prototype.registerComponent = function(data) { GameLib.EntityManager.prototype.removeComponent = function(data) { - if (data.component instanceof GameLib.Entity) { - - /** - * if this is an entity - remove all its children components first - */ - data.component.components.map( - function(component) { - var index = this.register.indexOf(component); - - if (index !== -1) { - - this.register.splice(index, 1); - - GameLib.Event.Emit( - GameLib.Event.REGISTER_UPDATE, - { - register : this.register - } - ); - } - }.bind(this) - ) - } + // if (data.component instanceof GameLib.Entity) { + // + // /** + // * if this is an entity - remove all its children components first + // */ + // data.component.components.map( + // function(component) { + // var index = this.register.indexOf(component); + // + // if (index !== -1) { + // + // this.register.splice(index, 1); + // + // GameLib.Event.Emit( + // GameLib.Event.REGISTER_UPDATE, + // { + // register : this.register + // } + // ); + // } + // }.bind(this) + // ) + // } if (data.component.parentEntity instanceof GameLib.Entity) { data.component.parentEntity.removeComponent(data.component); diff --git a/src/game-lib-quaternion.js b/src/game-lib-quaternion.js index b03e1aa..ba6b3c2 100644 --- a/src/game-lib-quaternion.js +++ b/src/game-lib-quaternion.js @@ -56,6 +56,12 @@ GameLib.Quaternion = function ( this.grain ); + Object.defineProperty( + this, + 'angle', + GameLib.Utils.LimitToPI('angle', this.angle) + ); + if (GameLib.Utils.UndefinedOrNull(grain)) { grain = 0.001; } diff --git a/src/game-lib-system-gui.js b/src/game-lib-system-gui.js index 7c99955..cdb5f8b 100644 --- a/src/game-lib-system-gui.js +++ b/src/game-lib-system-gui.js @@ -194,12 +194,20 @@ GameLib.System.GUI.prototype.onChange = function(property, subProperty, affected } }; -GameLib.System.GUI.prototype.controller = function(folder, object, property, subProperty, step, listen, affected) { +GameLib.System.GUI.prototype.controller = function(folder, object, property, subProperty, step, listen, affected, min, max) { - var min = -100; - var max = 100; + if (GameLib.Utils.UndefinedOrNull(min)) { + min = -100; + } - if (property === 'localRotation') { + if (GameLib.Utils.UndefinedOrNull(max)) { + max = 100; + } + + + if ( + property === 'localRotation' + ) { min = -Math.PI; max = Math.PI; } @@ -260,7 +268,7 @@ GameLib.System.GUI.prototype.buildQuaternionControl = function(folder, component this.controller(folder, object, property, 'y', step, listen, affected); this.controller(folder, object, property, 'z', step, listen, affected); this.controller(folder, object, property, 'w', step, listen, affected); - this.controller(folder, object, property, 'angle', step, listen, affected); + this.controller(folder, object, property, 'angle', 0.001, listen, affected, -Math.PI, Math.PI); folder.add( object[property]['axis'], @@ -268,7 +276,7 @@ GameLib.System.GUI.prototype.buildQuaternionControl = function(folder, component -1, 1, 0.01 - ).onChange( + ).name('quaternion.axis.x').onChange( function(value) { affected.map(function(component){ component[property]['axis'].x = Number(value); @@ -283,7 +291,7 @@ GameLib.System.GUI.prototype.buildQuaternionControl = function(folder, component -1, 1, 0.01 - ).onChange( + ).name('quaternion.axis.y').onChange( function(value) { affected.map(function(component){ component[property]['axis'].y = Number(value); @@ -298,7 +306,7 @@ GameLib.System.GUI.prototype.buildQuaternionControl = function(folder, component -1, 1, 0.01 - ).onChange( + ).name('quaternion.axis.z').onChange( function(value) { affected.map(function(component){ component[property]['axis'].z = Number(value);