Chap7. MANIPULATING 3D SPACE - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

Chap7. MANIPULATING 3D SPACE

Description:

chap7. manipulating 3d space (coordinate transformations) – PowerPoint PPT presentation

Number of Views:80
Avg rating:3.0/5.0
Slides: 34
Provided by: hdk8
Category:

less

Transcript and Presenter's Notes

Title: Chap7. MANIPULATING 3D SPACE


1
Chap7. MANIPULATING 3D SPACE
  • (COORDINATE TRANSFORMATIONS)
  • ????? ??????
  • ? ??

2
Contents
  • Understanding Transformations
  • Eye-Coordinate
  • Viewing Transformation
  • Modeling Transformation
  • Projection Transformation
  • Matrix Munching
  • Identity Matrix
  • Perspective Projection
  • Advanced Matrix Manipulation

3
UnderStanding Transformations
- Transformation Projection(make possible
the projection of 3D coordinates onto a 2D
screen) and Rotation/Moving/Scaling.
Transformation Use Viewing
Specifies the location of the viewer or
camera Modeling Moves objects
around scene Modelview Describes
the duality of viewing and modeling
transformation Projection Clips
and sizes the viewing volume Viewport
Scales final output to the window
4
Eye-Coordinate
  • Eye coordinates are from the viewpoint of the
    observer, regardless of any transformations that
    may occur-think of them as absolute screen
    coordinates
  • Positive x right Positive y up
  • Positive z travels away from the origin toward
    the user
  • Negative z travel futher away from the
    viewpoint into the screen

  • y
  • lt Fig 7-1 gt
    -z
  • -x

  • x
  • ??? z
    -y

5
Modify the current coord. System before drawing
your objects. (Save the current state, do some
transformation and drawing and restore)
Fig. 7-2
Eye coord? ???? 45? ??? ?? ???. ? ??? ???? ????
????. ?, ??? ????? ??? ???? ??? ???.
6
Viewing Transformation
  • The point of observation (0,0,0)
  • The direction of observation Looking down to
    the negative Z-axis.
  • This point is moved relative to the eye coord
    system
  • Allows to place the point of observation
    (camera) anywhere you want.
  • The Viewing Transformation must be specified
    before any other Translation


7
Model Transformation
  • Modeling Transformation are used to manipulate
    your model and
  • the particular objects within it Translation,
    Rotation, Scaling


8
Model Transformation(2)
  • Noncommutative


Fig.7-4
9
The Modelview Duality
  • The viewing and the modeling transformation are
    the same in terms of their internal effects as
    well as the final appearance.
  • Modelview Tranformation
  • No difference between moving an object backward,
    and moving the reference system forward.
  • Fig. 7-5 ??.

10
Projection Transformation
  • Projection actually defines the viewing volume
    and establish clipping planes
  • Specifies how a finished scene is translated to
    the final image on the scene

11
Projection Transformation(2)
  • Orthographic Projection
    Perspective Projection
  • When you are modeling simple objects that are
    unaffected by the position and distance of the
    viewer.
  • CAD, or blueprint.
  • They would appear in real life.
  • Foreshortening.
  • Vanishing point.
  • Parallel lines will not always be drawn parallel

12
Viewport Transformation
2D projection of your scene that will be mapped
to a window somewhere on your screen.
13
Matrix Munching
  • Modelview Marix
  • - 44 matrix that represents transformed
    coordinate system you are using to place and
    orient your object
  • x x e
  • y M ye
  • z ze
  • w we
  • w scaling factor, set by default to 1.0

14
The transformation pipeline
The Modelview Matrix, Projection Matrix, Viewport
Matrix
15
The Modelview Matrix
  • Translation
  • glTranslatef( GLfloat x, GLfloat y, GLfloat
    z)
  • ?) glTranslatef(0.0f, 10.0f, 0.0f)
  • auxWireCube(10.0f)

16
The Modelview Matrix
  • Rotation
  • glRotatef(GLFloa angle, GLfloat x, GLfloat y,
    GLfloat z)
  • ?) glRotatef(90.0f, 1.0f, 1.0f, 1.0f)
  • auxWireCube(10.0f)

17
The Modelview Matrix
  • Scaling
  • glScalef(GLfloat x, GLfloat y, GLfloat z)
  • ?) glScalef(2.0f, 1.0f, 2.0f)
  • auxWireCube(10.0f)

18
Identity Matrix - In essence, resetting the
Modelview matrix back to the origin -
Cummulative Each time you call one, the proper
matrix is constructed and multiplied by the
current Modelview matrix. - ?)
glTranslatef(0.0f, 10.0f, 0.0f)
auxSolidSphere(1.0f)
glTranslatef(10.0f, 0.0f, 0.0f)
auxSolidSphere(1.0f)
19
Identity Matrix glMatrixMode(GL_MODELVIEW)
glLoadIdentiy() glTranslatef(0.0f, 10.0f,
0.0f) auxSolidSphere(1.0f)
glLoadIdentity() glTranslatef(10.0f, 0.0f,
0.0f) auxSolidSphere(1.0f)
20
  • Identity Matrix
  • Loading the Modelview matrix with Identity
    matrix Reset the Modelview matrix to a
    known state (I.e, centered at the origin of our
    eye coordinate.)
  • glMatrixMode (GL_MODELVIEW)
  • the current operating matrix is the Modelview
    matrix
  • glLoadIdentity()
  • loads the current matrix with the Identity
    matrix.

