Game Development Reference
In-Depth Information
We also added a moveForward function. It moves the camera forward in the direction
it is pointing. We pass the distance as the parameter(s) and then multiply our
direction vector with this scalar and add or subtract the result from the position.
The moveForward function is defined as follows:
FreeCamera.prototype.moveForward = function(s) {
var newPosition = [this.pos[0] - s*this.dir[0], this.pos[1] -
s*this.dir[1], this.pos[2] - s*this.dir[2]];
this.setPosition(newPosition);
}
The next set of functions will be used in animation in Chapter 6 , Applying Textures
and Simple Animations to Our Scene . The objective of these functions is to move our
camera at a constant rate with the scene or use it as a first-person camera to move the
camera along with the model. These functions either move or rotate the camera at a
fixed or angular velocity, as shown in the following code:
FreeCamera.prototype.setAngularVel =function (newVec){
this.angVel[0] = newVec[0];
this.angVel[1] = newVec[1];
this.angVel[2] = newVec[2];
}
FreeCamera.prototype.getAngularVel =function (){
return vec3.clone(this.angVel);
}
FreeCamera.prototype.getLinearVel =function (){
return vec3.clone(this.linVel);
}
FreeCamera.prototype.setLinearVel =function (newVec){
this.linVel[0] = newVec[0];
this.linVel[1] = newVec[1];
this.linVel[2] = newVec[2];
}
FreeCamera.prototype.update =function (timeStep)
{
if (vec3.squaredLength(this.linVel) == 0 &&
vec3.squaredLength(this.angularVel) == 0)
return false;
if (vec3.squaredLength(this.linVel) > 0.0)
{
 
Search WWH ::




Custom Search