CS488 More Geometric Transformations, Object Hierarchies, and some - - PowerPoint PPT Presentation

cs488
SMART_READER_LITE
LIVE PREVIEW

CS488 More Geometric Transformations, Object Hierarchies, and some - - PowerPoint PPT Presentation

CS488 More Geometric Transformations, Object Hierarchies, and some Fonts Luc R ENAMBOT 1 Previous Lectures Frame buffers Drawing a line (Midpoint Line Algorithm) Polygon Filling (Edge-table algorithm) Line Clipping


slide-1
SLIDE 1

CS488

More Geometric Transformations, Object Hierarchies, and some Fonts

Luc RENAMBOT

1

slide-2
SLIDE 2

Previous Lectures

  • Frame buffers
  • Drawing a line (Midpoint Line Algorithm)
  • Polygon Filling (Edge-table algorithm)
  • Line Clipping (Cohen-Sutherland algorithm)
  • Polygon Clipping
  • Circles
  • Geometric Transformations
  • More Transformations

2

slide-3
SLIDE 3

Transformations

  • Last time we talked about 2D and 3D

transformations and how those transformations affect objects in the scene

  • Today we will talk more about this, and

discuss how polygons are usually formed into hierarchies of more meaningful objects

  • We will also briefly discuss how fonts are

handled

3

slide-4
SLIDE 4

Changing Coordinate Systems

  • Last time we talked about transforms in

terms of an object (polygon, line, point) in the same coordinate system of the world, that is (0,0) for the object is the same as (0,0) for the world

  • An alternative way is for each object to have

its own local coordinate system separate from all of the other objects and the world coordinate system

4

slide-5
SLIDE 5

Local Coordinates

  • This allows each object to be created

separately and then added into the world, using transformations to place the object at the appropriate point

  • Useful when you build larger objects out of

reusable smaller objects

5

slide-6
SLIDE 6

Example

6

(1,2) (3,2) (3,4) (1,4)

Square of width 2, height 2

(-1,-1) (1,-1) (1,1) (-1,1)

slide-7
SLIDE 7

Example

7

Rotation 45 deg Scaling (2,2)

slide-8
SLIDE 8

Example

8

Translation (2,2)

(0,0) (2,2)

slide-9
SLIDE 9

Design

  • When we design the object we place the center of

rotation/scaling where we wish it to be. For a wheel the center of rotation would be where the axle is to be attached, for a hinged gate the center would be at the hinge.

  • Each object must then be translated/rotated/scaled

(from its local coordinate system) to place it at the proper location in the world (in the world coordinate system)

9

slide-10
SLIDE 10

Example

  • Say we are drawing an automobile and we want to draw

the 4 tires. We can either draw each of the 4 tires independently at the appropriate location, or draw the same tire centered at its origin 4 times, and each time move it to the appropriate location in the world

10

slide-11
SLIDE 11

OpenGL Example

  • Create a solar system with a single sun and a single

planet in orbit about it

  • Simplifications
  • circular orbit
  • plane of the solar system:

Y=0 plane

  • Sun at 0,0,0 and sphere of radius 1
  • Planet a radius of 0.2 and orbits at a radius of 2
  • The planet rotates about its axis once per day
  • The planet revolves around the sun once each year

11

slide-12
SLIDE 12

Code

  • glLoadIdentity(); //reset the matrix to the identity matrix
  • glPushMatrix();
  • drawSphere(1.0) // user defined function to draw the sun
  • glRotatef(yearPercentage, 0.0, 1.0, 0.0);
  • glTranslatef(2.0, 0.0, 0.0);
  • glRotatef(dayPercentage, 0.0, 1.0, 0.0);
  • drawSphere(0.2) // user defined function to draw the planet
  • glPopMatrix();

12

slide-13
SLIDE 13

Single Coordinate System

  • If you think about the single coordinate system then the operations on the

matrix are done in the REVERSE order from which they are called:

  • Initially the transformation matrix is the identity matrix
  • The sun is drawn as a circle with radius 1 at (0,0,0)
  • The planet is drawn as a circle with radius 0.2 at (0,0,0)
  • The planet is rotated about the

