Title: Chap7. MANIPULATING 3D SPACE
1Chap7. MANIPULATING 3D SPACE
- (COORDINATE TRANSFORMATIONS)
- ????? ??????
- ? ??
2Contents
- Understanding Transformations
- Eye-Coordinate
- Viewing Transformation
- Modeling Transformation
- Projection Transformation
- Matrix Munching
- Identity Matrix
- Perspective Projection
- Advanced Matrix Manipulation
3UnderStanding 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
4Eye-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? ??? ?? ???. ? ??? ???? ????
????. ?, ??? ????? ??? ???? ??? ???.
6Viewing 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)
Fig.7-4
9The 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 ??.
10Projection 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
11Projection 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
12Viewport Transformation
2D projection of your scene that will be mapped
to a window somewhere on your screen.
13Matrix 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
14The transformation pipeline
The Modelview Matrix, Projection Matrix, Viewport
Matrix
15The Modelview Matrix
- Translation
- glTranslatef( GLfloat x, GLfloat y, GLfloat
z) - ?) glTranslatef(0.0f, 10.0f, 0.0f)
- auxWireCube(10.0f)
16The Modelview Matrix
- Rotation
- glRotatef(GLFloa angle, GLfloat x, GLfloat y,
GLfloat z) - ?) glRotatef(90.0f, 1.0f, 1.0f, 1.0f)
- auxWireCube(10.0f)
17The 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.
21The 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)
22The Matrix Stacks
23A Nuclear Example
- Using Orthographic Projection
- ATOM program
- ??? ?? ???? ?? ??, ??? ??? ?? 3??
- ??? ????.
- ???? ???? ??? 1?? ?? ???? ??.
Fig. 7-17
24A 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()
25A 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()
26A 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()
27Using 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
28Perspective Projection
Void gluPerspective(Gldouble fovy, Gldouble
aspect, Gldouble zNear, Gldouble zFar)
field-of-view ?? ??/?? ?????? ??? ??
???
29Perspective Projection
Void gluPerspective(Gldouble fovy, Gldouble
aspect, Gldouble zNear, Gldouble zFar)
field-of-view ?? ??/?? ?????? ??? ??
???
30Perspective 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()
31A 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
32Advanced 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)? ?? ??
33Summary
- Tank/Robot Simulation
- gluLookAt Specify your viewing transformation,
P222??.