Brown CSCI 1480 - Display Lists 2D Transformations

Unformatted text preview:

1Display Lists2D TransformationsCS148: Intro to CGInstructor: Dan MorrisTA: Sean WalkerJune 30, 2005Outline for today{ Moving Data Around{ 2D Transformations{ SIGGRAPH video break{ Matrix Transformations{ Composite TransformationsSending data to the video card{ OpenGL needs to know where you want to put your vertices{ There are several ways to send your vertices to the video hardware{ The first part of today’s lecture will explore three different waysApproach 1: Immediate Mode{ In “immediate mode” (everything so far in CS148), commands are sent to the video card immediately (hence the name)// Somewhere in my drawing code:glBegin(GL_POINTS);glVertex2i(10,20);glVertex2i(40,50);glEnd();What’s wrong with this approach?Approach 2: Display lists[list.cpp linelist.cpp stroke.cpp]// Just once, in some initialization function:// Ask OpenGL for one new display listg_mySlickFerrariDL = glGenLists(1);// Record the display listglNewList(g_mySlickFerrariDL, GL_COMPILE);glBegin(GL_TRIANGLES);// …maybe millions of glVertex calls…// …maybe change colors, other GL commands…glEnd();glEndList();// Every frame I just need to do:glCallList(g_mySlickFerrariDL);Display lists: Pros and Cons{ Save the overhead of making 1,000,000 function calls per frame{ Can draw the same object multiple times with different OpenGL stateWhat’s one other advantage of using display lists?What’s one disadvantage of using display lists?2Immediate Mode with Arrays{ Usually I don’t know all my vertex locations when I code my program{ So let’s say I read my vertices from a file into a big array…glBegin(GL_TRIANGLES);for(int i=0; i<numVertices*6; i+=6) {glVertex2i(vertices[i+0],vertices[i+1]);glVertex2i(vertices[i+2],vertices[i+3]);glVertex2i(vertices[i+4],vertices[i+5]);}glEnd();What’s wrong with this approach?Approach 3: Vertex Arrays [varrays.cpp]{ Tell OpenGL to grab all of your vertices from a block of memory// somewhere in my drawing code// tell GL I’m going to use vertex arraysglEnableClientState(GL_VERTEX_ARRAY);// tell GL where my vertices liveglVertexPointer(2,GL_FLOAT,0,myvertices);// tell GL to draw my trianglesglDrawArrays(GL_TRIANGLES,0,numVertices);// leave GL the way I found itglDisableClientState(GL_VERTEX_ARRAY);Vertex Arrays: Pros and Cons{ Pro: Avoid the overhead of 1,000,000 function calls{ Pro: You can change the contents of the array whenever you want (unlike display lists){ Con: Vertex data still gets copied every frameWhat do super-hard-core game developers do?{ Method 4: Vertex buffer objects{ Allocate memory on the video card, only transfer once{ Similar to display lists but often fasterOutline for today{ Moving Data Around{ 2D Transformations{ SIGGRAPH video break{ Matrix Transformations{ Composite Transformations2D Transformations{ Transformations are functions that change the position of a pointz Take one point in Rn, return another point in Rn{ If we apply a transformation to every point in an object, we can change the shape or position of the whole object32D Translationx’ = x + tx y’ = y + ty{ Moves input point by a vector [tx,ty]tx = 2.0ty = 1.0 [tx,ty]2D Translation for Objectsx’ = x + tx y’ = y + ty{ Moves entire object by [tx,ty]tx = 2.0ty = 1.0 2D Scalex’ = x * sx y’ = y * sy{ Multiplies input point by (sx,sy){ Moves point relative to the originWhat would the scale (1,-1) do?sx = sy = 2.0(this is a uniform scale)[x,y][2x,2y]2D Scale for Objectsx’ = x * sx y’ = y * sy{ Resizes entire objectWhat else did this do to my object?sx = sy = 2.02D scaling with a fixed pointMaybe we want (xf,yf) not to move when we scale...What point doesn’t move when we scale?How can that help us scale with a fixed point?x’ = xf + (x - xf)sx y’ = yf + (y - yf)syx’ = x * sx + (1 - sx) xf y’ = y * sy + (1 - sy) yfWhy use the second form of these equations?sx = sy = 2.0(xf,yf) = object center2D scaling with a fixed point{ What we really just did was combine two translations and a scaleTranslate by (-xf,-yf)Scale by (sx,sy)Translate by (xf,yf)42D Rotation{ Moves a point θ degrees along a circle centered at the origin{ But the other transformations had a formula on their slides...{ Doesn’t rotation get a formula too? Isn’t rotation good enough for Mr. Bigshot graphics lecturer? This is outright transformationism! As someone who believes in the equity of all transformations, I’m appalled by this behavior and I’m going to write a report to the something or other board of something or other unless I get a formula for rotation also. Right now.θ = 90˚2D Rotation{ This is straightforward in polar coordinates:x = r cos φ y = r sin φx’ = r cos(φ+θ)y = r sin(φ+θ){ But converting to polar coordinates is a mess{ So we’ll use trig identities…x’ = r cos(φ+θ) = r cos φ cos θ -r sin φ sin θy’ = r sin(φ+θ) = r cos φ sin θ + r sin φ cos θx’ = x cos θ -y sin θy’ = x sin θ + y cos θ2D Rotation for objectsWhat else did this do to my object?How do we fix this?2D Rotation about a fixed point{ Combine two translations and a rotation{ To rotate about a point (xr,yr):x’ = xr + (x - xr) cos θ -(y -yr) sin θy’ = yr + (x - xr) sin θ + (y - yr) cos θSIGGRAPH video breakRon Fedkiw et al (Stanford)… various physical simulation techniques{ Physical simulation: using physics to get realistic behavior from virtual objectsz Examples: f = ma, Navier-Stokes{ Simulation vs. renderingOutline for today{ Moving Data Around{ 2D Transformations{ SIGGRAPH video break{ Matrix Transformations{ Composite Transformations5Representing Transformations{ We do lots of transformations in computer graphics{ We do so many transformations in computer graphics that I want to say that again{ We do lots of transformations in computer graphics{ Need an efficient way of representing transformationsHomogeneous Coordinates{ Write a point (x,y) as a triple:[xh,yh,w]…where xh = x*w, yh = y*w{ w is called the ‘homogeneous coordinate’ and is usually equal to one{ When w = 1, x = xh and y = yhMatrix transformations{ In homogeneous coords, our basic transformations can be written as matrix multiplications{ I submit to you that this matrix represents a translation by [tx,ty]:⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡1001001tytx2D Matrix Translation⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡++=⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡++++++=⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡11*1*0*01**1*01**0*111001001tyytxxyxtyyxtxyxyxtytx{ From a few slides ago:x’ = x + tx y’ = y + ty{


View Full Document

Brown CSCI 1480 - Display Lists 2D Transformations

Download Display Lists 2D Transformations
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Display Lists 2D Transformations and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Display Lists 2D Transformations 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?