Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.

Similar presentations


Presentation on theme: "Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College."— Presentation transcript:

1 Computer Graphics: Programming, Problem Solving, and Visual Communication
Steve Cunningham California State University Stanislaus and Grinnell College PowerPoint Instructor’s Resource

2 Principles of Modeling
Modeling has many parts; this chapter covers several different aspects of modeling, from the simple to the more complex

3 Simple Geometric Modeling
The graphics primitives that are used in polygon-based modeling, and some examples of their uses

4 Modeling Space The geometry pipeline starts out in model space
This is the space you use to define each object in your scene You can use any coordinates that are convenient for you You can also build templates for things you want to use often

5 Fundamental Objects OpenGL, like most fundamental graphics systems, is based on polygons Polygons require points and edges, so you also have points and line segments The simplest polygons are triangles and quadrilaterals, so these are special cases

6 Fundamental Objects (2)
So the basic objects we work with are: Points Line segments Triangles Quadrilaterals (quads) Polygons Each is defined in terms of its vertices in order as you go around the object

7 Fundamental Objects (3)
In your more complete modeling, you will probably also work with polyhedra, objects that have polygons as faces Examples of these: Point, line, triangle, polygon (quad), polyhedron

8 Fundamental Objects (4)
To define one of these fundamental objects, you need to specify the vertices and the grouping This will typically look like begin(object_type) vertex(coordinates) vertex(coordinates) … vertex(coordinates) end

9 Fundamental Objects (5)
This defines the object by defining its boundary Boundary edges go from each vertex to the next The object is closed up by an edge from the last vertex to the first The boundary edges are used in the rendering process we will see later

10 Fundamental Objects (6)
When you define a polygon or quad, it may not necessarily be drawn as one Most polygon-based graphics systems really only draw triangles, so your object may be turned into triangles and then drawn You need to know if this will happen

11 Fundamental Objects (7)
A major question in drawing polygons is that most graphics systems will only draw convex polygons Any non-convex polygon will likely be drawn incorrectly (you can check this!) This suggests that any polygon can be drawn with a triangle fan (described below) from any vertex

12 Fundamental Objects (8)
Convexity example: One convex quadrilaterial and two non-convex ones (note vertex sequences)

13 Geometry Compression There is an overhead for each vertex you send to the graphics system Geometry compression is a way to send fewer vertices and still create the same object Graphics systems often have tools that allow geometry compression

14 Geometry Compression (2)
The geometry compression tools are fairly simple, but useful Line strips Line loops Triangle strips Triangle fans Quad strips

15 Geometry Compression (3)
Examples: line strip line loop

16 Geometry Compression (4)
Examples: triangle strip triangle fan

17 Geometry Compression (5)
Examples: quad strip with sequence of points (note this is different from the sequence if you just used quads!)

18 Geometry Compression (6)
Geometry compression in use: a sphere (left) with a triangle fan (middle) and quad strip (right)

19 Aliasing and Antialiasing
Most graphics systems let you choose if you want lines and edges to be antialiased -- drawn without jaggies Tradeoff is time vs image quality

20 Normals When we look at lighting, we will see that we need normals at each vertex A normal is a vector perpendicular to the plane of a polygon Normals can be calculated from the edges at a vertex, or they can be known from an object’s geometry

21 Surfaces Surfaces are common graphics objects and are relatively easy to compute You need to generate a set of points that lie on the surface and that are arranged so that they form a kind of grid You can then use the grid to create a set of triangles or quads to draw

22 Surfaces (2) A common example is the function surface
A grid in the domain is used to create a grid on the surface

23 Clipping Clipping defines a plane in the model space and specified that anything on one side (your choice) is not to be seen. The clipping plane is usually specified simply by giving the coefficients in the plane equation Clipping is very useful in letting the viewer see inside an object or objects

24 Homogeneous Coordinates
The familiar 3D space we use in graphics is sometimes viewed as being embedded in 4D space A point (x,y,z) is seen as equivalent to the homogeneous point (x,y,z,1) This lets the graphics system perform a number of operations more easily

25 Homogeneous Coordinates (2)
Embedding 3D space in 4D is hard to see, so consider the example of 2D space embedded in 3D

26 Homogeneous Coordinates (3)
The conversions between normal 3D and homogeneous 4D are

27 Transformations and Modeling
Using transformations to make complex models and scenes from simple geometric parts

28 Transformations Are… Transformations are functions that act on points in Euclidean space, mapping them into other points We are interested in the transformations that move points in ways interesting to computer graphics

