Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics CC416 Week 14 3D Graphics.

Similar presentations


Presentation on theme: "Computer Graphics CC416 Week 14 3D Graphics."— Presentation transcript:

1 Computer Graphics CC416 Week 14 3D Graphics

2 3D Viewing

3 3D Viewing Viewing: virtual camera Projection Depth
Visible lines and surfaces Surface rendering

4 3D Viewing pipeline 1 Similar to making a photo
Position and point virtuele camera, press button; Projection plane aka Viewing plane Pipeline has +/ same structure as in 2D

5 Synthetic Camera Metaphor for creating 3D scenes: Coordinate system:
Camera: u, v, n Object: x, y, z

6 3D Viewing pipeline 2 MC: Modeling Coordinates WC: World Coordinates
VC: Viewing Coordinates PC: Projection Coordinates NC: Normalized Coordinates DC: Device Coordinates Apply model transformations To camera coordinates Project To standard coordinates Clip and convert to pixels

7 Right hand coordinate system
Coordinate Systems Y +z x x +z Left hand coordinate system Not used in this class and Not in OpenGL Right hand coordinate system

8 3D viewing coordinates 1 zvp Specification of projection: P0 : View or eye point Pref : Center or look-at point V: View-up vector (projection along vertical axis) zvp : positie view plane yw P0 N V Pref xw zw P0, Pref , V: define viewing coordinate system Several variants possible

9 3D viewing coordinates 2 xview yview zview yw P0 N V Pref xw zw P0, Pref , V: define viewing coordinate system Several variants possible

10 3D view coordinates 3 n xview yview u v zview yw P0 N V Pref xw zw

11 Transform the left-handed eye coordinate system defined by v, u and VPN into the right-handed world coordinate system The origin of the eye coordinate system, COP is translated to the origin (0, 0, 0,) of the world coordinate system. Rotate so that The axis in the u direction is parallel to the world coordinate x-axis. The axis in the v direction is parallel to the world coordinate y-axis. The VPN is parallel to the negative z-axis, that is, going into the display screen. Make the negative z-axis the positive direction so that the positive z direction goes into the screen, i.e., make the eye coordinate system left-handed.

12 The matrices required to accomplish this transformation are given next.
The viewing coordinate origin is at a world position P0 (x0, y0, z0), the translation matrix to translate the viewing origin to the world origin is: x0 T = y0 z0 The rotation matrix that super imposes the viewing axes onto the world frame, using the u, v, n unit vectors, is ux uy uz 0 R = vx vy vz 0 nx ny nz 0

13 The coordinate transformation matrix is obtained by product R.T
MWC, VC = R.T ux uy uz -u.P0 = vx vy vz -v.P0 nx ny nz -n.P0 Where the translation unit vectors are the dot product: u.P0 = -x0ux – y0uy – z0uz v.P0 = -x0vx – y0vy – z0vz n.P0 = -x0nx – y0ny – z0nz

14 Steps in 3D Viewing Projection type specification
Why projection? Objects 3D, device 2D Two most important Perspective Parallel orthographic Viewing parameter specification Viewing plane Viewing (eye) coordinate system Scene coordinate system

15 Projections Projection Our concern Terminology
Transformation from n-D coordinate system to m-D coordinate system, where m < n Our concern n = 3 and m = 2  projection from 3D to 2D Terminology Projectors: Straight projection rays Center of projection: Where the projectors emanated from Projection plane: Where the projection forms

16 Projections Projection from 3D to 2D defined by
Projectors emanate from center of projection (COP), pass through each point of the object, and intersect the projection plane Planar geometric projections Projection is onto a plane Referred to as "projections" here

17 Projections Two Basic Classes Perspective Parallel
Distance between projection plane and COP is finite Visual effect similar to human visual system Perspective foreshortening: distance from COP longer, size smaller Exact shape, measurement, parallelism not reserved

18 Perspective Projection
Given a vertex in the eye coordinate system, v = (xe, ye, ze), the projected screen coordinates, (xs, ys) are computed as: Where d is the distance from COP to the view plane. These formulas are easily derived by considering the projection onto the x-z and y-z planes

19 Projections Parallel Distance between projection plane and COP is infinite Less realistic view Exact measurement and parallelism preserved Perspective Parallel

20 Classification of Planar Geometric Projections

21 Specification of an Arbitrary 3D View
View Plane Projection Plane Defined by VRP (View Reference Point) look at point in OpenGL VPN (View Plane Normal) (eye - look) in OpenGL

