CSC 308 Graphics Programming - PowerPoint PPT Presentation

1 / 56
About This Presentation
Title:

CSC 308 Graphics Programming

Description:

good news is that we can still use our drawing, shape, line and point classes. ... Alter the Point, Line, Shape, and Transformation classes to be 3d instead of 2d. ... – PowerPoint PPT presentation

Number of Views:59
Avg rating:3.0/5.0
Slides: 57
Provided by: webPr
Category:

less

Transcript and Presenter's Notes

Title: CSC 308 Graphics Programming


1
CSC 308 Graphics Programming
  • 3D Graphics
  • Information modified from Fergusons Computer
    Graphics via Java, and
  • Fundamentals of Computer Graphics. by Shirley

Dr. Paige H. Meeker Computer Science Presbyterian
College, Clinton, SC
2
Leaving the world of 2D
  • What have we learned?
  • Data structures to store various types of
    graphical objects (points, lines, shapes,
    drawings)
  • How to draw these on the screen for the viewer to
    see
  • How to make our objects move, rotate, and
    grow/shrink even reflect and shear.
  • Touched on making curves
  • Accept user input via keyboard or mouse
  • Animate our shapes.

3
Thus,
  • We have mastered most of the techniques required
    for 2d graphics.
  • Could now write applications as diverse as
    mapping systems and video games.
  • We live in the world of 3d not 2d what can we
    take from what we have already learned about 2d
    and apply it to our next frontier?
  • There is something almost magical about staring
    through a computer screen into a cyberspace and
    seeing worlds and objects that dont really
    exist. Lets get started!

4
Introduction
  • Modelling 3d with data structures
  • Expanding 2d points,lines, transforms etc.
  • Drawing 3d on a 2d screen
  • projections

5
3D coordinate system
  • In 2d we had height and breadth - but all shapes
    were flat
  • It makes sense to add a third coordinate to
    represent depth
  • By convention we use 3 mutually perpendicular
    axes, ( any 3 non co-planar axes would do).
  • Any point in 3d space can thus be represented by
    just those three numbers x,y z

6
2D -gt 3D
  • representation of a cube using our new coordinate
    system.
  • Each line of the cube (a-l) can still be
    described by its endpoints just as in 2d, but
    each point now has 3 coordinates.
  • good news is that we can still use our drawing,
    shape, line and point classes.
  • bad news is that they are all going to require
    some (hopefully small) alterations to work in 3d.

7
3D coordinate system
8
3D Points
  • Still using homogenous coordinates
  • Now need 4
  • Why?

9
3D Transformations
  • Since we now have an additional coordinate to
    cope with, our transformation matrices must also
    expand to cope.
  • Each transformation matrix with require an extra
    row and an extra column to become 4x4 matrices.
  • The change in Scaling and Translating is very
    straightforward. Rotation is a little more
    tricky (as usual!)

10
Scaling
11
Translation
12
Rotation (about axes)
  • In 2 dimensions, rotation were defined to take
    place about some stationary point - the centre of
    rotation.
  • In 3d, all rotation take place about one of the
    axes.

13
Rotation (about axes)
-90 about x axis
14
Rotation
  • x-axis
  • y-axis
  • z-axis

15
Local Rotation
  • translate the object to be rotated to the origin,
    perform the rotation and translate it back to
    where it started from

16
Modify the Point Class
  • Using Point2d as a guide, how would you now
    modify it to make a class Point3d.java?

17
How about Line, Drawing, and Shape?
  • How would these change from 2d to 3d?

18
Viewing
  • The really ironic thing about 3d graphics is that
    currently, we only have a 2d screen to display
    them on. So, after all the work involved in
    calculating the location of the points, lines,
    shapes, etc, we then have to figure out how to
    draw them on a 2d screen so that they still
    retain their 3d appearance!

19
2D Cartesian Coordinate System
20
3D Cartesian Coordinate System
21
Handed Coordinate Systems
  • Which way is up?

Right Handed
Left Handed
NOTE Rotating the system does not change it's
directionality in relation to itself. Various
industries will take advantage of this to orient
a the system in a convenient way.
22
Right Handed Rotation Example
23
Polar (2d) and Spherical(3d)Coordinate Systems
24
Projection
  • In general, projections transform points in a
    coordinate system of dimension n into points in a
    coordinate system of dimension less than n. In
    fact, computer graphics has long been used for
    studying n-dimensional objects by projecting them
    into 2D for viewing.

25
Projection
  • The projection of a 3D object is defined by
    straight projection rays (called projectors)
    emanating from a center of projection, passing
    through each point of the object, and
    intersecting a projection plane to form the
    projection.

26
Projection
  • Representation of a 3d object on a 2d screen
  • Several different projections exist
  • Well take a look at some common projections

27
Terms and definitions
28
Terms and Definitions
  • To work properly, the user has to position the
    center of projection (aka eye) in order to
    achieve good view quality
  • Here, there is only 1 eye humans have two. By
    producing 2 simultaneous projections based on two
    slightly different centers of projection (about 8
    cm apart), and feeding them separately to the
    left and right eyes, an imitation of 3d can be
    obtained (think VR goggles).

29
so?
  • We need to calculate the screen coordinates
    (xsys) of each projected point from the 3d
    coordinates
  • (theyre not the same!)
  • Usually!
  • Fortunately we can consider this calculation as
    a transformation.
  • Can use matrices to represent the various ways of
    doing it.

