3D Computer Game Design - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

3D Computer Game Design

Description:

The camera and viewing transformations. OpenGL matrices and matrix stacks ... Construct complicated models. The Modelview Matrix. Define the coordinate system ... – PowerPoint PPT presentation

Number of Views:75
Avg rating:3.0/5.0
Slides: 28
Provided by: tainc
Category:

less

Transcript and Presenter's Notes

Title: 3D Computer Game Design


1
????????3D Computer Game Design
  • Chapter 4
  • Transformations and Matrices (Part I)
  • ????? ???

2
In this chapter, you will learn
  • Coordinate transformations
  • The camera and viewing transformations
  • OpenGL matrices and matrix stacks
  • Projections
  • Using your own matrices with OpenGL

3
Understanding Coordinate Transformations
  • Local coordinate system
  • Unique for every object
  • Centered on the object
  • Doesnt depend on any other objects

4
Understanding Coordinate Transformations
  • When rendering 3D scenes, vertices pass through
    four types of transformations
  • Modeling transformation
  • Move objects from local coordinates into world
    coordinates
  • Viewing transformation
  • Move objects form world coordinates into eye or
    camera coordinates

5
Understanding Coordinate Transformations
  • Projection transformation
  • Map objects from eye coordinates to clip
    coordinate
  • Viewport transformation
  • Map the clip coordinates into the 2D viewport, or
    window, on your screen

6
(No Transcript)
7
Understanding Coordinate Transformations
  • OpenGL includes and combines the modeling and
    viewing transformation
  • Modelview transformation
  • These transformations execute in a specific order

8
Eye Coordinates
  • Define the cameras position and orientation
  • In OpenGL
  • The default camera is always oriented to look
    down the negative z axis

9
(No Transcript)
10
Viewing Transformations
  • Used to position and aim the cameras
  • Specify before any other modeling transformations
  • Create the viewing transformation

void glLoadIdentity()
11
Viewing Transformations
  • After initializing the current matrix, you can
    create the viewing matrix in several ways
  • Using the gluLookAt()
  • Using the translation and rotation modeling
    commands
  • Create your own routines

12
Modeling Transformations
  • Allow you to position and orient a model
  • Translation
  • Moving an object along a specified vector
  • Rotation
  • Rotate about a vector
  • Scaling
  • Increase or decrease the size of an object

13
(No Transcript)
14
Projection Transformations
  • Define the viewing volume and clipping planes
  • OpenGL offers two types of projections
  • Perspective projection
  • Show 3D worlds exactly as you see things in real
    life
  • Orthographic projection
  • Show objects on the screen in their true size,
    regardless of their distance from the camera

15
Viewport Transformations
  • Map the clip coordinates onto your windows
    rendering surface
  • The final images should be enlarged or shrunk

16
OpenGL and Matrices
  • Transformations in OpenGL rely on the matrix for
    all math computations
  • Matrix stack
  • Construct complicated models

17
The Modelview Matrix
  • Define the coordinate system
  • To place and orient objects
  • 4 x 4 matrix
  • Modify matrix
  • To modify the modelview matrix
  • Use the argument GL_MODELVIEW

void glMatrixMode(Glenum mode)
18
The Modelview Matrix
  • Other arguments for glMatrixMode
  • GL_PROJECTION, GL_COLOR, or GL_TEXTURE
  • Reset the modelview matrix to the default
    position (0, 0, 0) and orientation
  • Call the glLoadIdentity() function

glMatrixMode(GL_MODELVIEW) glLoadIdentity() //
do other transformations
19
Translation
  • Move an object from one position to another
    position
  • The OpenGL function
  • For example

void glTranslatefd(TYPE x, TYPE y, TYPE z)
glMatrixMode(GL_MODELVIEW) glLoadIdentity() glTr
anslatef(5.0f, 5.0f, 5.0f) DrawCube()
20
(No Transcript)
21
Rotation
  • Rotation
  • Angle
  • Measure in degrees in the counterclockwise
    direction
  • For example
  • Rotate clockwise around the y axis 135 degrees

void glRotatefd(TYPE angle, TYPE x, TYPE y,
TYPE z)
glRotatef(-135.0f, 0.0f, 1.0f, 0.0f)
22
Scaling
  • Increase or decrease the size of an object or
    coordinates system

void glScalefd(GLfloat x, GLfloat y, GLfloat
z) For example glScalef(2.0f, 2.0f, 2.0f)
23
Matrix Stacks
  • There are four types of matrix stacks in OpenGL
  • The modelview matrix stack
  • The projection matrix stack
  • The color matrix stack
  • The texture matrix stack

24
Matrix Stacks
  • The modelview matrix stack allows you to save the
    current state of transformation matrix
  • The functions to push and pop the matrix stacks
  • glPushMatrix() and glPopMatrix()

25
(No Transcript)
26
The Robot Example
  • RobotExample
  • Show an animated walking robot around which the
    camera rotate

27
Reference
  • Dave Astle and Kevin Hawkins, Beginning OpenGL
    Game Programming, 1st Edition, Course Technology
    PTR, 2004.
  • http//glbook.gamedev.net
Write a Comment
User Comments (0)
About PowerShow.com