0% found this document useful (0 votes)
66 views6 pages

3D Viewing & Clipping: Announcements Where Do Geometries Come From?

This document discusses 3D viewing and clipping techniques in computer graphics. It begins by explaining that geometries can come from 3D modeling, digitization, simulation or combinations of these. It then describes the process of getting geometry displayed, which involves transforming it to the camera coordinate system, projecting it using perspective or orthographic projection, clipping it to the view volume, and rasterizing it. The document provides detailed explanations of pinhole camera models, perspective and orthographic projections, viewing transformations, and clipping lines and polygons to the normalized view volume. It also discusses techniques for camera control and virtual trackballs.

Uploaded by

Indrajeet Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views6 pages

3D Viewing & Clipping: Announcements Where Do Geometries Come From?

This document discusses 3D viewing and clipping techniques in computer graphics. It begins by explaining that geometries can come from 3D modeling, digitization, simulation or combinations of these. It then describes the process of getting geometry displayed, which involves transforming it to the camera coordinate system, projecting it using perspective or orthographic projection, clipping it to the view volume, and rasterizing it. The document provides detailed explanations of pinhole camera models, perspective and orthographic projections, viewing transformations, and clipping lines and polygons to the normalized view volume. It also discusses techniques for camera control and virtual trackballs.

Uploaded by

Indrajeet Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Announcements Movie from Assignment 1 Grades out soon

Where do geometries come from?

3D Viewing & Clipping


Where do geometries come from? Where do geometries come from? Pin-hole camera Pin-hole camera Perspective projection Perspective projection Viewing transformation Viewing transformation Clipping lines & polygons Clipping lines & polygons Build them with 3D modelers Digitize or scan them Results of simulation/physically based modeling Combinations: Edit a digitized model Simplify a scanned model Evolve a model Often, need multiple models at different complexity

Watt 5.2 and 6.1


COMPUTER GRAPHICS 15-462
12 Sept 2001 Computer Graphics 15-462 1

Computer Graphics 15-462

Getting Geometry on the Screen Given geometry in the world coordinate system, how do we get it to the display?
Transform to camera coordinate system Transform (warp) into canonical view volume Clip Project to display coordinates (Rasterize)

Viewing and Projection Our eyes collapse 3-D world to 2-D retinal image (brain then has to reconstruct 3D) In CG, this process occurs by projection Projection has two parts:
Viewing transformations: camera position and direction Perspective/orthographic transformation: reduces 3-D to 2-D

Pinhole Optics
Stand at point P, and look through the hole - anything within the cone is visible, and nothing else is Reduce the hole to a point - the cone becomes a ray Pin hole is the focal point, eye point or center of projection.

Use homogeneous transformations As you learned in Assignment 1, camera can be animated by changing these transformations the root of the hierarchy
Computer Graphics 15-462 5

Computer Graphics 15-462

Computer Graphics 15-462

Perspective Projection of a Point


Image F I World W

Problems with Pinholes Correct optics requires infinitely small pinhole


No light gets through Diffraction Solution: Lens with finite aperture
image plane focal point lens

Image Formation
Image F World

W
scene point

Projecting a shape
project each point onto the image plane lines are projected by projecting end points only
Image W

View plane or image plane - a plane behind the pinhole on which the image is formed
point I sees anything on the line (ray) through the pinhole F a point W projects along the ray through F to appear at I (intersection of WF with image plane)
Computer Graphics 15-462 7

f
v u

I
World

Lens Law:
Computer Graphics 15-462 8

1 1 1 + = u v f
Computer Graphics 15-462

Note: Since we don't want the Note: Since we don't want the image to be inverted, from now on image to be inverted, from now on we'll put F behind the image plane. we'll put F behind the image plane.
9

Orthographic Projection
when the focal point is at infinity the rays are parallel and orthogonal to the image plane good model for telephoto lens. No perspective effects. when xy-plane is the image plane (x,y,z) -> (x,y,0) front orthographic view
World Image

A Simple Perspective Camera Canonical case:


camera looks along the z-axis focal point is the origin image plane is parallel to the xy-plane at distance d
(We call d the focal length, mainly for historical reasons)
y Image Plane x z
[0,0,d]

Similar Triangles
Y [Y, Z]

[(d/Z)Y, d]

Z [0, 0] [0, d]

F=[0,0,0]

vup: a vector that is pointing straight up in the image usually want world up direction

Diagram shows y-coordinate, x-coordinate is similar Using similar triangles