Y-axis by the percentage of day that has

  • passed. Since the planet is still at the origin this rotates the planet about

its center.

  • The planet is translated 2 units on the X-axis moving its center to (2, 0, 0)
  • The planet is rotated about the

Y-axis by the percentage of year that has

  • passed. Since the planet is no longer at the origin it rotates about the
  • rigin at a radius of 2

13

slide-14
SLIDE 14

Local Coordinate System

  • If you think about each object having its own coordinate system then the
  • perations on the matrix are done in the SAME order as they are called:
  • Initially the transformation matrix is the identity matrix
  • The sun is drawn as a circle with radius 1 at (0,0,0)
  • The planet is rotated about its

Y-axis by the percentage of year that has passed turning its coordinate system in the process

  • The planet is translated 2 units on its now rotated X-axis to its position in
  • rbit
  • The planet is rotated about its

Y-axis by the percentage of day that has

  • passed. Since the planet is still at (0,0,0) by its coordinate system, it

rotates about its center.

  • The planet is drawn as a circle with radius 0.2

14

slide-15
SLIDE 15

Example

  • Say you have three polygonal drawing functions available to you:
  • Draw a square centered at the origin with sides of length 1
  • Draw a circle centered at the origin with diameter of length 1
  • Draw a equilateral triangle with the center of its base at the
  • rigin with sides of length 1

15

How can I draw the following scene?

slide-16
SLIDE 16

Object Hierarchies

  • Single polygons are generally too small to be of

interest

  • Its hard to think of a single polygon as an

'object' unless you are writing Tetris(tm)

  • It is more convenient to think of objects which

are a collection of polygons forming a recognizable shape: a car, a house

  • This object can then be moved/rotated/scaled

as a single entity, at least at the conceptual level

16

slide-17
SLIDE 17

Object Hierarchies

  • Creating an object polygon by polygon is

very slow when you want to create a very large complex object

  • It does give you much more control over

the object than creating it from higher-level primitives (cube, cone, sphere)

17

slide-18
SLIDE 18

OpenInventor

  • Silicon Graphics (SGI) library
  • OpenInventor(tm) sits on top of OpenGL
  • Allows higher-level objects to be created
  • File format and runtime environment

18

slide-19
SLIDE 19

Example

19

  • Model: a ‘tree’
  • Constructed from a cube

and a cone

  • Constructed from triangular

polygons

slide-20
SLIDE 20

With primitives

20

#Inventor V2.1 ascii Separator { Separator { Translation { translation 0 -2 0 } Material { diffuseColor 0.8 0.2 0 } Cube { width 0.75 height 1.75 depth 0.75 } } Separator { Translation { translation 0 0.75 0 } Material { diffuseColor 0 0.8 0 } Cone { bottomRadius 1.4 height 4.3 }

slide-21
SLIDE 21

With polygons (1)

21

#Inventor V2.1 ascii Separator { Separator { Material { diffuseColor 0 0.8 0 } Separator { IndexedTriangleStripSet { vertexProperty VertexProperty { vertex [ 0 -1.4 -1.4, 0 2.9 0, 0.535757 -1.4 -1.29343, 0.989949 -1.4 -0.989949, 1.29343 -1.4 -0.535757, 1.4 -1.4 6.11959e-08, 1.29343 -1.4 0.535757, 0.989949 -1.4 0.989949, 0.535757 -1.4 1.29343, 2.11394e-07 -1.4 1.4,

  • 0.535756 -1.4 1.29343,
  • 0.989949 -1.4 0.98995,
  • 1.29343 -1.4 0.535757,
  • 1.4 -1.4 -1.66948e-08,
  • 1.29343 -1.4 -0.535757,
  • 0.989949 -1.4 -0.98995,
  • 0.535756 -1.4 -1.29343,

0 -1.4 0 ]

