transformation pipeline - computer science and...

21
Transformation Pipeline Local (Object) Modeling W ld S Local (Object) Space Modeling transformation World Space Viewing transformation Eye Space Clip Space Projection transformation Perspective divide NDC space Viewport mapping Screen space l d d Normalized Device Coordinates

Upload: others

Post on 15-Mar-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

Transformation Pipeline

Local (Object) Modeling W ld SLocal (Object)Space

Modelingtransformation

World Space

ViewingtransformationEye SpaceClip Space Projection

transformation

Perspectivedivide NDC space Viewport

mapping Screen spacel d dNormalized Device Coordinates

Page 2: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

Coordinate system

A coordinate system is used to unambiguously represent a pointunambiguously represent a point

It contains a reference point (the origin) and three linearly independent vectorsand three linearly independent vectors (the basis)

v3

v1

v2

O

Page 3: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

Screen Coordinate System

Glut

(0 0)OpenGL(0,0)

Page 4: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

Screen Coordinate System

- 2D Regular Cartesian Grid- Origin (0,0) at lower leftOrigin (0,0) at lower left

corner (OpenGL convention)- Horizontal axis – x

Vertical axis yVertical axis – y - Pixels are defined at the grid

intersections (0,0)

y

- This coordinate system is defined relative to the display window origin(OpenGL: the lower left corner

x

(Ope G t e o e e t co eof the window) (2,2)

Page 5: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

Local Coordinate System

Screen coordinate system is not very useful for displaying 3D objectsp y g j

You also do not necessarily know where the object is going to be placed in the end in the 3D world

Solution: define the positions of the vertices relative to its own center – Local coordinate system

yzyz

x x

Page 6: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

Simple OpenGL code

void display() { glClearColor(0,0,1,1);

OpenGL 1.1 convention, the goal here is to show you the idea

float vertices[] = {-0.5, -0.5, 0.0, 1.0, // first triangle-0.5, 0.5, 0.0, 1.0, 0 5 0 5 0 0 1 0g ( , , , );

glClear(GL_COLOR_BUFFER_BIT); glColor4f(1,1,0,1); //glColor* have been deprecated in OpenGL 3

glBegin(GL_TRIANGLES); //glBegin/End have been deprecated in OpenGL 3lC l 4f(1 1 0 1)

0.5, 0.5, 0.0, 1.0, 0.5, 0.5, 0.0, 1.0, // second triangle 0.5, -0.5, 0.0, 1.0, -0.5, -0.5, 0.0, 1.0};

glColor4f(1,1,0,1); glVertex4f(vertices[0], vertices[1], vertices[2], vertices[3]); glVertex4f(vertices[4], vertices[5], vertices[6], vertices[7]); glVertex4f(vertices[8], vertices[9], vertices[10], vertices[11]); glColor4f(1,0,0,1);glColor4f(1,0,0,1); glVertex4f(vertices[12], vertices[13], vertices[14], vertices[15]); glVertex4f(vertices[16], vertices[17], vertices[18], vertices[19]); glVertex4f(vertices[20], vertices[21], vertices[22], vertices[23]); glEnd();

glutSwapBuffers(); }

Page 7: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

World Coordinate System

Local coordinates along do not allow you to specify where the object will be placed position, size, orientation

Transformations need to be performed to position the object in the world coordinate systemobject in the world coordinate system

This is done through an arbitrary number of affine transformations (translation, rotation, scaling) applied to each vertex

=or =or

Page 8: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

Modeling Transformation

The transformation from local to world coordinates The matrix used is called modelingg

transformation matrix A modeling transformation is a sequence of

translations, rotations, scalings (in arbitrary order) matrices multiplied togethermatrices multiplied together

More detail to come in the next lecture

Page 9: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

Transformation Pipeline

Local (Object) Modeling W ld SLocal (Object)Space

Modelingtransformation

World Space

ViewingtransformationEye SpaceClip Space Projection

transformation

Perspectivedivide NDC space Viewport

mapping Screen spacel d dNormalized Device Coordinates

Page 10: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

Simple OpenGL code

void display() {

glClearColor(0,0,1,1);

OpenGL 1.1 convention, the goal here is to show you the idea

float vertices[] = {-0.5, -0.5, 0.0, 1.0, // first triangle-0.5, 0.5, 0.0, 1.0, 0 5 0 5 0 0 1 0glClear(GL_COLOR_BUFFER_BIT);

glColor4f(1,1,0,1); //glColor* have been deprecated in OpenGL 3

glMatrixMode(GL_MODELVIEW); glLoadIdentity();

0.5, 0.5, 0.0, 1.0, 0.5, 0.5, 0.0, 1.0, // second triangle 0.5, -0.5, 0.0, 1.0, -0.5, -0.5, 0.0, 1.0};

More detail about what happens behind the scene glRotatef(45, 0,0,1);

glBegin(GL_TRIANGLES); //glBegin/End have been deprecated in OpenGL 3glColor4f(1,1,0,1); glVertex4f(vertices[0], vertices[1], vertices[2], vertices[3]); glVe te 4f( e ti e [4] e ti e [5] e ti e [6] e ti e [7])

will be explained

glVertex4f(vertices[4], vertices[5], vertices[6], vertices[7]); glVertex4f(vertices[8], vertices[9], vertices[10], vertices[11]); glColor4f(1,0,0,1); glVertex4f(vertices[12], vertices[13], vertices[14], vertices[15]); glVertex4f(vertices[16], vertices[17], vertices[18], vertices[19]); glVertex4f(vertices[20], vertices[21], vertices[22], vertices[23]); lE d()glEnd();

glutSwapBuffers();

}

Page 11: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

Viewing transformation

Local (Object) Modeling W ld SLocal (Object)Space

Modelingtransformation

World Space

ViewingtransformationEye SpaceClip Space Projection

transformation

Perspectivedivide NDC space Viewport

mapping Screen spacel d dNormalized Device Coordinates

Page 12: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

Viewing Transformation

Convert from the world coordinate system to the

( ) dicamera (eye) coordinate system

The camera position is th i ithe origin

Derive the basis from the direction and orientation f th

uvof the camera This makes the later

transformations easier ld

v ny Eye coordinate

frame coiworld x

z

Page 13: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

Viewing Transformation Head tilt: Rotate your head by Just rotate the object about the eye space z axis - Mw2e =

v uv

n

(ex ey ez)

y

(ex,ey,ez) x

z

Page 14: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

ModelView Transformation

Modeling and Viewing transformations concatenated together

ML2E (or, GL_MODELVIEW matrix) =

void display()

= M

void display() {

glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity();

fixed function pipeline OpenGL= ML2E glLoadIdentity();

gluLookAt(0,0,1,0,0,0,0,1,0);display_all(); // your display routine

}

pipeline OpenGL

Page 15: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

Viewing transformation

Local (Object) Modeling W ld SLocal (Object)Space

Modelingtransformation

World Space

ViewingtransformationEye SpaceClip Space Projection

transformation

Perspectivedivide NDC space Viewport

mapping Screen spacel d dNormalized Device Coordinates

Page 16: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

Projection Transformation

Projection – map the object from 3D space to 2D screen

y yz

x

z

x

z

Perspective: gluPerspective() Parallel: glOrtho()

Page 17: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

Projection Transformation

Maps (projects) everything in the visible Maps (projects) everything in the visible volume into a canonical view volume

(1, 1, -1)(xmax, ymax, -far)

(-1, -1, 1)(xmin, ymin, -near)

Canonical View VolumeglOrtho(xmin, xmax, ymin, ymax, near, far)

Page 18: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

Projection Transformation

Maps (projects) everything in the visible Maps (projects) everything in the visible volume into a canonical view volume

(1, 1, -1)y

(-1, -1, 1)x

z

Z = 1 z = 1( 1 1)Canonical View Volume

Z = 1 z = -1 (-1, -1)

gluPerspective(fovy, aspect, near, far)

Page 19: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

Projection Transformation

Projection Matrix

glFrustum(xmin, xmax, ymin, ymax, N, F) N = near plane, F = far plane

Page 20: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

Viewing transformation

Local (Object) Modeling W ld SLocal (Object)Space

Modelingtransformation

World Space

ViewingtransformationEye SpaceClip Space Projection

transformation

Perspectivedivide NDC space Viewport

mapping Screen spacel d dNormalized Device Coordinates

Page 21: Transformation Pipeline - Computer Science and Engineeringweb.cse.ohio-state.edu/~wang.3602/courses/cse5542-2013-spring/10... · Transformation Pipeline Local (Object)Local (Object)

Viewport The rectangular region in the screen for

displaying the graphical objects defined in the ld i dworld window

Defined in the screen coordinate system

V_T

glViewport(int left, int bottom, int (right-left),int (top-bottom));

V L V R

V_B

( p ));

call this function before drawing(calling glBegin() andV_L V_R (calling glBegin() and

glEnd() )