CM0304 Graphics I Graphics Hardware I.1 Graphics Systems
CMT107 Visual Computing
Copyright By PowCoder代写 加微信 powcoder
II.2 Viewing
Xianfang Sun
School of Computer Science & Informatics
Cardiff University
➢ Projection
• Parallel projection
• Perspective projection
➢ OpenGL viewing
3:56 PM 2CMT107 Visual Computing
Viewing Transformations
3:56 PM 3CMT107 Visual Computing
➢ Viewing transformations:
• Camera transformation: 3D world coordinates to 3D
camera coordinates
• Projection transformation: Define a viewing volume, and
transform 3D camera coordinates onto the view plane
• Viewport transformation: The image on the view plane is
translated and scaled to be fitted in the viewport on the
Projection
3:56 PM 4CMT107 Visual Computing
➢ General definition
• Transform points in nD space to mD space, n > m
➢ In computer graphics:
• Map 3D camera coordinates to 2D view plane coordinates
• Also map depth to a specific range ([0, 1], related to
viewing volume)
Parallel Projection
3:56 PM 5CMT107 Visual Computing
➢ Centre of projection is at infinity
➢ Direction of projection (DOP) is the same for all points
Parallel Projection Matrix
3:56 PM 6CMT107 Visual Computing
➢ General parallel projection transformation (defined by , )
• Orthogonal (orthographic) projection for = 90
Orthographic Projection
3:56 PM 7CMT107 Visual Computing
➢ Direction of projection orthogonal to view plane
• Points with the same (x, y) coordinates will project at
the same point on the view plane
➢ Applications: for exact scaling the object like CAD etc
➢ Direction of projection not orthogonal to view plane
• For cavalier projection ( = 45),
two points with the same (x, y)
coordinates will keep their
distance on the view plane
• For cabinet projection (= 63.4),
two points with the same (x, y)
coordinates will half their
distance on the view plane
➢ Applications: for technical drawing
and illustration like in furniture, or
architecture, etc.
Oblique Projection
3:56 PM 8CMT107 Visual Computing
Perspective Projection
3:56 PM 9CMT107 Visual Computing
➢ Map points onto view plane along projectors emanating
from centre of projection
➢ Application : for art drawings, especially for representing
large scenes.
Perspective Projection
3:56 PM 10CMT107 Visual Computing
➢ Compute 2D coordinates from 3D coordinates using
similar triangles
Perspective Projection Matrix
3:56 PM 11CMT107 Visual Computing
➢ 44 homogeneous coordinates matrix representation
Perspective vs. Parallel Projection
3:56 PM 12CMT107 Visual Computing
➢ Perspective projection
• Size varies inversely with distance – looks realistic
• Distance and angles are not (in general) preserved
• Parallel lines do not (in general) remain parallel
➢ Parallel projection
• Good for exact measurements
• Parallel lines remain parallel
• Angles are not (in general) preserved
• Less realistic looking
Viewport on Screen
3:56 PM 13CMT107 Visual Computing
➢ Coordinate systems on display:
• Screen coordinate system: Origin at the upper-left
corner of the screen, x direction from left to right, and
y direction from top to bottom
• Window coordinate system: Origin at the lower-left
corner of the window, x direction from left to right,
and y direction from bottom to top
• Viewport: The rectangular
region in the window where
the image is drawn. Defined
on window coordinate
system by (x0, y0, w, h)
Viewport Transformation
3:56 PM 14CMT107 Visual Computing
➢ The whole image on the view plane are mapped on the
whole viewport (by scaling and translating)
➢ To avoid distortion, the aspect ratio of the viewport
should be equal to the aspect ratio of the viewing volume
• aspect ratio: The ratio of the width to the height of a
rectangle area (w/h)
OpenGL Projection
3:56 PM 15CMT107 Visual Computing
➢ Actual projection is set by projection matrix
➢ Projection matrix specifies parallel or perspective
projection parameters
➢ Projection matrix is essentially defined by selecting a
viewing volume (the region camera can see)
➢ Points inside the viewing volume are projected into a
cube of edge length 2 (x, y, and z all range from -1 to 1)
• Depths are maps of the z coordinate to the range [0, 1]
➢ Orthographic and perspective projections are
implemented in class Transform, simulating the projection
functions in OpenGL fixed-function pipeline
Parallel Projection Viewing Volume
3:56 PM 16CMT107 Visual Computing
Perspective Projection Viewing Volume
3:56 PM 17CMT107 Visual Computing
Orthographic Viewing in Transform
3:56 PM 18CMT107 Visual Computing
ortho (xmin, xmax, ymin, ymax, near, far);
➢ Projection matrix:
➢ No oblique projection is implemented
Perspective Viewing in Transform
3:56 PM 19CMT107 Visual Computing
frustum (xmin, xmax, ymin, ymax, near, far);
➢ Projection matrix:
Using Field of View
3:56 PM 20CMT107 Visual Computing
➢ frustum not intuitive
➢ Better interface (for symmetric frustum):
perspective (fovy, aspect, near, far) =
frustum (-w2, w2, -h2, h2, near, far);
OpenGL Viewport
3:56 PM 21CMT107 Visual Computing
glViewport (x, y, width, height);
➢ Default value (0, 0, winWidth, winHeight)
• winWidth and winHeight specify the size of the window
➢Map points drawn on the view plane into the viewport
• Coordinate transforming from ([-1,-1] ~[1,1]) on the camera
coordinate system to ([x,y] ~[x+width,y+height]) on the
window coordinate system
➢When combined with perspective(), either
• glViewport (x, y, width, height);
perspective(fovy, width/height, near, far);
• glViewport (x, y, width, width/aspect);
perspective(fovy, aspect, near, far);
➢ Similar when combined with ortho()
3:56 PM 22CMT107 Visual Computing
➢ How are world coordinates transformed into camera
coordinates? Why is this done?
➢ What is parallel projection? How is it computed?
➢ What is perspective projection? How is it computed?
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com