normal [ 0 0.309586 -0.950871, 0.363883 0.309586 -0.878491, 0.672368 0.309586 -0.672368, 0.878491 0.309586 -0.363883, 0.950871 0.309586 4.15639e-08, 0.878491 0.309586 0.363883, 0.672368 0.309586 0.672368, 0.363883 0.309586 0.878491, 1.43578e-07 0.309586 0.950871,

  • 0.363883 0.309586 0.878491,
  • 0.672367 0.309586 0.672368,
  • 0.878491 0.309586 0.363883,
  • 0.950871 0.309586 -1.1339e-08,
  • 0.878491 0.309586 -0.363883,
  • 0.672367 0.309586 -0.672368,
  • 0.363882 0.309586 -0.878491,

0 -1 0 ] materialBinding OVERALL normalBinding PER_VERTEX_INDEXED }

slide-22
SLIDE 22

With polygons (2)

22

coordIndex [ 16, 0, 17, 2, 3, -1, 3, 4, 17, 5, 6, -1, 6, 7, 17, 8, 9, -1, 9, 10, 17, 11, 12, -1, 12, 13, 17, 14, 15, -1, 16, 17, 15, -1, 1, 1, 0, 2, -1, 1, 1, 2, 3, -1, 1, 1, 3, 4,

  • 1, 1, 1, 4, 5, -1, 1, 1,

5, 6, -1, 1, 1, 6, 7, -1, 1, 1, 7, 8, -1, 1, 1, 8, 9, -1, 1, 1, 9, 10, -1, 1, 1, 10, 11, -1, 1, 1, 11, 12,

  • 1, 1, 1, 12, 13, -1, 1, 1,

13, 14, -1, 1, 1, 14, 15, -1, 1, 1, 15, 16, -1, 1, 1, 16, 0, -1 ] normalIndex [ 16, 16, 16, 16, 16, -1, 16, 16, 16, 16, 16, -1, 16, 16, 16, 16, 16, -1, 16, 16, 16, 16, 16, -1, 16, 16, 16, 16, 16, -1, 16, 16, 16, -1, 15, 0, 0, 1, -1, 0, 1, 1, 2, -1, 1, 2, 2, 3,

  • 1, 2, 3, 3, 4, -1, 3, 4,

4, 5, -1, 4, 5, 5, 6, -1, 5, 6, 6, 7, -1, 6, 7, 7, 8, -1, 7, 8, 8, 9, -1, 8, 9, 9, 10, -1, 9, 10, 10, 11,

  • 1, 10, 11, 11, 12, -1, 11, 12,

12, 13, -1, 12, 13, 13, 14, -1, 13, 14, 14, 15, -1, 14, 15, 15, 0, -1 ] } } } Material { diffuseColor 0.8 0.2 0 } IndexedTriangleStripSet { vertexProperty VertexProperty { vertex [ -0.375 -1.125 0.375,

  • 0.375 -2.875 0.375,

0.375 -1.125 0.375, 0.375 -2.875 0.375, 0.375 -1.125 -0.375, 0.375 -2.875 -0.375,

  • 0.375 -1.125 -0.375,
  • 0.375 -2.875 -0.375 ]

normal [ 0 0 1, 0 0 -1,

  • 1 0 0,

1 0 0, 0 1 0, 0 -1 0 ] texCoord [ ]

  • rderedRGBA [ ]

materialBinding OVERALL normalBinding PER_VERTEX_INDEXED } coordIndex [ 5, 3, 7, 1, -1, 2, 4, 0, 6, -1, 5, 4, 3, 2, -1, 1, 0, 7, 6, -1, 7, 6, 5, 4,

  • 1, 3, 2, 1, 0, -1 ]

normalIndex [ 5, 5, 5, 5, -1, 4, 4, 4, 4, -1, 3, 3, 3, 3, -1, 2, 2, 2, 2, -1, 1, 1, 1, 1,

  • 1, 0, 0, 0, 0, -1 ]

} }

slide-23
SLIDE 23

Polygons

  • Triangular polygons are often used instead of

4-sided ones because the 3 vertices in the triangle are guaranteed to form a plane, while the 4 vertices of a 4-sided polygon may not all fall in the same plane which may cause problems later on.

23

