Viewing and Camera Control

advertisement
What you will learn about today
• Cameras in OpenGL
– Where this fits into world transformations
– Various types of cameras
What is moving?
frame1
frame2
frame3
Let’s Examine the Camera
• If I gave you a world, and said I want to
render it from another viewpoint, what
information do I have to give you?
–
–
–
–
–
–
Position
Which way we are looking
Which way is “up”
Aspect Ratio
Field of View
Near and Far
glm::lookat
Orients and positions the “camera”
lookat( eyex, eyey, eyez,
centerx, centery, centerz,
upx,upy, upz);
eye – the position of the camera in world coordinates
center – the camera is pointed at this point
up – the direction defined to be up for the camera
Moving the camera
How can we translate the camera?
add a vector to the eye and center parameters
How far will this move it?
the length of the vector
What happens if you don’t change the center?
the camera will stay fixed on the original point
Camera without glm::lookat?
How can we translate and orient the camera without
lookat?
inverse transforms: translate(-x,-y,-z); rotate(-angle, a,b,c)
Where does this go in your openGL program (using
lookat or not)?
- usually at the beginning of your display function
Camera: side view
View Right
View Up
View Normal
View Direction
Camera: looking through the
camera
View Up
View Right
What are the vectors?
Transformation World->Camera
1 0 0  camerax 
0 1 0  camera 
T 
y
0 0 1  cameraz 


0
0
0
1


N
n
 (n , n , n )
1
2
3
N
V N
u
 (u ,u ,u )
1
2
3
V N
v  n u  (v1 , v2 , v3 )
u1 u2
v v
2

R 1
n1

0
M W CVC
u3
v3
n2 n3
0 0
 R T
0
0

0

1
View Right = u
View Up = V
View Direction = -N
First Person Camera
• How is this implemented?
• Where is the ‘eye’?
• What is the look at point?
• What is up?
up
center
eye
First Person Camera
• How do we move the camera?
• Add a vector to eye and center
up
center
eye
move dir
First Person Camera
• How do we rotate the camera?
• Move the center point - add a vector to it
• Up vector
• Side vector: lookat x up
center
up
eye
Lookat implementation oddities
• What will happen if up == lookat direction?
• Spins around the up axis in a weird way
• Why does this happen?
• Two axes of your camera frame are aligned!
• How can we avoid this?
• Maintain an orthogonal camera frame - Reset the up
vector using lookat X side (e.g., more common in flight
games)
• Constrain the lookat direction to not get to close to the up
vector (e.g., common in FPS games)
• Use quaternions
3rd Person Camera
• How is this implemented?
• Where is the ‘eye’?
• What is the look at point?
• What is up?
3rd Person Camera
• Remember, initially the camera is
• At the origin looking down –z)
• Same as glm::lookat(0,0,0, 0,0,-1,0,1,0)
• How can this be more easily implemented without glm::lookat?
• translate the character so you can see it
• Draw the character
• Rotate the world around Y at the fixed point of the character
• Translate the world inversely to the character position
• Render the world
Birds Eye Camera
• How is this implemented?
• Where is the ‘eye’?
• What is the look at point?
• What is up?
Review: What you learned about
today
• Cameras in OpenGL
– Where this fits into world transformation
• The camera transform is performed after the world
transform
IS THE SAME AS:
• The camera is always at 0,0,0 looking down –z
• The world transforms instead
– Various types of cameras
• 1st, 3rd, birdseye
Download