CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.

16
CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann

Transcript of CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.

Page 1: CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.

CS 325Introduction to Computer Graphics

03 / 03 / 2010

Instructor: Michael Eckmann

Page 2: CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 325 - Spring 2010

Today’s Topics• Questions/comments?

• Review for exam

• 3d view volume clipping

Page 3: CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 325 - Spring 2010

Arbitrary 3d View examples• In the handout description of the viewing parameters for figure

6.34 it says all parameters are the same except view up vector

is 10 degrees away from y axis.

• Notice the house is tilted slightly to the right (compared to the

figure 6.22) so the up direction is tilted towards the left.

• The handout doesn't explicitly state this Vup vector, so let's try

to figure it out.

• To determine the coordinates of a vector that's 10 degrees away

from (0,1,0) we can ...

• Draw diagram on the board.

Page 4: CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 325 - Spring 2010

Arbitrary 3d View examples• So, the dot product of v1=(0,1,0) with v2=(x,1,0) is 1.

• Then use other equation for dot product: |v1||v2|cosA = 1

• |v1| = 1

• |v2| = sqrt(1+x*x)

• So, sqrt(1+x*x) cos A = 1

• A=10 degrees. so, cosA is about .985

• So, sqrt(1+x*x) = 1/.985, then square both sides to get

• 1+x*x = 1.0307, x*x = 0.0307, then sqrt of both to get • X = + or - 0.175

• A Vup vector of (-0.175, 1, 0) could have approximately that

effect.

Page 5: CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 325 - Spring 2010

Review for exam• Given v1 = (2,1,0) and v2 = (0,5,1)

• draw them in 3d coordinates• what is the magnitude of each?• what is their dot product?• what is the angle between them?• what is their cross product?

• Given v1 = (1, 2, 0) and v2 = (0, 0, 17) • what is the angle between them?

• Given these three points: (1, 2, 2), (1, 2, 0), (0, 2, 5) what plane

do they define?

Page 6: CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 325 - Spring 2010

Review for exam• Given these three points: (1, 2, 2), (1, 2, 0), (0, 2, 5) what plane

do they define?• recall that the cross product of [p1-p2] and [p3-p2] gives us

a normal vector• and recall that the general equation of a plane is

• Ax+By+Cz+D=0• The (A,B,C) is a normal vector, so we can use what we

calculated earlier as A,B,C• Then, to get D,

– we just need to take the dot product of the normal vector with a point on the plane (any of the 3 given points). This is Ax + By + Cz. So, that number + D equals 0.

Page 7: CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 325 - Spring 2010

Review for exam• Produce a matrix that transforms from a 2d window in world

coordinates to a 2d viewport.

• Let's say the window in the world is from (10, 10) to (30, 50)

and the viewport in screen coordinates is from (.1,.1) to (.9, .9).

Page 8: CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 325 - Spring 2010

Review for exam• Suppose you want to display a circle with center (4,7) and you

have the coordinates of the pixels for the 2nd octant. How

would you plot the pixels for the other 7 octants?

Page 9: CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 325 - Spring 2010

Review for exam• Suppose you want to display a circle with center (4,7) and you

have the (x, y) coordinates of the pixels for the 2nd octant.

What are the coordinates of the pixels for the other 7 octants?• we know that if the center is at the origin, then an (x,y) in

octant 2 will correspond to the following pixels in the other 7 octants:

– (y,x), (x,-y), (y,-x), (-x,y), (-y,x) (-x,-y), (-y,-x)• but for us, the center is at (4,7) so we need to translate the

(x,y) by (-4,-7) and then compute the 7 pixels and add (4,7) to each before plotting

• so for each pixel in the 2nd octant, (x,y), :– (x-4,y-7) leads to the 7 pixels (with center 0) of– (y-7, x-4), (y-7, 4-x), (x-4, 7-y),(4-x,y-7),– (4-x, 7-y), (7-y, x-4), (7-y, 4-x)

• then add (4,7) to each to get the actual answer:– (y-3, x+3), (y-3, 11-x), (x, 14-y),(8-x,y),– (8-x, 14-y), (11-y, x+3), (11-y, 11-x)

Page 10: CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 325 - Spring 2010

View volume

Page 11: CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 325 - Spring 2010

3d Clipping• The view volume on the last slide has 6 faces

• For a canonical view volume the faces are the on the

following planes:

• x = z, x = -z, y = z, y = -z, z = zmin

, z = -1

• the 2 vertical faces (the front and back clipping planes) are on z = z

min, z = -1

• the two side faces are on x = z, x = -z• the top and bottom faces are on y = z, y = -z

• the view volume lives totally in -z, so which plane is the top face on? y = z or y = -z ?

Page 12: CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 325 - Spring 2010

3d Clipping• Cohen Sutherland's extension into 3d from 2d.

• A six bit (as opposed to 4 in 2d) outcode is used here.• 1 = true, 0 = false

– Bit 1 = above view volume (y > -z)– Bit 2 = below view volume (y < z)– Bit 3 = right of view volume (x > -z)– Bit 4 = left of view volume (x < z)– Bit 5 = behind view volume (z < -1)– Bit 6 = in front of view volume (z > z

min)

This leads to 27 different outcode volumes

See drawing on board.

Page 13: CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 325 - Spring 2010

3d Clipping• Trivially accept if both endpoints have outcodes of

000000.

• Trivially reject if logical AND of the outcodes of the

endpoints is NOT 000000.

• Calculate intersection with borders of clipping planes if

can't trivially accept or reject.

Page 14: CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 325 - Spring 2010

3d Clipping• the parametric equation of a line is:

• x = x0 + t (x

1 – x

0)

• y = y0 + t (y

1 – y

0)

• z = z0 + t (z

1 – z

0), 0 <= t <= 1

• Calculating the intersections of lines with the unit slope planes

of the cvv is easy.

• For example, for the y = z plane, y0 + t (y

1 – y

0) = z

0 + t (z

1 –

z0) and we can solve for t. We'll then know the y and z

coordinates of the intersection (z = y), so just use t to find the x

coordinate.

Page 15: CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 325 - Spring 2010

3d Clipping• Then, once we have the x y and z coordinates of the

intersection we can determine if• the intersection is actually on a face of the view volume• or the intersection is not on a face of the view volume

– if the intersection is not on a face, then we exclude the portion of the line outside that plane (away from the view volume) and recalculate the region code of the intersection

– if the intersection is on a face, we keep that intersection as a final endpoint and exclude the portion of the line outside that plane, recalculate region code too.

• Another nice feature of this algorithm is that when given two

endpoints of the line segment and their region codes, even if we

can't trivially accept or reject them, we can tell which planes

they intersect (when corresponding bits are different.)

Therefore, we only have to clip that line against those planes.

Page 16: CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 325 - Spring 2010

3d Clipping• Calculating the intersections at unit slopes is easier than at

arbitrary slopes, hence the decision to normalize to a canonical

view volume.• x = x

0 + t (x

1 – x

0)

• y = y0 + t (y

1 – y

0)

• z = z0 + t (z

1 – z

0), 0 <= t <= 1

• Recall an arbitrary plane is Ax + By + Cz + D = 0 (the equation

of a plane.)

• It should be obvious that more calculations are involved in

finding the intersection of a line with an arbitrary plane than

with simple planes like y = z, z = -1, etc.