slide-24
SLIDE 24

Hierarchies

  • Hierarchies are typically stored as Directed

Acyclic Graphs (DAG)

  • They are trees where a node can have

multiple parents as long as no cycle is generated.

24

slide-25
SLIDE 25

Hierarchies

  • Hierarchies store all information necessary

to draw an object:

  • Polygon information
  • Material information
  • Transformation information
  • An object hierarchy gives a high degree of

encapsulation

25

slide-26
SLIDE 26

Hierarchies

  • Hierarchies are useful when you want to be able to manipulate an
  • bject on multiple levels
  • With an arm you may want to rotate the entire arm about the

shoulder, or just the lower arm about the elbow, or just the wrist or just a finger. If you rotate the entire arm then you want the rest of the arm parts to follow along as though they were joined like a real arm - if you rotate the arm then the elbow should come along for the ride

  • With a car the wheels should rotate but if the car body is

moving then the wheels should also be moving the same amount

26

slide-27
SLIDE 27

Example

27

slide-28
SLIDE 28

Inheritance

  • An object hierarchy allows inheritance
  • Attributes to be set once
  • then used by multiple sub-objects.
  • For example, at the top of the hierarchy the object could

be set to draw only as a wireframe, or with different lighting models, or different colors, or different texture

  • maps. This would then be inherited by the sub-objects and

not have to be explicitly set each of them

28

slide-29
SLIDE 29

Benefits

  • An object hierarchy gives a high degree of

encapsulation

  • Hierarchies increase modularity
  • Hierarchies decrease storage space
  • Hierarchies make it easy to propagate changes

29

slide-30
SLIDE 30

Exercise

  • How can I redraw the house and tree scene

to make better use of objects?

30

slide-31
SLIDE 31

Font

  • Text is handled in one of two ways
  • Using a bitmap for each character in the font
  • Using lines / polygons for each character in

the font

31

slide-32
SLIDE 32

Bitmap Font

  • Rectangular array of 0s and 1s

00000000 00011000 00100100 01000010 01111110 01000010 01000010 01000010

32 A

slide-33
SLIDE 33

Bitmap Font

  • Need a set of bitmaps for each

size and style of font

  • 2D only
  • Always aligned with the screen
  • Dealt with specially while

manipulating the frame buffer

  • Fast

33

slide-34
SLIDE 34

Polygonal Font

  • Re-scalable so that the

definition can generate a 'smooth' character of any size

  • Can be either 2D or 3D
  • Can be rotated
  • Treated like any other line/

polygon to be displayed

  • Slower

34

slide-35
SLIDE 35

OpenGL Fonts

  • OpenGL provides minimal font support
  • glutBitmapCharacter
  • glutStrokeCharacter
  • Fortunately there are free 3D fonts

available, such ‘freetype’ fonts and libraries

35

slide-36
SLIDE 36

Bitmap OpenGL

  • Bitmap
  • void glutBitmapCharacter(void *font, int character)
  • GLUT_BITMAP_8_BY_13
  • GLUT_BITMAP_9_BY_15
  • GLUT_BITMAP_TIMES_ROMAN_10
  • GLUT_BITMAP_TIMES_ROMAN_24
  • GLUT_BITMAP_HELVETICA_10
  • GLUT_BITMAP_HELVETICA_12
  • GLUT_BITMAP_HELVETICA_18
  • Ex: glutBitmapCharacter(GLUT_HELVETICA_18,'3');
  • Position in the frame buffer
  • void glRasterPos2f(float x, float y);

36

slide-37
SLIDE 37

3D Font OpenGL

  • Drawn with lines
  • Controlled by function glLineWidth
  • Stroke
  • void glutStrokeCharacter(void *font, int character)
  • GLUT_STROKE_ROMAN
  • GLUT_STROKE_MONO_ROMAN
  • Ex: glutStrokeCharacter(GLUT_HELVETICA_18,'3')
  • int glutStrokeWidth(void *font, int character);
  • Width of a character

37

slide-38
SLIDE 38

Coming Next Time

  • 3D Graphics
  • More Matrices...

38