//-----------------------------------------------------------------------------
// Camera Object - Movement & Orientation
//-----------------------------------------------------------------------------
void camera::look( const glm::vec3& inTarget ) {
glm::vec3 diffTarget ( pos - inTarget );
glm::quat rotations ( 0.f, diffTarget );
glm::vec3 angles ( glm::angle( rotations ) );
pitch = angles.x;
yaw = angles.y;
roll = angles.z;
}
void camera::move( float dx, float dy, float dz ) {
pos.x += dx;
pos.y += dy;
pos.z += dz;
}
void camera::rotate( float dPitch, float dYaw, float dRoll ) {
pitch = dPitch;
yaw = dYaw;
roll = dRoll;
}
//-----------------------------------------------------------------------------
// Camera - Updating
//-----------------------------------------------------------------------------
void camera::update() {
//update the rotations
glm::quat rotateX( std::cos( pitch ), std::sin( pitch ), 0.f, 0.f );
glm::quat rotateY( std::cos( yaw ), 0.f, std::sin( yaw ), 0.f );
glm::quat rotateZ( std::cos( roll ), 0.f, 0.f, std::sin( roll ) );
glm::quat endRot = rotateZ * rotateY * rotateX;
switch( camType ) {
default:
case CAM_TYPE_FPS:
target.x = endRot.x;
target.y = endRot.y;
target.z = endRot.z;
break;
case CAM_TYPE_SPECTATOR:
eye = endRot;
break;
}
mvp
= projMat
* glm::lookAt( pos, target, up )
* glm::mat4_cast( eye );
}