Add Camera::LookAt

This is identical to the POV-Ray look_at keyword for cameras. In fact, I stole the code almost directly from them… It's super handy for panning and tilting the camera towards a particular point, and saves me having to do dubiously accurate direction vector calculations by hand.

I still need to figure out what exactly this math is doing.
This commit is contained in:
Eryn Wells 2014-08-03 18:33:09 -07:00
parent e64b9403ac
commit 7297bc5c17
4 changed files with 52 additions and 0 deletions

View file

@ -93,6 +93,31 @@ Camera::SetUp(const Vector3& up)
mUp = up;
}
void
Camera::LookAt(const Vector3& pt)
{
const Double directionLength = mDirection.length();
const Double rightLength = mRight.length();
const Double upLength = mUp.length();
/* TODO: What does this actually do? */
const Double handedness = mUp.cross(mDirection).dot(mRight);
mDirection = (pt - mOrigin).normalize();
/* TODO: Check for zero length direction vector. */
mRight = Vector3::Y.cross(mDirection).normalize();
mUp = mDirection.cross(mRight);
mDirection *= directionLength;
if (handedness > 0.0) {
mRight *= rightLength;
} else {
mRight *= -rightLength;
}
mUp *= upLength;
}
#pragma mark - Perspective Camera
PerspectiveCamera::PerspectiveCamera()