quaternion updates

beta.r3js.org
-=yb4f310 2017-09-10 13:10:49 +02:00
parent 9625c5a3b3
commit 49c35fb35c
5 changed files with 79 additions and 58 deletions

View File

@ -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

View File

@ -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(

View File

@ -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);

View File

@ -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;
}

View File

@ -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);