CHAPTER 4 Geometric Transformations: The Pipeline Vivian by Richard S. Wright Jr.

25
CHAPTER 4 Geometric Transformations: The Pipeline Vivian by Richard S. Wright Jr.
  • date post

    19-Dec-2015
  • Category

    Documents

  • view

    219
  • download

    2

Transcript of CHAPTER 4 Geometric Transformations: The Pipeline Vivian by Richard S. Wright Jr.

CHAPTER 4

Geometric Transformations:The Pipeline

Vivian

by Richard S. Wright Jr.

Transformation Terminology• Viewing• Modeling• Modelview• Projection• Viewport

+x

+x

+y +y

+z

Eye Coordinates

-x

-y

-x

-y

Viewing Transformations

+x

+y

+z

-x

-y

(0,0,0)

• Translation• Rotation• Scaling

Modeling Transformations

+y

+x

+y

+x

+y

+x

+y

+x

+y

+x

+y

+x

rotation/translation and translation/rotation.

θ

θ

+x

+y

+z

+x

+y

+z

The Modelview Duality

Projection TransformationsOrthographic Perspective

The Matrix: Mathematical Currency

for 3D Graphics• What is matrix?

963

852

741

4

3

2

1

142

877.05.1

420

The Transformation Pipeline

11

vertex

ModelviewMatrix

ProjectionMatrix

PerspectiveDivision

ViewportTransform

Modelview

Modelview

Projection

lll

object eye

clip normalizeddevice

window

• other calculations here– material è color– shade model (flat)– polygon rendering mode– polygon culling– clipping

• glTranslatef(x, y, z);

• glRotatef(angle, x, y, z);

• glScalef(x, y, z);

• glLoadIdentity();

The Modelview Matrix

Transformation functions - Translate

• glTranslatef(x, y, z);

• Ex: glTranslatef(0.0f, 10.0f, 0.0f);

Transformation functions - Rotate

• glRotatef(angle, x, y, z);

• Ex: glRotatef(45.0f, 1.0f, 1.0f, 1.0f);

Transformation functions - Scale

• glScalef(x, y, z);

• Ex: glScalef(2.0f, 1.0f, 2.0f);

Transformation functions - The Identity Matrix

• glLoadIdentity();

Matrix Stack

glPushMatrix glPopMatrix

glGet(GL_MAX_MODELVIEW_STACK_DEPTH)

The Matrix Stacks

A Nuclear Example// First Electron Orbit// Save viewing transformation

glPushMatrix();

// Rotate by angle of revolutionglRotatef(fElect1, 0.0f, 1.0f, 0.0f);// Translate out from origin to orbit distanceglTranslatef(90.0f, 0.0f, 0.0f);

// Draw the electronglutSolidSphere(6.0f, 15, 15);

// Restore the viewing transformationglPopMatrix();

A Nuclear Example(cont.)// Second Electron OrbitglPushMatrix();glRotatef(45.0f, 0.0f, 0.0f, 1.0f);glRotatef(fElect1, 0.0f, 1.0f, 0.0f);glTranslatef(-70.0f, 0.0f, 0.0f);glutSolidSphere(6.0f, 15, 15);glPopMatrix();

// Third Electron OrbitglPushMatrix();glRotatef(360.0f, -45.0f, 0.0f, 0.0f, 1.0f);glRotatef(fElect1, 0.0f, 1.0f, 0.0f);glTranslatef(0.0f, 0.0f, 60.0f);glutSolidSphere(6.0f, 15, 15);glPopMatrix();

Using Projections• Orthographic Projections• Perspective Projections

Frustum

near far

Perspective viewing volume

w

h

Perspective Projections

// Reset coordinate system glMatrixMode(GL_PROJECTION); glLoadIdentity();

// Produce the perspective projection gluPerspective(60.0f, fAspect, 1.0,

400.0);

Advanced Matrix Manipulation

1000

TzZzYzXz

TyZyYyXy

TxZxYxXx

GLfloat matrix[16]; // Nice OpenGL friendly matrix

Translation/location

Loading a Matrix• glLoadMatrixf(GLfloat m);

• void glLoadTransposeMatrixf(Glfloat* m);

// Load an identity matrixGLfloat m[] = { 1.0f, 0.0f, 0.0f, 0.0f, // X Column0.0f, 1.0f, 0.0f, 0.0f, // Y Column0.0f, 0.0f, 1.0f, 0.0f, // Z Column0.0f, 0.0f, 0.0f, 1.0f }; // TranslationglMatrixMode(GL_MODELVIEW);glLoadMatrixf(m);