Game Development Reference
In-Depth Information
The preceding set of functions translates StageObject along the given axis. The key
function is translateOnAxis , and all other functions are dependent on it.
StageObject.prototype.localToWorld= function ( vector ) {
var v1=vec3.create();
vec3.transformQuat(v1,vector,this.matrixWorld );
return v1;
};
StageObject.prototype.worldToLocal= function () {
var m1 = mat4.create();
return function ( vector ) {
mat4.invert(m1,this.matrixWorld);
var v1=vec3.create();
vec3.transformQuat(v1,vector,m1 );
return v1;
};
}();
The preceding functions transform any vector from the world space to the object's
local space and vice versa.
StageObject.prototype.add=function ( object ) {
if ( object === this ) {
return;
}
if ( object.parent !== undefined ) {
object.parent.remove( object );
}
object.parent = this;
//object.dispatchEvent( { type: 'added' } );
this.children.push( object );
// add to scene
};
StageObject.prototype.remove= function ( object ) {
var index = this.children.indexOf( object );
if ( index !== - 1 ) {
object.parent = undefined;
//object.dispatchEvent( { type: 'removed' } );
this.children.splice( index, 1 );
}
}
 
Search WWH ::




Custom Search