/
The Camera Navigating and viewing The Camera Navigating and viewing

The Camera Navigating and viewing - PowerPoint Presentation

kittie-lecroy
kittie-lecroy . @kittie-lecroy
Follow
342 views
Uploaded On 2019-11-21

The Camera Navigating and viewing - PPT Presentation

The Camera Navigating and viewing the virtual world Camera properties and definition Perspective transformation Quaternion transforms for changing camera Road Map pinhole camera model tiny aperture finite size screen ID: 766320

perspective camera orientation direction camera perspective direction orientation position matrix viewing world projection vector current aperture quaternion transform move

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "The Camera Navigating and viewing" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

The Camera Navigating and viewing the virtual world

Camera properties and definition Perspective transformation Quaternion transforms for changing camera Road Map

pinhole camera model tiny aperture finite size screen The Camera Light from world aperture Light strikes screen

Recall that we used 3 matrices for transformation in the BasicEffect :world (for where the object is in the virtual world) viewing (describes transformation of world to canonical space in front of camera) projection (transform from 3D world to 2D screen) Separation allows us to deal with each independently Viewing and Projection

operation to transform 3D world coordinates to 2D screen coordinates orthogonal projection: parallel rays perspective projection: rays pass through aperture (pinhole, human eye) Projections

Simple projection: (x,y,z,1)  (x,y) z value used in depth buffer Orthogonal Projection

only map objects within "canonical" viewing volume If the world is bigger (and not properly oriented) need coordinate transform to map into canonical volume Canonical View Volume

Previously, assumed the camera was axis-aligned Not typically the case! Specify camera position, orientation Common mechanism: camera position viewing direction up direction Arbitrary view direction

Given gaze direction g, up direction h "Camera axes": say u, v, w w = -g/|g| (gaze direction is – z) u = h x w / | h x w | v = w x u Arbitrary view direction

Projections Orthographic Perspective

Perspective In classical perspective, have vanishing points Parallel lines appear to converge

Orthographic projection works when we have a large aperture Our experience of the world is in perspective : distant objects look smaller Perspective aperture small object large object Objects have same apparent size

Viewing Frustum near plane z = n far plane z = f "frustum": a truncated cone or pyramid

Perspective aperture y g y r n z g y s = y g (n/ z g ) y s y s = y r (n/ z r ) z r

Need to divide by z No division with matrices Again use homogeneous coordinates: "homogenize" operation The perspective divide y s = y r (n/ z r )

Homogenizing x y z 1 equiv hx hy hz h for any nonzero h

Perspective Matrix 1 0 0 0 0 1 0 0 0 0 (n+f)/n -f 0 0 1/n 0

Perspective Matrix n 0 0 0 0 n 0 0 0 0 n+f -fn 0 0 1 0

Perspective Matrix n 0 0 0 0 n 0 0 0 0 n+f -fn 0 0 1 0 x y z 1 nx ny (n+f)z-fn z =

Perspective Matrix n 0 0 0 0 n 0 0 0 0 n+f -fn 0 0 1 0 x y z 1 nx ny (n+f)z-fn z = nx/z ny/z (n+f)-fn/z 1 homogenize

Perspective Matrix n 0 0 0 0 n 0 0 0 0 n+f -fn 0 0 1 0 x y z 1 nx ny (n+f)z-fn z = nx/z ny/z (n+f)-fn/z 1 homogenize y s = y g (n/ z g ) compare:

We need to preserve Z ordering so that depth tests still work The perspective matrix preserves Z At z=f, preserves z=f At z=n, preserves z=n At intermediate values, preserves order What happens to Z

Wide-angle perspective looks weird Human focal region has small solid angle – we do not experience severe perspective distortion Technically correct results may not be perceptually correct Perils of Perspective

Recall that to specify camera position and orientation, need 6 quantities: 3 for 3D position “ forward direction” (unit axis, 2 scalars to specify) “up direction” (orthogonal to forward, can be specified just with an angle, one scalar) This info goes into the viewing transform Camera Orientation

Matrix.CreateLookAt ( cameraPosition , // where the camera is targetPosition , // where camera looks at upVector // “up” direction (towards top) ); XNA Viewing

Can apply transformations to viewing matrix translations, rotations… Can also recreate matrix at each frame inexpensive compared to everything else! Need to track camera orientation and position vector for position quaternion for orientation Changing Camera

contains: position (vector) forward direction (vector)up direction (vector) Want to be able to swing the camera sideways, up and down, spin (roll), plus move Example Camera

Change position according to current velocity x( t+dt) = x(t) + v(t) dt Might have v(t) from player control, or velocity of body being followed Might have specific camera dynamics Moving the camera

Often interpret player controls in terms of current heading move forward move backward strafe right, left change orientation (right, left, up, down, roll, all in current frame of reference) Player control

With forward and up known as part of camera, can change position easily move forward: x( t+dt) = x(t) + f(t)*s* dt s = speed, f(t) = forward direction at time t can get sideways vector as u x f (cross product) moving sideways uses same principle as moving forward, just direction differs Player control

Store orientation as quaternion q Update forward, up directions using current q rotation of initial forward f 0 , initial up u 0 say p = (0,f0), q’ = conjugate of qfor q = ( s,v ), q' = (s,-v) f = vector( qpq ’)In XNA, f = Vector.Transform(f0, q) Describing orientation

Now, changing camera orientation is easy: Rotations about current forward, up, side axes available, or obtained from cross product Quaternion.CreateFromAxisAngle (axis, angle); describes rotation Compose with current quaternion:q = Quaternion.Multiply ( q,qrot );Normalize q, and voila! Changing orientation