point [x,y,z] projects to [(d/z)x, (d/z)y, d]

Computer Graphics 15-462

10

Computer Graphics 15-462

11

Computer Graphics 15-462

12

A Perspective Projection Matrix


Projection using homogeneous coordinates: transform [x, y, z] to [(d/z)x, (d/z)y, d]
d 0 0 0 0 0 x d 0 0 y d = [dx dy dz z] x y d z d 0 z z 1 0 1 Divide by 4th coordinate
(the w coordinate)

Wait, theres more! Perspective transformation can also


map rectangle in the image plane to the viewport specify near and far clipping planes instead of mapping z to d, transform z between znear and zfar on to a fixed range used for z-buffer hidden surface removal specify field-of-view (fov) angle

The View Volume


Pyramid in space defined by focal point and window in the image plane (assume window mapped to viewport) Defines visible region of space Pyramid edges are clipping planes Frustum = truncated pyramid with near and far clipping planes
Why near plane? Prevent points behind the camera being seen Why far plane? Allows z to be scaled to a limited fixed-point value (z-buffering)

0 d 0 0

2-D image point:


discard third coordinate apply viewport transformation to obtain physical pixel coordinates
Computer Graphics 15-462 13 Computer Graphics 15-462 14 Computer Graphics 15-462 15

But wait... What if we want the camera somewhere other than the canonical location? Alternative #1: derive a general projection matrix. (hard) Alternative #2: transform the world so that the camera is in canonical position and orientation (much simpler) These transformations are viewing transformations They can be specified in many ways - some more sensible than others (beware of Foley, Angel and Watt are ok)
Computer Graphics 15-462 16

Camera Control Values


All we need is a single translation and angle-axis rotation (orientation), but... Good animation requires good camera control--we need better control knobs Translation knob - move to the lookfrom point Orientation can be specified in several ways:
specify camera rotations specify a lookat point (solve for camera rotations)

A Popular View Specification Approach


Focal length, image size/shape and clipping planes are in the perspective transformation In addition:
lookfrom: lookat: where the focal point (camera) is the world point to be centered in the image

Also specify camera orientation about the lookat-lookfrom axis

Computer Graphics 15-462

17

Computer Graphics 15-462

18

Implementation
Implementing the lookat/lookfrom/vup viewing scheme (1) Translate by -lookfrom, bring focal point to origin (2) Rotate lookat-lookfrom to the z-axis with matrix R:
v = (lookat-lookfrom) (normalized) and z = [0,0,1] rotation axis: a = (vxz)/|vxz| rotation angle: cos = vz and sin = |vxz|

The Whole Picture

It's not so complicated


x z
lookfrom vup

y x z y x z Translate LOOKFROM to the origin Rotate the view vector (lookat -lookfrom) onto the z-axis.

START HERE
lookat

glRotate(, ax, ay, az) (3) Rotate about z-axis to get vup parallel to the y-axis

LOOKFROM: LOOKAT:

Where the camera is A point that should be centered in the image VUP: A vector that will be pointing straight up in the image FOV: Field-of-view angle. d: focal length WORLD COORDINATES
Computer Graphics 15-462 20

y x

Multiply by the projection matrix and everything will be in the canonical camera position

Rotate about z to bring vup to y-axis

Computer Graphics 15-462

19

Computer Graphics 15-462

21

Virtual Trackballs
Imagine world contained in crystal ball, rotates about center Spin the ball (and the world) with the mouse Given old and new mouse positions
project screen points onto the sphere surface rotation axis is normal to plane of points and sphere center angle is the angle between the radii

Clipping
There is something missing between projection and viewing... Before projecting, we need to eliminate the portion of scene that is outside the viewing frustum
y x
clipped line

Normalizing the Viewing Frustum


Solution: transform frustum to a cube before clipping
y x
clipped line 1 1 near far 0 1

y x

clipped line

z
image plane near far

There are other methods to map screen coordinates to rotations

z
image plane near far

Need to clip objects to the frustum (truncated pyramid) Now in a canonical position but it still seems kind of tricky...
Computer Graphics 15-462 22 Computer Graphics 15-462 23

Converts perspective frustum to orthographic frustum This is yet another homogeneous transform!

Computer Graphics 15-462

24

The Normalized Frustum OpenGL uses -1<=x<=1, -1<=y<=1, -1<=z<=1 But it doesnt really matter we can clip against any such cube.
Or, we can translate normalizing transformations by applying the appropriate trans.

But wait! Divide by zero?


