Game Development Reference
In-Depth Information
vec3.cross(this.up, this.dir, this.left);
vec3.normalize(this.up, this.up);
vec3.cross( this.left , this.up, this.dir);
vec3.normalize(this.left , this.left);
}
}
Understanding the yaw function for the orbit camera
The orbit camera's yaw function algorithm is as follows:
If the orbit point and position are the same, perform the following steps:
1.
We calculate the rotation quaternion from the global up vector [0,1,0] and not
from the camera up vector as follows:
quat.setAxisAngle(quate,[0, 1, 0], angle);
2.
The camera position does not change. We transform each vector with the
quaternion like we do in the free camera as follows:
vec3.transformQuat(this.dir, this.dir, quate);
vec3.transformQuat(this.left, this.left, quate);
vec3.transformQuat(this.up, this.up, quate);
3.
Compute unit vectors for all three vectors.
If the orbit point and camera position are different, perform the following steps:
1.
Create a rotation quaternion around the global up vector as follows:
quat.setAxisAngle(quate, [0,1,0], angle);
2.
Calculate the new position after transforming the old position with a
quaternion. This calculates a new position relative to the origin.
vec3.transformQuat(newpos,this.pos,quate);
3.
Transform the position from relative to origin to relative to orbit point
as follows:
vec3.add(this.pos,newpos, this.orbitPoint);
4.
Calculate the direction vector from the orbit point and new position, and
calculate the unit direction vector as follows:
vec3.subtract(this.dir,this.orbitPoint, this.pos);
vec3.normalize(this.dir,this.dir);
5.
Calculate the up vector after transforming it with the quaternion as follows:
vec3.transformQuat(this.up, this.up, quate);
 
Search WWH ::




Custom Search