22 Specification of an Arbitrary 3D View
Window Similar to the window in 2D Contents mapped to the viewport Projection on the view plane outside the window not shown Specification needs the following Minimum and maximum window coordinates Two orthogonal axes Can be defined by view volume

23 Specification of an Arbitrary 3D View
PRP (Projection Reference Point) Parallel: Direction of Projection (DOP) = from PRP to CW Perspective: COP “Eye” in OpenGL View volume Clipping and projection Perspective Semi-infinite pyramid with apex at PRP and edges passing through window corners Parallel Infinite parallelepiped with sides parallel to DOP

24 Specification of an Arbitrary 3D View
View volume (cont’d) Finite view volume Front clipping plane Parallel to VRP Specified by F (front distance) = distance(FCP - VRP) Back clipping plane Specified by B (back distance) = distance(BCP - VRP) In OpenGL, “near” and “far” represents “front” and “back”, respectively, in the camera coordinate

25 Finite View Volumes Parallel Perspective

26 Specification of an Arbitrary 3D View
Mapping from view volume to 2D display View volume --> NPC (Normalized Projection Coordinates), i.e., standard cube 3D viewport specified in NPC z=1 face of NPC cube mapped to display If wire-frame, z coordinate discarded If surface, hidden-surface removal

27 OpenGL 3D Viewing 1 3D Viewing in OpenGL: Position camera;
Specify projection.

28 OpenGL 3D Viewing 2 View volume y x z Camera always in origin, in direction of negative z-axis. Convenient for 2D, but not for 3D.

29 OpenGL 3D Viewing 3 Solution for view transform: Transform your model such that you look at it in a convenient way. Approach 1: Do it yourself. Apply rotations, translations, scaling, etc., before rendering the model. Surprisingly difficult and error-prone. Approach 2: Use gluLookAt();

30 OpenGL 3D Viewing 4 MatrixMode(GL_MODELVIEW); gluLookAt(x0,y0,z0, xref,yref,zref, Vx,Vy,Vz); x0,y0,z0: P0, viewpoint, location of camera; xref,yref,zref: Pref, centerpoint; Vx,Vy,Vz: V, view-up vector. Default: P0 = (0, 0, 0); Pref = (0, 0, 1); V=(0, 1, 0).

31 OpenGL 3D Viewing 5 Orthogonal projection: y x z
MatrixMode(GL_PROJECTION); glOrtho(xwmin, xwmax, ywmin, ywmax, dnear, dfar); xwmin, xwmax, ywmin,ywmax: specification window dnear: distance to near clipping plane dfar : distance to far clipping plane dnear dfar y ywmax x Select dnear and dfar right: dnear < dfar, model fits between clipping planes. z xwmax ywmin xwmin

32 OpenGL 3D Viewing 6 Perspective projection: y x z
MatrixMode(GL_PROJECTION); glFrustrum(xwmin, xwmax, ywmin, ywmax, dnear, dfar); xwmin, xwmax, ywmin,ywmax: specification window dnear: distance to near clipping plane dfar : distance to far clipping plane dfar dnear y x ywmax Select dnear and dfar right: 0 < dnear < dfar, model fits between clipping planes. z ywmin xwmax xwmin Standard projection: xwmin = -xwmax, ywmin = -ywmax

33 OpenGL 3D Viewing 7 Finally, specify the viewport (just like in 2D):
glViewport(xvmin, yvmin, vpWidth, vpHeight); xvmin, yvmin: coordinates lower left corner (in pixel coordinates); vpWidth, vpHeight: width and height (in pixel coordinates); vpHeight vpWidth (xvmin, yvmin)

34 OpenGL 2D Viewing 8 In short: To prevent distortion, make sure that:
glMatrixMode(GL_PROJECTION); glFrustrum(xwmin, xwmax, ywmin, ywmax, dnear, dfar); glViewport(xvmin, yvmin, vpWidth, vpHeight); glMatrixMode(GL_MODELVIEW); gluLookAt(x0,y0,z0, xref,yref,zref, Vx,Vy,Vz); To prevent distortion, make sure that: (ywmax – ywmin)/(xwmax – xwmin) = vpWidth/vpHeight Make sure that you can deal with resize/reshape of the (OS) window.

35 3D NDC to 2D Image (Near) Plane
Resulting image on the near plane Chapter 14


Download ppt "Computer Graphics CC416 Week 14 3D Graphics."

Similar presentations


Ads by Google