Game Development Reference
In-Depth Information
StageObject.prototype.rotateX= function (angle) {
var v1 = vec3.fromValues( 1, 0, 0 );
return this.rotateOnAxis( v1, angle );
}
StageObject.prototype.rotateY= function (angle) {
var v1 = vec3.fromValues( 0, 1, 0 );
return this.rotateOnAxis( v1, angle );
}
StageObject.prototype.rotateZ=function (angle) {
var v1 = vec3.fromValues( 0, 0, 1 );
return this.rotateOnAxis( v1, angle );
}
The preceding set of functions either initializes the quaternion or simply updates it
with new values. The implementation of the preceding functions uses the quat class
of the glMatrix library.
StageObject.prototype.translateOnAxis= function (axis, distance) {
// translate object by distance along axis in object space
// axis is assumed to be normalized
var v1 = vec3.create();
vec3.copy(v1, axis );
vec3.transformQuat(v1, v1, this.quaternion);
vec3.scale(v1, v1, distance);
vec3.add(this.position, this.position, v1);
return this;
}
StageObject.prototype.translateX= function () {
var v1 = vec3.fromValues( 1, 0, 0 );
return function ( distance ) {
return this.translateOnAxis( v1, distance );
};
}();
StageObject.prototype.translateY= function () {
var v1 = vec3.fromValues( 0, 1, 0 );
return function ( distance ) {
return this.translateOnAxis( v1, distance );
};
}();
StageObject.prototype.translateZ= function () {
var v1 = vec3.fromValues( 0, 0, 1 );
return function ( distance ) {
return this.translateOnAxis( v1, distance );
};
}();
 
Search WWH ::




Custom Search