1 / 40

# 3-D Transformations - PowerPoint PPT Presentation

3-D Transformations. Kurt Akeley CS248 Lecture 8 18 October 2007 http://graphics.stanford.edu/courses/cs248-07/. Overview. Tuesday 2-D transformation Composition of 2-D transformations Line equations, 2-D normals, and inverses Today Apply 2-D concepts to 3-D

Related searches for 3-D Transformations

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about '3-D Transformations' - lou

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### 3-D Transformations

Kurt Akeley

CS248 Lecture 8

18 October 2007

http://graphics.stanford.edu/courses/cs248-07/

Tuesday

• 2-D transformation

• Composition of 2-D transformations

• Line equations, 2-D normals, and inverses

Today

• Apply 2-D concepts to 3-D

• Look at OpenGL in some detail

Specify translation

(Almost) always have these values

Homogeneous 3-D transformation

Translation:

y

x

z

Right-hand rule for rotations by positive θ

Plane equations are transformed by the inverse of the matrix used to transform vertexes

Convert to plane equation, transform, and convert back:

Application

struct { float x,y,z,w;float nx,ny,nz; float r,g,b,a;} vertex;

Vertex assembly

Vertex operations

Primitive assembly

Primitive operations

Rasterization

Fragment operations

Framebuffer

Display

no

vo

Object coordinates

Transform vo by MTransform no by M-1

Model transformation

World coordinates(lighting calculations)

nw

vw

Transform vw by V

Vertex operations

View transformation

ve

Eye coordinates

Transform ve by P

Projection transformation

vc

Clip coordinates

Move world-coordinate and eye-coordinate operations (e.g., vertex lighting) to object coordinates

Collapse the M, V, and P matrixes to a single MMVP matrix

• Efficient implementation (less arithmetic)

• Simplified semantics

Costs:

• Must transform lights to object coordinates

• And how would the light positions be defined?

Change orientation and position, but not shape

Preserve geometric lengths and (relative) angles

Rigid-body transformations are:

• Translation and Rotation

• Not Scale and Shear (with occasional exceptions)

A homogeneous matrix is a rigid-body matrix if its upper-left 3x3 matrix is orthogonal

A matrix is orthogonal if and only if

• All columns are orthogonal and unit-length, and

• All rows are orthogonal and unit-length

no

vo

Object coordinates

Transform vo by MTransform no by M-1

Model transformation(non-rigid)

World coordinates(lighting calculations)

nw

vw

Transform vw by V

View transformation(rigid)

Vertex operations

ve

Eye coordinates

Transform ve by P

Projection transformation(non-rigid)

vc

Clip coordinates

no

vo

Object coordinates

Transform vo by MTransform no by M-1

Model transformation(non-rigid)

World coordinates(lighting calculations)

nw

vw

Vertex operations

View and projection transformation(non-rigid)

Transform vw by MVE

vc

Clip coordinates

no

vo

Object coordinates

“Model-view” transformation(non-rigid)

Transform vo by MTransform no by M-1

Eye coordinates(lighting calculations)

ne

ve

Vertex operations

Transform ve by P

Projection transformation(non-rigid)

vc

Clip coordinates

Simplicity

• Eliminates the need to explicitly specify viewer location

Efficiency

• In eye coordinates

• View location is (0 0 0)

• View direction is (0 0 -1)

• These zeros and ones lead to efficient lighting calculations

• But the optimizations are no longer important 

You are free to treat the intermediate coordinates as world coordinates:

• Compose view transform V into P rather than M

• There is little penalty for doing so:

• Diffuse, ambient, and emission lighting work well

• But specular lighting, which depends on viewer location, doesn’t

• In X-Window terminology: “Mechanism, not policy”

• OpenGL 2.0 allows you to redefine everything I’ll describe today

no

vo

Object coordinates

glMatrixMode(GL_MODELVIEW);

“Model-view” transformation(non-rigid)

Transform vo by MTransform no by M-1

Eye coordinates(lighting calculations)

ne

ve

glMatrixMode(GL_PROJECTION);

Transform ve by P

Projection transformation(non-rigid)

vc

Clip coordinates

Remember to do this!

glMultMatrixf(float m[16]);

glMultMatrixd(double m[16]);

glMultTransposeMatrixf(float m[16]);

glMultTransposeMatrixd(double m[16]);

glRotatef(float θ, float x, float y, float z);

glRotated(double θ, double x, double y, double z);

glTranslatef(float x, float y, float z);

glTranslated(double x, double y, double z);

glScalef(float x, float y, float z);

glScaled(double x, double y, double z);

glTranslated(px, py, pz);

glRotated(θ, a);

glTranslated(-px, -py, -pz);

DrawObject();

Transform the coordinate system

Transform the object

glMultMatrixf(mat1);

glMultMatrixf(mat2);

glMultMatrixf(mat3);

DrawObject();

Transform the coordinate system

Transform the object

glTranslated(2, 3, 0);

glRotated(45, 0, 0, 1);

glTranslated(-2, -3, 0);

DrawObject();

Transformations are applied opposite the specified order

Each transformation operates in the fixed coordinate system

(2.5 3.5 0)

Transformations are applied in the order specified

Each transformation operates relative to the current coordinate system

(2.5 3.5 0)

Separate stacks are maintained for M and P

Minimum (queryable) depths are 32 for M and 2 for P

glPushMatrix(); // pushes C onto the appropriate stack

// leaves C unchanged

glPopMatrix(); // restores C from top of stack and pops

glPushMatrix();

glRotatef(shoulder, 1, 0, 0);

SolidBox(1.5*unit, 1.5*unit, 5*unit, RED);

glTranslatef(0, 0, 5*unit);

glPushMatrix();

glRotatef(elbow, 1, 0, 0);

SolidBox(1.25*unit, 1.25*unit, 4*unit, WHITE);

glTranslatef(0, 0, 4*unit);

glPushMatrix();

glRotatef(wrist, 1, 0, 0);

SolidBox(unit, unit, 1.5*unit, GREEN);

glTranslatef(0, 0, 1.5*unit);

glPushMatrix();

glTranslatef(0, 0.25*unit, 0);

glRotatef(finger, 1, 0, 0);

SolidBox(0.75*unit, 0.5*unit, 1.5*unit, YELLOW);

glPopMatrix();

glPushMatrix();

glTranslatef(0, -0.25*unit, 0);

glRotatef(thumb, 1, 0, 0);

SolidBox(0.75*unit, 0.5*unit, 1.5*unit, YELLOW);

glPopMatrix();

glPopMatrix();

glPopMatrix();

glPopMatrix();

(x y z0) specifies a 3-D direction

• Division by zero pushes the point to infinity

• Normals are a special kind of direction

• Transformed by the inverse of the vertex matrix

• Other directions are correctly transformed by the vertex matrix itself

• E.g., surface tangents

OpenGL provides no mechanism to pre-multiply C

• Why?

Our 2-D understanding translated easily to 3-D

• Lines  planes

• Rotation becomes more involved

• Normals are transformed by the upper-left 3x3 of M

There is a duality to transformation

• Transform the coordinate system

• Transformations are applied in the specified order

• Each transformation is relative to the current coordinate system

• Transform the object

• Transformations are applied opposite the specified order

• Each transformation operates in the fixed coordinate system

OpenGL matrixes are post-multiplied

• Matches vertex semantics (interesting)

• Enables hierarchical modeling (important)