Game Development Reference
In-Depth Information
this.matrixAutoUpdate = true;
this.matrixWorldNeedsUpdate = true;
this.visible = true;
};
First, we added a few variables such as quaternion to hold the rotation DOF,
location has been renamed to position , and new variables, scale and matrixWorld ,
have been added. If stageObject is the child object, then the final matrix,
worldMatrix , is the concatenation of its parent, matrixWorld , and modelMatrix .
The parent object and the children array have been added to hold the parent and
children information.
Two new variables, matrixAutoUpdate and matrixWorldNeedsUpdate , have
been added to reduce the possible computation time. Basically in our previous
code packets, we were calculating modelMatrix of each StageObject on every
animation frame. However, now, we will only calculate the matrices if any of the
DOFs ( scale , quaternion , and position ) change. On any DOF update, we will set
the matrixAutoUpdate and matrixWorldNeedsUpdate values to false , then only
modelMatrix and matrixWorld will be recalculated.
StageObject.prototype.rotate=function(radianX,radianY,radianZ) {
quat.rotateX(this.quaternion,this.quaternion,radianX);
quat.rotateY(this.quaternion,this.quaternion,radianY);
quat.rotateZ(this.quaternion,this.quaternion,radianZ);
}
StageObject.prototype.setRotationFromAxisAngle=function ( axis,
angle) {
// assumes axis is normalized
quat.setAxisAngle(this.quaternion, axis, angle );
}
StageObject.prototype.setRotationFromMatrix= function ( m ) {
// assumes the upper 3 x 3 of m is a pure rotation matrix
(that is, unscaled)
quat.fromMat3(this.quaternion, m );
}
StageObject.prototype.setRotationFromQuaternion=function ( q ) {
// assumes q is normalized
this.quaternion=quat.clone( q );
}
StageObject.prototype.rotateOnAxis= function(axis, angle) {
// rotate object on axis in object space
// axis is assumed to be normalized
quat.setAxisAngle(this.quaternion, axis, angle );
}
 
Search WWH ::




Custom Search