21
The Matrix Stacks
  • Often want to save the current transformation
    state and then restore it To facilitate this,
    OpenGL maintains a matrix stack.
  • Matrix stacks for the Modelview, Projection and
    Texture matrix.
  • The stack depth is implementation dependent
  • ?) Microsoft? OpenGL ??
  • 32 for the Modelview stack
  • 2 for the Projection stack
  • glGet(GL_MAX_MODELVIEW_STACK_DEPTH)
  • glGet(GL_MAX_PROJECTION_STACK_DEPTH)

22
The Matrix Stacks
23
A Nuclear Example
  • Using Orthographic Projection
  • ATOM program
  • ??? ?? ???? ?? ??, ??? ??? ?? 3??
  • ??? ????.
  • ???? ???? ??? 1?? ?? ???? ??.

Fig. 7-17
24
A Nuclear Example
void RenderScene(void)
Static float fElect1 0.0f glClear(GL_COLOR_BUFF
ER_BIT GL_DEPTH_BUFFER_BIT) glMarix
Mode(GL_MODELVIEW) glLoadIdentity()
glTranslate(0.0f, 0.0f, -100f) glRGB(255,0,0) au
xSolidSphere(10.0f) // ??? ??? glRGB(255,255,0)
// ??? ?? .
// ??? ?? // ??? ?? fElect1
10.0f if(fElect1 gt 360.0f) fElect1
0.0f glFlush()
25
A Nuclear Example
void RenderScene(void)
glMarixMode(GL_MODELVIEW) glLoadIdentity()
glTranslate(0.0f, 0.0f, -100f) glRGB(255,0,0) au
xSolidSphere(10.0f) // ??? ??? glRGB(255,255,0)
// ??? ?? glPushMatrix() //viewing ??
?? glRotatef(fElect1, 0.0f, 1.0f,
0.0f) glTranslatef(90.0f, 0.0f,
0.0f) glSolidSphere(6.0f) glPopMatrix()
// ??? ?? // ??? ?? fElect1
10.0f if(fElect1 gt 360.0f) fElect1
0.0f glFlush()
26
A Nuclear Example
// ??? ?? glPushMatrix() glRotatef(45, 0.0f,
0.0f, 1.0f) glRotatef(fElect1, 0.0f, 1.0f,
0.0f) glTranslatef(-70.0f, 0.0f,
0.0f) glSolidSphere(6.0f) glPopMatrix() // ???
?? fElect1 10.0f if(fElect1 gt
360.0f) fElect1 0.0f glFlush()
void RenderScene(void)
glMarixMode(GL_MODELVIEW) glLoadIdentity()
glTranslate(0.0f, 0.0f, -100f)
glPushMatrix() //??? ?? glRotatef(fElect1,
0.0f, 1.0f, 0.0f) glTranslatef(90.0f, 0.0f,
0.0f) glSolidSphere(6.0f) glPopMatrix()
27
Using Projections
Projection matrix specifies the size and shape of
our viewing volume. (Modelview matrix is used to
position our vantage point of viewing volume and
to place our objects therein) Orthographic
Projections ORTHO program
Fig. 7-18, 7-19, 7-20 Hollow tube-like box
28
Perspective Projection
Void gluPerspective(Gldouble fovy, Gldouble
aspect, Gldouble zNear, Gldouble zFar)
field-of-view ?? ??/?? ?????? ??? ??
???
29
Perspective Projection
Void gluPerspective(Gldouble fovy, Gldouble
aspect, Gldouble zNear, Gldouble zFar)
field-of-view ?? ??/?? ?????? ??? ??
???
30
Perspective Projection
Define the frustum
Fig. 7-23, 24, 25
Void ChangeSize(GLsizei w, Glsizei h) Glfloat
fAspect if(h 0) h 1 glviewport(0, 0, w,
h)
glMatrixMode(GL_PROJECTION) glLoadIdetity() gluP
erspective(60.0f, fAspect,1.0, 400.0) glMatrixMo
de(GL_MODELVIEW) glLoadIdentity()
31
A Far-Out Example
  • Sun/Earth/Moon System
  • Enabled some lighting and shading
  • When the Earth appears larger, its on the near
    side of the Sun on the far side, it appears
    smaller.

Sun/Earth/Moon system
32
Advanced Matrix Manipulation
Loading a Matrix(Column Major) glFloat m
1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
1.0f glMatrixMode(GL_MODELVIEW)
glLoadMatrix(m)
Performing Your Own tansformation glFloat m
1.0f, 0.0f, 0.0f, 10,0f 0.0f, 1.0f, 0.0f,
0.0f 0.0f, 0.0f, 1.0f, 0.0f 0.0f, 0.0f, 0.0f,
1.0f glMatrixMode(GL_MODELVIEW)
glMulMatrix(m)
glTranslate(10.0,0.0,0.0)? ?? ??
33
Summary
  • Tank/Robot Simulation
  • gluLookAt Specify your viewing transformation,
    P222??.
Write a Comment
User Comments (0)
About PowerShow.com