Download presentation
Presentation is loading. Please wait.
1
University of British Columbia © MIchiel van de Panne Geometric Transformations and quick OpenGL intro
2
University of British Columbia Project 0 Get used to OpenGL: compile and run templatecompile and run template change draw routine to dodecahedronchange draw routine to dodecahedron add color change on mouse clickadd color change on mouse click
3
University of British Columbia OpenGL State State machine: set state variables, including colorset state variables, including color Program structure: graphics initializationgraphics initialization draw routinedraw routine –specify geometric type –provide vertices
4
University of British Columbia Rendering Triangles Example: glBegin( GL_TRIANGLES ); glColor3f( 1.0, 0.0, 0.0 ); glVertex3f( 0.0, 1.0, 0.0 ); glColor3f( 0.0, 0.0, 1.0 ); glVertex3f( 0.0, 0.0, 0.0 ); glVertex3f(1.0, 0.0, 0.0 ); glEnd(); Every vertex gets the color, etc. that corresponds to the last specified value.
5
University of British Columbia Points, lines, polygons
6
University of British Columbia Math Review Working with Frames F2F2F2F2 F3F3F3F3 F1F1F1F1 F1F1F1F1P(3,-1) F2F2F2F2P(-1.5,2) F3F3F3F3P(1,2) y=4? no! y=2 j has horiz and vert components
7
University of British Columbia Transformations Rotation B A
8
University of British Columbia 2D Transformations © Marc Levoy
9
University of British Columbia 2D transformations © Marc Levoy
10
University of British Columbia Challenge Matrix multiplication for everything except translationfor everything except translation how to do everything with multiplication?how to do everything with multiplication? –then just do composition, no special cases Homogeneous coordinates to the rescue 2D cartesian (x,y) --> 3D homogeneous (x,y,w)2D cartesian (x,y) --> 3D homogeneous (x,y,w) homogeneouscartesian / w
11
University of British Columbia Homogeneous coordinates © Marc Levoy point in 2D cartesian + weight w = point in 2D cartesian + weight w = point P in 3D homog. coords point P in 3D homog. coords multiples of (x,y,w) multiples of (x,y,w) represent same point in 2D cartesianrepresent same point in 2D cartesian a line L in 3D homoga line L in 3D homog homogenize a point in 3D: homogenize a point in 3D: divide by w to get (x/w, y/w, 1)divide by w to get (x/w, y/w, 1) projects point onto w=1 planeprojects point onto w=1 plane
12
University of British Columbia Homogeneous coordinates © Marc Levoy w=0 denotes point at infinity w=0 denotes point at infinity think of as direction think of as direction cannot be homogenized cannot be homogenized lies on x-y plane lies on x-y plane (0,0,0) is not allowed (0,0,0) is not allowed
13
University of British Columbia Transformations Rotation glRotatef(angle,x,y,z);glRotated(angle,x,y,z);
14
University of British Columbia Transformations Scaling glScalef(a,b,c);glScaled(a,b,c); scale(a,b,c)
15
University of British Columbia Transformations Translation glTranslatef(a,b,c);glTranslated(a,b,c); translate(a,b,c)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.