790 likes | 812 Views
Computer Graphics: Programming, Problem Solving, and Visual Communication. Steve Cunningham California State University Stanislaus and Grinnell College PowerPoint Instructor’s Resource. Principles of Modeling.
E N D
Computer Graphics:Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College PowerPoint Instructor’s Resource
Principles of Modeling Modeling has many parts; this chapter covers several different aspects of modeling, from the simple to the more complex
Simple Geometric Modeling The graphics primitives that are used in polygon-based modeling, and some examples of their uses
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
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
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
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
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
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
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
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
Fundamental Objects (8) • Convexity example: One convex quadrilaterial and two non-convex ones (note vertex sequences)
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
Geometry Compression (2) • The geometry compression tools are fairly simple, but useful • Line strips • Line loops • Triangle strips • Triangle fans • Quad strips
Examples:line strip line loop Geometry Compression (3)
Examples:triangle strip triangle fan Geometry Compression (4)
Examples:quad strip with sequence of points (note this is different from the sequence if you just used quads!) Geometry Compression (5)
Geometry Compression (6) • Geometry compression in use: a sphere (left) with a triangle fan (middle) and quad strip (right)
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
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 calculatedfrom the edges at a vertex,or they can be known froman object’s geometry
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
Surfaces (2) • A common example is the function surface • A grid in the domain is used to create a grid on the surface
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
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
Homogeneous Coordinates (2) • Embedding 3D space in 4D is hard to see, so consider the example of 2D space embedded in 3D
Homogeneous Coordinates (3) • The conversions between normal 3D and homogeneous 4D are
Transformations and Modeling Using transformations to make complex models and scenes from simple geometric parts
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
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
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
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:
Modeling Transformations (3) • Rotation • Rotation is a little morecomplex algebraically,but its operation is easilyseen 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)
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) withtranslate(tx,ty,tz) does:
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
Transformations Example (2) • First, the ball is created • And then it is kicked
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.
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
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”
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
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
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
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
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
An Example (3) • The general code for this looks like pushTransformStackscale // entire arrowpushTransformStack translate // we will move cylinder onto cone rotate scale draw cylinderpopTransformStackdraw cone // this is already in the right place popTransformStack
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
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
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
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
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
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