29 Transformations Are… (2)
There are some specific kinds of transformations you have seen in the graphics pipeline Modeling transformations Viewing transformations Projection transformations We will look at them in this order

30 Modeling Transformations
There are three transformations we will use in modeling These let us take the objects we define in their own modeling space and place them in a common world space Scaling Rotation Translation

31 Modeling Transformations (2)
Scaling Each coordinate of a vertex is multiplied by a specific value The values for different coordinates may be different Scaling by (sx,sy,sz) with scale(sx,sy,sz) does:

32 Modeling Transformations (3)
Rotation Rotation is a little more complex algebraically, but its operation is easily seen in the 2D example You specify a rotation by specifying the angle of rotation and the line (through the origin) with direction vector <a,b,c> that vertices are to be rotated around Rotate(theta,a,b,c)

33 Modeling Transformations (4)
Translation Each coordinate of a vertex is offset by a specific value The values for each coordinate may differ Translating by (tx,ty,tz) with translate(tx,ty,tz) does:

34 Transformations Example
To create a scene showing a rugby ball flying after it is kicked, we must do two things First, create the rugby ball by scaling a sphere Second, create images of the ball in flight by showing it rotated and translated several times

35 Transformations Example (2)
First, the ball is created And then it is kicked

36 Composite Transformations
In the rugby example, each of the balls shown flying was created by starting with a sphere and applying all three transformations: translate(rotate(scale(ball))) This is a composite transformation with several transformations applied to the geometry. This is very common.

37 Composite Transformations (2)
Notice the order: translate(rotate(scale(ball))) This is standard notation: Transformations are written to the left of the object they act on The transformations at the right are done before transformations farther to the left

38 Composite Transformations (3)
We write all transformations this way Tn*Tn-1*…*T2*T1 This means that T1 is applied first and Tn applied last You can phrase this as “last-specified, first-applied”

39 Composite Transformations (4)
An important fact about transformations: Order Counts! Transformations are not commutative T1*T2 ≠ T2 * T1 So you must get your transformations in the right order to get the right results

40 Composite Transformations (5)
There is a common order for graphics transformations scale first, rotate second, translate last This goes along with a good general rule for modeling your simple objects model objects at the origin so it is easier to transform them correctly

41 Composite Transformations (6)
This order of application goes along with an ordering of operations The order is that the operations defined nearest the geometry are applied first So this turns into the coding sequence translate rotate scale geometry

42 An Example We want to create a 3D arrow from the basic shapes of a cone and a cylinder The cone and cylinder are in standard positions and of standard size

43 An Example (2) We must scale the cone and cylinder to appropriate sizes and then put them together to create a standard-size arrow as shown Then this standard arrow must be scaled to the size we need for our application

44 An Example (3) The general code for this looks like
pushTransformStack scale // entire arrow pushTransformStack translate // we will move cylinder onto cone rotate scale draw cylinder popTransformStack draw cone // this is already in the right place popTransformStack

45 The Viewing Transformation
Another important transformation in computer graphics is the viewing transformation This is the transformation that takes your models in world space and maps them into eye space You saw this in the geometry pipeline

46 The Viewing Transformation (2)
The viewing transformation V is done last, after all the geometry is defined in world space Thus when we write the entire sequence of transformations that will be done on the geometry, the viewing transformation is written to the left of all modeling transformations

47 The Modelview Transformation
The final product of all modeling transformations and the viewing transformation is then V*Tn*Tn-1*…*T2*T1 This product is called the modelview transformation

48 The Modelview Transformation (2)
The order of the transformations in the modelview transformation is suggestive A modeling transformation later in the sequence is closer to the geometry, so it is defined later in the program So as the program executes, all new transformations it meets are simply multiplied at the right of the sequence

49 The Modelview Transformation (3)
So there is only one access point to the sequence of transformations, and the state of the transformation environment at any point can be captured by saving the sequence at that point This suggests that there should be a way to store these states so we could return to any previous state

50 Transformation Stacks
A transformation stack is an answer to the question of storing the state of the modelview transformation We will see that there is a compact way to store any transformation, so we can create a stack of transformations The contents of the stack are states of the modelview transformation at known points in the program

51 Transformation Stacks (2)
The transformation at the top of the stack is the one used whenever any geometry is specified New modeling transformations are multiplied onto the one at the top of the stack To save the state, save a copy of the current top and add it to the stack To retrieve the last state, pop the stack

52 The Projection Transformation
The final transformation we have is the projection transformation P This maps 3D eye space to 2D screen space and is applied after all the modeling and viewing transformations So the total transformation environment for graphics is P*V*Tn*Tn-1*…*T2*T1

