Lecture 12 - Pitch and Yaw Camera
As a look-ahead:
- lab 8 will be on 3D Camera.
- Project 4 will be due next Monday, rather than at the end of Thursday this week. That's because you'll be implementing the camera tech we will talk about today into it.
- Lab 9/10 will be on a particle system (this will be good for Final Project Sketch)
- Also includes boids, or a group background animation for things like NPCs
- And then another advanced rendering technique (TBD by Zoe later)
- Final Project: demoed in person during Finals Week
- There's two required check-ins in-person to make sure you're manage is timed.
This week, we'll discuss:
- virtual camera
- review of the graphics pipeline, namely how projections works as well as clipping & culling
- a grab bag exposing you to effects for your Final Project
- advanced graphics topics
Animation: Control Along Curves
When we did hiearchical modeling, we would instead probably want to animate over a curve instead:
We might also want to move some point along a curve that isn't linear, like shown above. But how do we represent these curves? The P4 code has some of these splines, and if we look in there in Bezier.h
we can get a better idea of what's going on.
The Camera: The V
Matrix
We use the View matrix V
as a way to translate, rotate, etc. the world we've already made.
We already have this, so now we need to first know what the position of the camera/eye is in the world. We can use glm::LookAt()
to generate this V
matrix:
glm::LookAt(
vec3 eyePositionInTheWorld,
vec3 eyeLookAtPoint, // essentially helps generate the lookingDirection from eyeLookAtPoint - eyePositionInTheWorld
vec3 UpVector, // almost always (0,1,0). Most games do this. Generates the 'barell-roll' angle in case we want to rotate our view in that plane.
);
So for this camera you need to do:
- Pitch and Yaw (look anywhere)
- WASD (go anywhere)
- Translate
eyePositionInTheWorld
to move anywhere
- Translate
We'll talk about Pitch and Yaw in more detail here.
Pitch and Yaw
We can use eyeLookAtPoint
from getting the spherical coordinate into cartesian:
and really when we move the mouse some position
And
Strafing and Dollying
Say we want to strafe left/right. How do we translate to do that? You don't just move along
Thus we need the cross product!:
and for dollying, we just move in the direction of the view vector:
Defining our Camera
We'll make a Camera Object Camera
which will use our function above.
We'll want to use orthonormal basis vectors which are vectors of:
- unit length
- perpendicular to one another
Namely, we can do a change of basis to convert our standard world basis vectors to our camera basis vectors:
Namely, we just use two matrices, the translation matrix, and the rotation matrix:
We form these basis vectors for the camera
is just
Look at how these are generated:
is generated by flipping our vector, then normallizing it. need to be perpendicular to (we need an orthonormal basis, remember), then we want to have not point in the direction of since we usually have the second vector (like ) to be the up direction. Hence needs to be that, so needs to be perpendicular to . is just perpendicular to .