# CS代考计算机代写 Computer Graphics

Computer Graphics

Jochen Lang

jlang@uottawa.ca

Faculté de génie | Faculty of Engineering

Jochen Lang, EECS jlang@uOttawa.ca

This Lecture

• Drawing and Animation

– Drawing and graphics pipeline – Modelling a Tetrahedron

– Projections from 3D to 2D

– Rasterization

– Animations

Jochen Lang, EECS jlang@uOttawa.ca

Drawing a Simple 3D Shape

• Tetrahedron: 4 triangles, 4 edges or 4 vertices

Jochen Lang, EECS jlang@uOttawa.ca

Modeling

• We can describe the tetrahedron by the positions of the vertices

• We need to use three dimensions

• 4 Vertices:

[-1.0 -1.0 -1.0] [1.0 -1.0 -1.0] [0.0 1.0 0.0] [0.0 -1.0 1.0]

• This means we have a coordinate system

• Redaxisisx,greenisyandblueisz

Jochen Lang, EECS jlang@uOttawa.ca

Image is 2D

• We can map to 2D by simply dropping the z-axis

• 4 Vertices:

[-1.0 -1.0 -1.0] [1.0 -1.0 -1.0] [0.0 1.0 0.0] [0.0 -1.0 1.0]

• Orthographic Projection

• But looks not too nice, why?

Jochen Lang, EECS jlang@uOttawa.ca

Historical Perspective

Source: Wikimedia

Jochen Lang, EECS jlang@eecs.uOttawa.ca

Perspective

Source: Wikimedia

Jochen Lang, EECS jlang@eecs.uOttawa.ca

Perspective Projection is Important

• Distance from viewer determines image size

• Examples:

– Railroad standard gauge is 1,435 mm

– Airport tunnel

Source: Wikimedia

Jochen Lang, EECS jlang@uOttawa.ca

1D Perspective Projection

• Cameras and eyes can be approximated by a camera pinhole model.

• In2D:

Similar triangles

focal length

height

Source: Wikimedia

depth pinhole

projected height

Jochen Lang, EECS jlang@uOttawa.ca

Perspective Viewing

• Size change because of depth

image plane

optical axis

Jochen Lang, EECS jlang@uOttawa.ca

Effect of Focal Length

– Zoom lenses have a large focal length

– Wide angle lenses have a short focal length

Source: Wikimedia

Jochen Lang, EECS jlang@uOttawa.ca

Apply to Tetrahedron

• Perspective view

• Additional information is needed

– Camera placement

– Placement

– Field of view or focal length – FoV

• How to apply the perspective transform?

Jochen Lang, EECS jlang@uOttawa.ca

Relative Vertex Positions

• First step:

– In general: Make the camera focal point the origin of our coordinate system

– Here, we effectively update the z-value

Jochen Lang, EECS jlang@uOttawa.ca

Field of View

• Alternate specification of focal length given image size

– Opening angle of camera

– horizontal, vertical and diagonal are used

Source: Wikimedia

Jochen Lang, EECS jlang@uOttawa.ca

Conversion to Focal Length

image plane

• Assume square image

pinhole

• Let’s assume image plane is from -1…1 in both directions:

Jochen Lang, EECS jlang@uOttawa.ca

2D Positions

• Take the relative coordinate

• Flip the z-axis and hence mirror the image

• Apply

. () . . .

• Result

• Same for other vertices

Jochen Lang, EECS jlang@uOttawa.ca

Another Example

– Cube under perspective projection

– Vanishing points (Parallel line on a tilted plane intersect not at infinity).

vanishing point 2

center of projection

vanishing point 1

image plane

Wikimedia

Source:

Jochen Lang, EECS jlang@uOttawa.ca

Viewing Geometry: Pinhole Camera

• Relate the image plane to the 3D world by projective projection.

• Extrinsic parameters:

– Position of pinhole and orientation of camera

– Rigid body transform

– Orientation specified by optical axis and image orientation

• Intrinsic parameters:

– Focal length possibly different in x and y

– Origin image coordinates – center of projection

Jochen Lang, EECS jlang@uOttawa.ca

Rasterization

• So far only dealt with the vertex positions but need to draw triangles

– Need to know which vertices form a face

– E.g. index the vertices 1,…,4 then faces are: 2 1 3, 3 1 4, 4 1 2 and 3 4 2

– This gives edges, e.g., 2 1 3 implies an edge .

• Display is only pixels in a raster – Need to rasterize the triangles – May add colors

Jochen Lang, EECS jlang@uOttawa.ca

Summary Graphics Pipeline

• Four major tasks: – Modelling

• Produces geometric primitives and description of surface, volume and light properties

– Geometric processing

• Normalization (change to camera, canonical coordinates or normalized device coordinates), clipping, culling, hidden-surface removal and possibly shading

– Rendering: Rasterization or Ray Tracing

• Rasterization: Deciding on mapping of pixels to primitives, e.g., triangle rasterization and line drawing, followed by fragment processing

– Display

• transfer of frame buffer to screen; may require, e.g., anti-aliasing and tone mapping

Jochen Lang, EECS jlang@uOttawa.ca

Animations

• Movement of tetrahedron

– 2D animation or 3D animation – Some techniques:

Source: Wikimedia

• Skeletonal animation or transformation based

– Every ball position is encoded in a transformation matrix and the transformation are interpolated or updated

• Physicis-based

– The position is updated based on some

Jochen Lang, EECS jlang@uOttawa.ca

physical laws, e.g., dynamics

• Key frames plus interpolation

– Every ball position is a keyframe image

– Interpolate the image between keyframes

Next lecture

• Drawing and Animation

– Drawing and graphics pipeline – Modelling a Tetrahedron

– Projections from 3D to 2D

– Rasterization

– Animations

Jochen Lang, EECS jlang@uOttawa.ca