But doesnt projection require dividing by the z coordinate? If -1<=z<=1, wont we get divide by 0? Ah, but its really the w coordinate we divide by, and its positive definite! The original perspective transformation puts a vertexs z value in w Since hither<=z<=yon for vertices that dont get clipped, w is positive definite (modulo sign convention for hither and yon) Hence, no worries on that front. All the z=0 vertices will get clipped before we divide out the homogeneous coordinate.

Clipping to a Cube Determine which parts of the scene lie within cube We will consider the 2D version: clip to rectangle This has its own uses (viewport clipping) Two approaches:
clip during scan conversion (rasterization) - check per pixel or end-point clip before scan conversion

Must clip in homogeneous coordinates:


w>0: -w<=x<=w, -w<=y<=w, -w<=z<=w w<0: -w>=x>=w, -w>=y>=w, -w>=z>=w

We will cover clip to rectangular viewport before scan conversion


Computer Graphics 15-462 25 Computer Graphics 15-462 26 Computer Graphics 15-462 27

Line Clipping Modify endpoints of lines to lie in rectangle How to define interior of rectangle? Convenient definition: intersection of 4 half-planes
Nice way to decompose the problem Generalizes easily to 3D (intersection of 6 half-planes)

Line Clipping Modify end points of lines to lie in rectangle Method:


Is end-point inside the clip region? - half-plane tests If outside, calculate intersection between the line and the clipping rectangle and make this the new end point

Cohen-Sutherland Algorithm
Uses outcodes to encode the half-plane tests results
1001 ymax 0001 0000 0010 1000 1010

bit 1: y>ymax bit 2: y<ymin bit 3: x>xmax bit 4: x<xmin

ymin

ymax

interior
ymin xmin xmax

28

y < ymax

y > ymin

x > xmin

x < xmax

Both endpoints inside: trivial accept One inside: find intersection and clip Both outside: either clip or reject (tricky case)

0101 xmin

0100 xmax

0110

Rules:
Trivial accept: outcode(end1) and outcode(end2) both zero Trivial reject: outcode(end1) & (bitwise and) outcode(end2) nonzero Else subdivide
Computer Graphics 15-462 30

Computer Graphics 15-462

Computer Graphics 15-462

29

Cohen-Sutherland Algorithm
Uses outcodes to encode the half-plane tests results
1001 ymax 0001 0000 0010 1000 1010

Cohen-Sutherland Algorithm: Subdivision If neither trivial accept nor reject:


Pick an outside endpoint (with nonzero outcode) Pick an edge that is crossed (nonzero bit of outcode) Find line's intersection with that edge Replace outside endpoint with intersection point Repeat until trivial accept or reject
1001 ymax 0001 0000 0010 1000 1010

Polygon Clipping Convert a polygon into one or more polygons that form the intersection of the original with the clip window

bit 1: y>ymax bit 2: y<ymin bit 3: x>xmax bit 4: x<xmin

ymin 0101 xmin 0100 xmax 0110

Rules:
Trivial accept: outcode(end1) and outcode(end2) both zero Trivial reject: outcode(end1) & (bitwise and) outcode(end2) nonzero Else subdivide
Computer Graphics 15-462 31 Computer Graphics 15-462 ymin 0101 xmin 0100 xmax 0110

bit 1: y>ymax bit 2: y<ymin bit 3: x>xmax bit 4: x<xmin

32

Computer Graphics 15-462

33

Sutherland-Hodgman Polygon Clipping Algorithm Subproblem:


clip a polygon (vertex list) against a single clip plane output the vertex list(s) for the resulting clipped polygon(s)

Sutherland-Hodgman Polygon Clipping Algorithm (Cont.) To clip vertex list against one half-plane:
if first vertex is inside - output it loop through list testing inside/outside transition - output depends on transition:
> in-to-in: > out-to-out: > in-to-out: > out-to-in: output vertex no output output intersection output intersection and vertex

Cleaning Up
Post-processing is required when clipping creates multiple polygons As external vertices are clipped away, one is left with edges running along the boundary of the clip region. Sometimes those edges dead-end, hitting a vertex on the boundary and doubling back Need to prune back those edges Sometimes the edges form infinitely-thin bridges between polygons Need to cut those polygons apart

Clip against all four planes


generalizes to 3D (6 planes) generalizes to any convex clip polygon/polyhedron

Computer Graphics 15-462

34

Computer Graphics 15-462

35

Computer Graphics 15-462

36

You might also like