30
Projections
  • Two basic classes of projections
  • Perspective distance from center of projection
    to the projection plane is finite. Causes the
    size of the perspective projection of an object
    to vary inversely with the distance of that
    object from the center of projection.
  • Parallel distance from center of projection to
    the projection plane is infinite. (Better for
    exact measurements less realistic.)

31
Orthographic and PerspectiveViewing Projections
32
Parallel Projection
33
Perspective Projection
d
z
C
(xs,ys)
ps
By similar triangles
p
(x,y,z)

screen
x
34
Perspective Projection
35
Perspective Projection
So. Divide by
want
36
Now
  • In addition to the perspective transformation, we
    may also need to apply a viewpoint transformation
    before displaying data on the screen. This give
    the camera (eye point) the ability to move, pan,
    tilt and zoom.

37
Default viewpoint
38
Alternative viewpoint
39
Viewpoint translation and rotation
  • Moving the viewpoint by viewpoint transformation
    allows us to describe the position of the camera
    in terms a translation of its position and a
    rotation of its orientation.
  • A (camera or viewpoint) is described as having
    six degrees of freedom i.e. we can translate it
    in the x, y and z directions and we can spin it
    about the x,y, and z axes.

40
Viewpoint translation
41
Viewpoint rotation
42
How do we do it?
  • Already have all the mathematical tools required
    - matrices from the previous section.
  • Dont actually move the camera,
  • Transform the world (or the model of it) in
    precisely the opposite sense to the way we would
    have moved the camera.
  • These operations are in fact equivalent - you end
    up with the same view.
  • Easier to program that way.
  • Think of it in terms of an idle cameraman who has
    the world moved instead of shifting the camera

43
(No Transcript)
44
Moving the camera or moving the world
  • Viewpoint transformation is itself a combination
    of 2 separate transformations,
  • one for the rotation,
  • one for the translation.
  • These two transformations must be concatenated to
    produce the complete transformation. It is
    important to note that the rotation represents a
    local rotation of the entire world about the
    position of the camera and must be applied first.

45
Implementing 3d
  • Consider how implement data model
  • Consider overall system design
  • Consider changes to 2d classes
  • Consider how to implement projection/viewpoint
    transformation
  • Consider changes to 2d classes

46
Implementing 3d
  • Changes to the 2d classes
  • Matrix class no change at all.
  • Point3d
  • Add an extra (z) coordinate
  • change constructor, toString and setters and
    getters to match.

47
Implementing 3d
  • Line3d
  • A constructor needs altering to allow the
    specification of the z coordinate.
  • May need to alter the drawing method as well

48
Implementing3d
  • Tranformation3d
  • Increase size of matrices to 4x4
  • Add all of the matrices for rotation round the
    axes (rotatex, rotatey, rotatez)
  • Add matrices for various projections

49
To display, what we need to do is
  • Take the 3d data model that is stored in our
    shapes, lines and points - and apply a series of
    transformations to it before somehow plotting it
    on the screen.

50
Those transformations are
  • a local rotation of the model about the
    viewpoints x axis
  • a local rotation of the model about the
    viewpoints y axis
  • a local rotation of the model about the
    viewpoints z axis
  • a translation of the model in the x direction by
    an amount equal to the (negative) displacement of
    the viewpoint from the origin in the x direction
  • a translation of the model in the y direction by
    an amount equal to the (negative) displacement of
    the viewpoint from the origin in the y direction
  • a translation of the model in the z direction by
    an amount equal to the (negative) displacement of
    the viewpoint from the origin in the z direction
  • one of the projection transformations

51
  • Concatenate them (multiply them in the order
    given)
  • Dont transform the model!
  • Transform a copy of each point as you come to use
    it
  • I.e. in the draw() methods

52
Concatenate the transformations
  • The rotation and translation transforms can be
    concatenated into one viewpoint transformation in
    the Gapp class.

53
Sharing the transformations
  • Once the concatenation has been done, Gapp calls
    the setDrawingTransformation method of the
    drawing objects and thus sets the transformation
    to be used by the entire data structure.

54
Using the drawing transformation
  • It is still the draw methods of the line class
    that does the actual work of line drawing. (and
    later in the Bezier3d and Spline3d we will be
    adding)
  • The projection transformation is dealt with
    entirely within the Line3d class (and later in
    the Bezier3d and Spline3d we will be adding)
  • Make copies of the endpoints of the line, apply
    the drawing transformation to those copies
    (LEAVING THE ORIGINALS UNCHANGED) and use the x
    and y coordinates of those points as the
    endpoints of the lines we draw on screen.

55
Summary
  • Extra (z) coordinate
  • Rewrite transformations as 4x4 matrices
  • Projection reducing 3d model to 2d display
  • Viewpoint transformation
  • Six degrees of freedom of camera
  • Implementation of 3d graphics

56
Homework FIRST LARGE PROJECT!!
  • Alter the Point, Line, Shape, and Transformation
    classes to be 3d instead of 2d.
  • Add a perspective and parallel projection method
    to the Transformation3d class.
  • Enjoy Fall Break.
  • Next Wednesday Well explain in more detail how
    to implement the viewing transform and display
    our graphics and define our user interface.
  • DUE Monday, October 30 A working 3D Modeler
    that will allow the user to create 3d shapes,
    apply transformation to those shapes, and view
    them in a parallel or perspective trasformation.
Write a Comment
User Comments (0)
About PowerShow.com