Game Development Reference
In-Depth Information
6.
Calculate the left vector using the cross product of up and direction vectors.
Compute the unit left vector ( vec3.cross( this.left, this.up, this.
dir); vec3.normalize(this.left, this.left) ):
OrbitCamera.prototype.yaw = function (angle) {
if (isVectorEqual(this.pos, this.orbitPoint)) {
var quate=quat.create();
quat.setAxisAngle(quate,[0, 1, 0], angle);
vec3.transformQuat(this.dir, this.dir, quate)
vec3.transformQuat(this.left, this.left, quate)
vec3.transformQuat(this.up, this.up, quate)
vec3.normalize(this.up,this.up);
vec3.normalize(this.left,this.left);
vec3.normalize(this.dir,this.dir);
}
else {
var camPosOrbit =vec3.create();
vec3.subtract(camPosOrbit,this.pos, this.orbitPoint);
var quate=quat.create();
quat.setAxisAngle(quate,[0, 1, 0], angle);
var newpos = vec3.create();
vec3.transformQuat(newpos, camPosOrbit, quate);
vec3.add(this.pos,newpos, this.orbitPoint);
vec3.subtract(this.dir,this.orbitPoint, this.pos);
vec3.normalize(this.dir,this.dir);
vec3.transformQuat(this.up, this.up, quate)
vec3.normalize(this.up,this.up);
vec3.cross(this.left,this.up, this.dir);
vec3.normalize(this.left,this.left);
}
}
The next function is setDistance where we set the initial camera location. It simply
copies the orbitpoint to position and then invokes goFarther .
OrbitCamera.prototype.setDistance = function (distance)
{
if (distance >= this.getClosestDistance() && distance <= this.
getFarthestDistance())
{
// place the camera at the orbit point, then goFarther
vec3.copy(this.pos,this.orbitPoint);
this.goFarther(distance);
}
}
 
Search WWH ::




Custom Search