Game Development Reference
In-Depth Information
2.
Calculate the new position after transforming the old position with the
quaternion. This calculates the new position relative to the origin.
vec3.transformQuat(newpos,this.pos,quate);
3.
Transform the position relative to the origin to relative to the orbit point
as follows:
vec3.add(this.pos,newpos, this.orbitPoint);
4.
Calculate the direction vector from the orbit point and new position and also
calculate the unit direction as follows:
vector.(vec3.subtract(this.dir,this.orbitPoint, this.pos);
vec3.normalize(this.dir, this.dir));
5.
Calculate the up vector using the cross product of the direction and left
vectors. Compute the unit up vector and normalize it as shown in the
following code:
vec3.cross(this.up,this.dir, this.left);
vec3.normalize(this.up,this.up));
6.
Calculate the left vector using the cross product of the up and direction
vectors. Compute the unit left vector and normalize it as shown in the
following code:
vec3.cross( this.left ,this.up, this.dir);
vec3.normalize(this.left ,this.left))
The complete pitch function is defined as follows:
OrbitCamera.prototype.pitch = function (angle) {
if (isVectorEqual(this.pos, this.orbitPoint)) {
var quate=quat.create();
quat.setAxisAngle(quate, this.left, angle);
vec3.transformQuat(this.dir, this.dir, quate);
vec3.normalize(this.dir,this.dir);
vec3.cross(this.up,this.dir, this.left);
vec3.normalize(this.up, this.up);
}
else {
vec3.subtract(this.pos,this.pos, this.orbitPoint);
var quate =quat.create();
quat.setAxisAngle(quate,this.left, angle);
var newpos = vec3.create();
vec3.transformQuat(newpos, this.pos,quate);
vec3.add(this.pos, newpos, this.orbitPoint);
vec3.subtract(this.dir, this.orbitPoint, this.pos);
vec3.normalize(this.dir, this.dir);
 
Search WWH ::




Custom Search