53 Modeling for Visual Communication
Some basic ideas to help you create effective communications with computer graphics

54 The Fundamental Idea The most important question in your decision of how to model something is How will my audience best understand this idea? Other considerations, such as finding an easy way to make your model, are secondary

55 The Meaning of Shapes Simple shapes can carry a lot of impact
Consider some ways to mark a point with a small shape: A circle A letter x A triangle A cross A pentagram A hexagram The circle has no cultural meaning we know of; the letter x has little meaning; but the other four have a large significance to some people

56 The Meaning of Shapes (2)
What are curves and surfaces? Are there actual physical surfaces for the electrostatic potential of Coulomb’s law, for example?

57 The Meaning of Shapes (3)
One of the problems students face in learning science and mathematics is learning that curves and surfaces are not real, but are only abstractions that represent values How can you communicate that when it is so seductive to create beautiful pictures of surfaces?

58 The Meaning of Shapes (4)
Another problem is using dimensions appropriately We can sometimes exchange one dimension for color, for example Color evokes responses but does not carry exact values; compare

59 The Meaning of Shapes (5)
When the added dimension is time, it is particularly interesting to think of how to communicate it With a 2D object, we can use time as the third dimension, but is it understood?

60 The Meaning of Shapes (6)
If the dimension of the problem goes beyond three, it can be difficult With a three dimensional model varying over time, you can use animation With more than three intrinsic dimensions it is more difficult 2D (or more) function of a 2D variable 1D (or more) function of a 3D variable there are some vocabularies for these

61 The Meaning of Shapes (7)
For a function of a 2D variable, you can show discrete objects on a grid on a 2D space: For example: vector length (with color) and orientation Or you could use glyphs at discrete points

62 The Meaning of Shapes (8)
For a 1D function of a 3D variable, you can show samples of the function’s values at points in 3D space

63 Other Content You can also add legends and labels to your image to give your audience the context to understand the image

64 Scene Graphs and Modeling Graphs
Tools to help manage complex scenes and hierarchical models

65 Modeling Can Be Complex
As you create scenes, you may find that you have a number of objects to work with Some of these objects may be defined only in world terms, but some may be defined in terms of other objects in the scene We need ways to describe complex and hierarchical scenes

66 A Solution Comes From the Scene Graph
Scene graph technology is a key part of several graphics APIs java3D VRML 2 openSG It is not part of OpenGL, but it is simple to use the concepts for your modeling

67 What is a Scene Graph? A graph (usually a tree) whose nodes describe grouping, transformations, geometry, and appearance

68 Slightly Simpler Form There are a few parts of the full scene graph that we don’t need The virtual universe The locale (we just call it a scene) The view platform But the rest of the tree is straightforward to create for your work We call this a modeling graph to recognize that it’s not a full scene graph

69 Hierarchical Modeling
The modeling graph is perhaps most useful when we work with models that have hierarchies of parts Controlling the motion of individual parts needs to take the parts’ parents’ motion into account This is difficult to do in absolute coordinates

70 Helicopter Example Probably the best example uses a helicopter flying above some surface The helicopter has a body and two rotors; the rotors are attached to the body but have their own motion

71 A Simple Modeling Graph
A very simple start at a modeling graph for the scene is: But this is not complete; it does not include include any transformations, for example

72 A More Complete Graph A more complete modeling graph for the scene, including both transformations and appearance data, is:

73 Other Ways to See this Graph
One of the values of thinking of modeling through a graph is that we can restructure the graph to get new views For example, if we invert the eyepoint we get a new and equivalent graph:

74 Changing the View With this new graph, it is easy to see that if we change the viewpoint placement transforms, we can get a new scene, as:

75 Using the Modeling Graph for Coding
It is easy to see some rewrite rules that let us traverse the modeling graph and write code for the scene as we go The transformation stack is a key part of this process, so be sure you know how it works before using these rules

76 Modeling Graph Rewrite Rules
As you traverse the modeling graph, Every time you go down a subtree at a grouping node, push the stack Every time you meet a transformation node, code the transformation Every time you meet a shape node, code the appearance and then code the geometry Every time you start back up a subtree, pop the stack

77 There Are a Few More Details
There are also details about projection, viewing, lighting, and the like, but they are straightforward It is also easy to see how to change a part of a scene by allowing changes to a node over time or by a user action Modeling graphs let you focus on design and make your coding much easier


Download ppt "Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College."

Similar presentations


Ads by Google