Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intro to lighting (Chapter 11)

Similar presentations


Presentation on theme: "Intro to lighting (Chapter 11)"— Presentation transcript:

1 Intro to lighting (Chapter 11)
Class 13 Selection and Picking dragging with picking Collision Detection articulated Figure Intro to lighting (Chapter 11)

2 Picking and Selection Run BallAndTorusPicking.cpp to understand the problem. How computer knows which shape or color to use for drawing. How can the computer "know" which shape belongs to a pixel to modify?

3 glRenderMode(GL_SELECT)
Selection Tell computer you will be selecting glRenderMode(GL_SELECT) Specify a (new, small) viewing volume selection volume Redraw the scene, invisibly, recoding which items hit the viewing volume hit list

4 when hit records are written
A hit record is written into the hit buffer when both a name stack manipulation or a glRenderMode() command is encountered a hit has occured - a primitive has been drawn that intersects the selection volume

5 what hit records contain
the number of names in the name stack at the time of writing the record the min z-value‡ of primitives that hit selection volume since last hit record was written the max z-value‡ of primitives that hit selection volume since last hit record was written the sequence of names in the name stack at time of writing, bottom one first, may be none.

6 How to PICK the right selection volume?

7 gluPickMatrix(pickX, pickY, width, height, viewport[4])
glLoadIdentity(); gluPickMatrix(pickX, pickY,width,height, viewport[4]); glFrustrum(); or gluPerspective; or glOrtho; (same as resize function, or what the program is using.)

8 gluPickMatrix(pickX, pickY, width, height, viewport[4])
pickX and pickY are in gl screen coords. front face of selection volume is centered at (pickX, pickY) with given width and height. In pixels. viewport array supplies current viewport boundaries. Can use glGetIntegerv(GL_VIEWPORT,viewport)

9 min and max values ‡ min and max are "normalized" by dividing by depth of selection volume, so value is in range [0,1]. Then multiplied by and stored as an unsigned int.

10 ballAndTorusPicking.cpp void drawBallAndTorus(void)
void drawScene(void) // The mouse callback routine. void pickFunction(int button, int state, int x, int y) void findClosestHit(int hits, unsigned int buffer[]) void animate(int value)

11 ballAndTorusPicking Make these changes for better model
In function drawBallAndTorus remove glutSwapBuffers(); In function drawScene add glutSwapBuffers();

12 In Ortho, dragging using selection
BoxAndCubesPickingAndDragging.cpp (MJB) use selection to know you have clicked on object while button stays down, use mouseMotion. end motion when button released On board, discuss change of coordinates

13 In Ortho, dragging using selection
BoxAndCubesPickingAndDragging.cpp (MJB) Don't call glutPostRedisplay in drawScene. Do swap buffers (or flush) in drawScene Do call glutPostRedisplay in mouseMotion Don't swap buffers in drawBoxAndCubes Don't glutPostRedisplay in drawBoxAndCubes

14 other ways to pick we won't cover
Color each object a different colors, and check the color of the pixel using glReadPixels Using a pick ray and gluUnProject

15 collision detection Run spaceTravel.cpp
Go through code - non-collision parts Notice class, constructors Notice viewports. Notice display list. Notice rand. In setup I added srand(time(0)); Need to include ctime I also changed FILL_PROBABILITY

16 collision detection Run spaceTravel.cpp
Go through code - non-collision parts Notice class, constructors Notice viewports. Notice display list. Notice rand. In setup I added srand(time(0)); Need to include ctime I also changed FILL_PROBABILITY

17 geometry of the spacecraft
radius 5 height 10 red center to edge of circle =sqrt(50) = 7.072

18 geometry of collisions
Got to Here!!!!!!!!

19 collision detection spaceTravel.cpp
static int isCollision = 0; // Is there collision between the spacecraft and an asteroid? functions: int checkSpheresIntersection(...) int asteroidCraftCollision(...) see specialKeyInput function

20 Articulated Figure On your own, run animateMan.cpp.
Do the experiments in the book. Come back with questions.

21 Phong's Lighting Model Ambient light - even light all around. Direction of light and viewer don't matter. Diffuse - fine scale graininess of surface. Direction of light source matters, direction of viewer doesn't matter. Specular - shininess of surface. Direction of light source and viewer both matter.

22 Run sphereInBox1.cpp Observe box and ball materials and lighting.
Look at code later.

23 Lots of thing to specify for each light and material of objects
Ambient R, G, B Diffuse R, G, B Specular R, G, B For material, also emissive - looks like light coming from object. Specular also has a shininess component.

24 Normals To get proper reflection, we need to know "surface direction".

25 BoxAndSquaresPickingAndViews.cpp Cookie cutter approach – take advantage of it!


Download ppt "Intro to lighting (Chapter 11)"

Similar presentations


Ads by Google