Unformatted text preview:

Picking and CurvesWeek 6David BreenDepartment of Computer ScienceDrexel UniversityBased on material from Ed Angel, University of New MexicoCS 480/680INTERACTIVE COMPUTER GRAPHICSAngel: Interactive Computer Graphics 3E© Addison-Wesley 20022Objectives• Picking– Select objects from the display• Introduce types of curves and surfaces– Explicit– Implicit– Parametric– Strengths and weaknesses• Discuss Modeling and Approximations– Conditions– StabilityAngel: Interactive Computer Graphics 3E© Addison-Wesley 20023Picking• Identify a user-defined object on the display• In principle, it should be simple because themouse gives the position and we should beable to determine to which object(s) a positioncorresponds• Practical difficulties– Pipeline architecture is feed forward, hard to gofrom screen back to world– Complicated by screen being 2D, world is 3D– How close do we have to come to object to say weselected it?Angel: Interactive Computer Graphics 3E© Addison-Wesley 20024Three Approaches• Hit list– Most general approach but most difficult toimplement• Use back or some other buffer to storeobject ids as the objects are rendered• Rectangular maps– Easy to implement for many applications– Divide screen into rectangular regionsAngel: Interactive Computer Graphics 3E© Addison-Wesley 20025Using another buffer andcolors for picking• For a small number of objects, we can assign a unique color(often in color index mode) to each object• We then render the scene to a color buffer other than the frontbuffer so the results of the rendering are not visible• We then get the mouse position and use glReadPixels() toread the color in the buffer we just wrote at the position of themouse• The returned color gives the id of the objectAngel: Interactive Computer Graphics 3E© Addison-Wesley 20026Using Regions of the Screen• Many applications use a simple rectangular arrangement of thescreen– Example: paint/CAD program• Easier to look at mouse position and determine which area ofscreen it is in that using selection mode pickingdrawing areatoolsmenusAngel: Interactive Computer Graphics 3E© Addison-Wesley 20027Rendering Modes• OpenGL can render in one of threemodes selected by glRenderMode(mode)– GL_RENDER: normal rendering to the framebuffer (default)– GL_FEEDBACK: provides list of primitivesrendered but no output to the frame buffer– GL_SELECTION: Each primitive in the viewvolume generates a hit record that is placedin a name stack which can be examinedlaterAngel: Interactive Computer Graphics 3E© Addison-Wesley 20028Hit RecordAngel: Interactive Computer Graphics 3E© Addison-Wesley 20029Using Selection Mode• Initialize name buffer• Enter selection mode (using mouse)• Render scene with user-defined names (id#)– Every object in view volume generates a hit– Name stack processing always done• Reenter normal render mode– This operation returns number of hits• Examine contents of name buffer (hit records)– Hit records include number of ids, depthinformation and ids on stack at moment ofrenderingAngel: Interactive Computer Graphics 3E© Addison-Wesley 200210Selection Mode Functions•glSelectBuffer(): specifies name buffer•glInitNames(): initializes name buffer•glPushName(id): push id on name buffer•glPopName(): pop top of name buffer•glLoadName(id): replace top name onbuffer• id is set by application to identify objects• Can’t be called inside glBegin/glEndAngel: Interactive Computer Graphics 3E© Addison-Wesley 200211Selection Mode and Picking• In general, selection mode won’t workfor picking because every primitive inthe view volume will generate a hit• Change the viewingparameters so thatonly those primitivesnear the cursor are inthe altered view volume– Use gluPickMatrixAngel: Interactive Computer Graphics 3E© Addison-Wesley 200212gluPickMatrix()• gluPickMatrix(Gldouble x, Gldouble y,Gldouble w, Gldouble h, Glint *vp)– k– Creates a projection matrix for picking thatrestricts drawing to a w x h area centered at(x,y) in the window coordinates within theviewport vpGo to pick.cIntroduction to CurvesAngel: Interactive Computer Graphics 3E© Addison-Wesley 200215Escaping Flatland• Until now we have worked with flat entitiessuch as lines and flat polygons– Fit well with graphics hardware– Mathematically simple• But the world is not composed of flatentities– Need curves and curved surfaces– May only have need at the application level– Implementation can render themapproximately with flat primitivesAngel: Interactive Computer Graphics 3E© Addison-Wesley 200216Modeling with Curvesdata pointsapproximating curveinterpolating data pointAngel: Interactive Computer Graphics 3E© Addison-Wesley 200217What Makes a GoodRepresentation?• There are many ways to represent curvesand surfaces• Want a representation that is– Stable– Smooth– Easy to evaluate– Must we interpolate or can we just come close todata?– Do we need derivatives?Angel: Interactive Computer Graphics 3E© Addison-Wesley 200218Explicit Representation• Most familiar form of curve in 2D y=f(x)• Cannot represent all curves– Vertical lines– Circles• Extension to 3D– y=f(x), z=g(x)– The form z = f(x,y) defines a surfacexyxyzAngel: Interactive Computer Graphics 3E© Addison-Wesley 200219Implicit Representation• Two dimensional curve(s) g(x,y)=0• Much more robust– All lines ax+by+c=0– Circles x2+y2-r2=0• Three dimensions g(x,y,z)=0 defines a surface– Intersect two surface to get a curve• In general, we cannot solve for points that satisfythe equationAngel: Interactive Computer Graphics 3E© Addison-Wesley 200220Parametric Curves• Separate equation for each spatial variable x=x(u) y=y(u) z=z(u)• For umax ≥ u ≥ umin we trace out a curve in twoor three dimensionsp(u)=[x(u), y(u), z(u)]Tp(u)p(umin)p(umax)Angel: Interactive Computer Graphics 3E© Addison-Wesley 200221Selecting Functions• Usually we can select “good” functions– not unique for a given spatial curve– Approximate or interpolate known data– Want functions which are easy to evaluate– Want functions which are easy to differentiate• Computation of normals• Connecting pieces (segments)– Want functions which are smoothAngel: Interactive Computer Graphics 3E© Addison-Wesley 200222Parametric LinesLine connecting two points p0 and p1


View Full Document

DREXEL CS 480 - Lecture6

Documents in this Course
Load more
Download Lecture6
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 Lecture6 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 Lecture6 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?