1k likes | 1.03k Views
Learn how to capture 3D scenes like a pro using real and virtual camera methods with OpenGL codes explained in detail. Explore 3D viewing, perspective projection, and viewing transformations for stunning images!
E N D
CSCE 441 Computer Graphics3-D Viewing Jinxiang Chai
Outline 3D Viewing Required readings: HB 10-1 to 10-10 Compile and run the codes in page 388 - opengl three-dimensional viewing program example 1
Taking Pictures Using A Real Camera Steps: - Identify interesting objects - Rotate and translate the camera to a desired camera viewpoint - Adjust camera settings such as focal length - Choose desired resolution and aspect ratio, etc. - Take a snapshot
Taking Pictures Using A Real Camera Steps: - Identify interesting objects - Rotate and translate the camera to a desired camera viewpoint - Adjust camera settings such as focal length - Choose desired resolution and aspect ratio, etc. - Take a snapshot Graphics does the same thing for rendering an image for 3D geometric objects
3D Geometry Pipeline Rotate and translate the camera Object space World space View space Focal length Aspect ratio & resolution Normalized projection space Screen/Image space 5
Taking Steps Together C M Object space World space View space P V Normalized project space Image space 11
OpenGL Codes 12
OpenGL Codes 13
OpenGL Codes 14
3D Geometry Pipeline Object space World space View space Normalized project space Image space
3D Geometry Pipeline Translate, scale &rotate Object space World space glTranslate*(tx,ty,tz)
3D Geometry Pipeline Translate, scale &rotate Object space World space glScale*(sx,sy,sz)
3D Geometry Pipeline Translate, scale &rotate Object space World space Rotate about r by the angle glRotate*
3D Geometry Pipeline Object space World space View space Normalized projection space Image space Screen space
3D Geometry Pipeline World space View space Now look at how we would compute the world->eye transformation
3D Geometry Pipeline Rotate&translate World space View space Now look at how we would compute the world->eye transformation
Viewing Trans: gluLookAt gluLookAt(eyex,eyey,eyez,atx,aty,atz,upx,upy,upz) 23
Camera Coordinate Canonical coordinate system - usually right handed (looking down –z axis) - convenient for project and clipping
Camera Coordinate Mapping from world to eye coordinates - eye position maps to origin - right vector maps to x axis - up vector maps to y axis - back vector maps to z axis
Viewing Transformation We have the camera in world coordinates We want to model transformation T which takes object from world to camera
Viewing Transformation We have the camera in world coordinates We want to model transformation T which takes object from world to camera Trick: find T-1 taking object from camera to world
Viewing Transformation ? We have the camera in world coordinates We want to model transformation T which takes object from world to camera Trick: find T-1 taking object from camera to world
Review: 3D Coordinate Trans. p Transform object description from to 30
Review: 3D Coordinate Trans. Transform object description from camera to world
Viewing Transformation Trick: find T-1 taking object from camera to world - eye position maps to origin - back vector maps to z axis - up vector maps to y axis - right vector maps to x axis
Viewing Transformation H&B equation (10-4) Trick: find T-1 taking object from camera to world
Viewing Trans: gluLookAt gluLookAt(eyex,eyey,eyez,atx,aty,atz,upx,upy,upz)
Viewing Trans: gluLookAt gluLookAt(eyex,eyey,eyez,atx,aty,atz,upx,upy,upz) How to determine ? Mapping from world to eye coordinates
Viewing Trans: gluLookAt gluLookAt(eyex,eyey,eyez,atx,aty,atz,upx,upy,upz) How to determine ? Mapping from world to eye coordinates
Viewing Trans: gluLookAt gluLookAt(eyex,eyey,eyez,atx,aty,atz,upx,upy,upz) Mapping from world to eye coordinates
Viewing Trans: gluLookAt gluLookAt(eyex,eyey,eyez,atx,aty,atz,upx,upy,upz) Mapping from world to eye coordinates
Viewing Trans: gluLookAt gluLookAt(eyex,eyey,eyez,atx,aty,atz,upx,upy,upz) H&B equation (10-1) Mapping from world to eye coordinates
Viewing Trans: gluLookAt Test: gluLookAt( 4.0, 2.0, 1.0, 2.0, 4.0, -3.0, 0, 1.0, 0 ) - What’s the transformation matrix from the world space to the camera reference system?
3D Geometry Pipeline 3D-3D viewing transformation World space View space
Projection General definition transform points in n-space to m-space (m<n) In computer graphics map 3D coordinates to 2D screen coordinates
Projection How can we project 3d objects to 2d screen space? General definition transform points in n-space to m-space (m<n) In computer graphics map 3D coordinates to 2D screen coordinates
Perspective Projection Maps points onto “view plane” along projectors emanating from “center of projection” (COP)
Perspective Projection What’s relationship between 3D points and projected 2D points? Maps points onto “view plane” along projectors emanating from “center of projection” (COP) 48
3D->2D Consider the projection of a 3D point on the camera plane
3D->2D Consider the projection of a 3D point on the camera plane 50
3D->2D By similar triangles, we can compute how much the x and y coordinates are scaled Consider the projection of a 3D point on the camera plane
3D->2D By similar triangles, we can compute how much the x and y coordinates are scaled Consider the projection of a 3D point on the camera plane
Homogeneous Coordinates Is this a linear transformation?
Homogeneous Coordinates Is this a linear transformation? • no—division by z is nonlinear
Homogeneous Coordinates Is this a linear transformation? • Trick: add one more coordinate: • no—division by z is nonlinear homogeneous image coordinates homogeneous scene coordinates
Homogeneous Point Revisited If w=1, nothing happens Sometimes, we call this division step the “perspective divide” Remember how we said 2D/3D geometric transformations work with the last coordinate always set to one What happens if the coordinate is not one We divide all coordinates by w:
The Perspective Matrix Now we can rewrite the perspective projection equation as matrix-vector multiplications
The Perspective Matrix This becomes a linear transformation! Now we can rewrite the perspective projection equation as matrix-vector multiplications