Chapter 12 Interactive Graphics Chih-Kuo Yeh. Direct Manipulation Demo.

Slides:



Advertisements
Similar presentations
Better Interactive Programs
Advertisements

3D Game Programming Geometric Transformations
Introduction to OpenGL (Part 4)
Graphics Pipeline.
Chapter 3. Drawing primitives in Space Presented by Garrett Yeh.
CHAPTER 4 Geometric Transformations: The Pipeline Vivian by Richard S. Wright Jr.
When click!! (void) glRenderMode (GL_SELECT); glInitNames(); glPushName(0); glMatrixMode (GL_PROJECTION); glPushMatrix (); glLoadIdentity (); gluPickMatrix.
Viewing and Transformation
OpenGL and Projections
Objectives Learn to build arbitrary transformation matrices from simple transformations Learn to build arbitrary transformation matrices from simple transformations.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Better Interactive Programs Ed Angel Professor of Computer Science, Electrical and Computer.
Projections and Picking Wed 24 Sep 2003
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 OpenGL Transformations Ed Angel Professor of Computer Science, Electrical and Computer.
OpenGL (II). How to Draw a 3-D object on Screen?
CSC461 Lecture 9: GLUT Callbacks Objectives Introduce double buffering for smooth animations Programming event input with GLUT.
Informationsteknologi Tuesday, November 6, 2007Computer Graphics - Class 41 Today’s class Input and interaction.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Picking. What is picking? Selecting an object on the screen What does this require? –Get Mouse Location –Compute what objects are rendered at the position.
19/4/ :32 Graphics II Syllabus Selection and Picking Session 1.
3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!
1 OpenGL Basics A Graphics Standard ©Mel Slater, Anthony Steed
CSC461 Lecture 11: Interactive Programs Contents and Objectives Picking Writing modes – XOR/Copy Rubberbanding Display list.
Open GL Programming Speaker: 彭任右 Date: 2005/10/3.
1 Working with Callbacks Yuanfeng Zhou Shandong University.
WORKING WITH CALLBACKS Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Angel: Interactive.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360.
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Geometric transformations The Pipeline
Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, Chapter 13.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Introduction to OpenGL 1. 2 OpenGL A Graphics rendering API introduced in 1992 by Silicon Graphics Inc Provide the low-level functions to access graphics.
Computing & Information Sciences Kansas State University Lecture 20 of 42CIS 636/736: (Introduction to) Computer Graphics Lecture 21 of 42 William H. Hsu.
Stages of Vertex Transformation To specify viewing, modeling, and projection transformations, you construct a 4 × 4 matrix M, which is then multiplied.
1 Better Interactive Programs. 2 Objectives Learn to build more sophisticated interactive programs using ­Picking Select objects from the display Three.
Computer Graphics Bing-Yu Chen National Taiwan University.
Modeling with OpenGL Practice with OpenGL transformations.
Computer Science Term 1, 2006 Tutorial 2 Assignment 3 – The Virtual World.
OpenGL Selection. Three Selection Methods Color coding (OpenGL) Selection mode (OpenGL) Selection ray (generic)
Computer Graphics I, Fall 2010 Working with Callbacks.
Computer Graphics I, Fall 2010 OpenGL Transformations.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Transformations.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
CGGM Lab. Tan-Chi Ho 2001 Viewing and Transformation.
Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower.
OpenGL: The Open Graphics Language Introduction By Ricardo Veguilla.
Introduction to OpenGL & HW1 Announcement 劉軒銘, 網媒所 碩二 ICG 2012 Fall.
Viewing and Projection
Chap 3 Viewing and Transformation
1 OpenGL Transformations. 2 Objectives Learn how to carry out transformations in OpenGL ­Rotation ­Translation ­Scaling Introduce OpenGL matrix modes.
Selection Mode, Introduction to Widgets Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 6, 2003.
Implement of transformation,projection, viewing Hanyang University Jungsik Park.
OpenGL LAB III.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Working with Callbacks.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360/4360.
CSC Graphics Programming
Viewing 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
School of Computer Science
Working with Callbacks
Transformations V, Viewing I Week 3, Fri Jan 22
3D Computer Graphics (3080/GV10) Week 5-6 Tutorial 3
Better Interactive Programs
Reference1. [OpenGL course slides by Rasmus Stenholt]
Advanced Graphics Algorithms Ying Zhu Georgia State University
Working with Callbacks
Better Interactive Programs
Computer Graphics Practical Lesson 8
Picking in OpenGL Yingcai Xiao.
Transformation Back-face culling View frustum culling
Presentation transcript:

Chapter 12 Interactive Graphics Chih-Kuo Yeh

Direct Manipulation Demo

p1 COP Center of Projection p2 Window Coordinates Object 1 Object 2

Modelview Transformation Vertex Coordinates x, y, z, w Object Coordinates Eye Coordinates Clip Coordinates Device Coordinates Window Coordinates x,y Projection Transformation Perspective Division Viewport Transformation Modelview Matrix Projection Matrix Part of OpenGL State Viewport Transformation

 Selection  Feedback Application Model Application Program Graphics System Output Devices Input Devices API Function Calls or Protocol Data

glSelectBuffer(…) ProcessSelection glMatrixMode(GL_PROJECTION) glPushMatrix() glMatrixMode(GL_PROJECTION) glPopMatrix() Change render mode

glRenderMode(GL_SELECT ) glRenderMode(GL_RENDER ) RenderScene() gluPickMatrix(…) Change render mode

glInitNames() glPushName() glLoadName(…) RenderScene Draw your object 1 glLoadName(…) Draw your object 2

 GLint glRenderMode(GLenum mode);  Mode = 1. GL_RENDER (the default) 2. GL_SELECT 3. GL_FEEDBAC glRenderMode() GL_RENDER GL_SELECT 1 zmin zmax Yellow Cube glRenderMode(GL_RENDER) returns the number of hits while in SELECT mode

 void gluPickMatrix(GLdouble x, GLdouble y, GLdouble width, GLdouble height, GLint viewport[4]);  glGetIntegerv(GL_VIEWPORT, viewport);  gluPickMatrix(xPos, viewport[3] – yPos + viewport[1], 2,2, viewport);

Perspective View Volume Canonical View Volume Projection Transform Pick Matrix Transform Screen Coordinates

 Each hit record consists of four items, in order. 1. The number of names on the name stack when the hit occurred. 2. Both the minimum and maximum window-coordinate z values 3. The contents of the name stack at the time of the hit, with the bottommost element first.

void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Save the matrix state and do the rotations glMatrixMode(GL_MODELVIEW); glPushMatrix(); // Translate the whole scene out and into view glTranslatef(0.0f, 0.0f, f); // Initialize the names stack glInitNames(); glPushName(0); // Name and draw the Sun glColor3f(1.0f, 1.0f, 0.0f); glLoadName(SUN); DrawSphere(15.0f); // Draw Mercury glColor3f(0.5f, 0.0f, 0.0f); glPushMatrix(); glTranslatef(24.0f, 0.0f, 0.0f); glLoadName(MERCURY); DrawSphere(2.0f); glPopMatrix(); // Draw Venus glColor3f(0.5f, 0.5f, 1.0f); glPushMatrix(); glTranslatef(60.0f, 0.0f, 0.0f); glLoadName(VENUS); DrawSphere(4.0f); glPopMatrix(); // Draw the Earth glColor3f(0.0f, 0.0f, 1.0f); glPushMatrix(); glTranslatef(100.0f,0.0f,0.0f); glLoadName(EARTH); DrawSphere(8.0f); glPopMatrix(); // Draw Mars glColor3f(1.0f, 0.0f, 0.0f); glPushMatrix(); glTranslatef(150.0f, 0.0f, 0.0f); glLoadName(MARS); DrawSphere(4.0f); glPopMatrix(); // Restore the matrix state glPopMatrix();// Modelview matrix glutSwapBuffers(); }

void MouseCallback(int button, int state, int x, int y) { if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) ProcessSelection(x, y); }

void ProcessSelection(int xPos, int yPos) { GLfloat fAspect; // Space for selection buffer static GLuint selectBuff[BUFFER_LENGTH]; // Hit counter and viewport storage GLint hits, viewport[4]; // Setup selection buffer glSelectBuffer(BUFFER_LENGTH, selectBuff);

// Get the viewport glGetIntegerv(GL_VIEWPORT, viewport); // Switch to projection and save the matrix glMatrixMode(GL_PROJECTION); glPushMatrix(); // Change render mode glRenderMode(GL_SELECT);

glLoadIdentity(); gluPickMatrix(xPos, viewport[3] - yPos + viewport[1], 2,2, viewport); // Apply perspective matrix fAspect = (float)viewport[2] / (float)viewport[3]; gluPerspective(45.0f, fAspect, 1.0, 425.0); // Draw the scene RenderScene(); // Collect the hits hits = glRenderMode(GL_RENDER);

GLuint nErr = glGetError(); // If a single hit occurred, display the info. if(hits == 1) ProcessPlanet(selectBuff[3]); else glutSetWindowTitle("Nothing was clicked on!"); // Restore the projection matrix glMatrixMode(GL_PROJECTION); glPopMatrix(); // Go back to modelview for normal rendering glMatrixMode(GL_MODELVIEW);

glSelectBuffer( int size, int *pBuffer ); Set up Pick Buffer Selection Buffer: user specified integer array

stack pointer Set up Pick Buffer Initialize Name Stack glRenderMode( GL_SELECT ); glInitNames();

gluPickMatrix( x, y, 5.0, 5.0, viewport ); Initialize Name Stack Set up Pick Buffer Specify a Pick Volume

glPushName(100); Specify a Pick Volume Initialize Name Stack Set up Pick Buffer Draw Object with IDs glDrawRedRect();

glPushName(200); Specify a Pick Volume Draw Object with IDs Initialize Name Stack Set up Pick Buffer glDrawGreenRect();

Specify a Pick Volume Draw Object with IDs Initialize Name Stack Set up Pick Buffer glPushName(300); glDrawBlueRect();

Do anything you want !!! Specify a Pick Volume Draw Object with IDs Initialize Name Stack Set up Pick Buffer Post Processing gRenderMode( GL_RENDER );

glSelectBuffer(…) ProcessSelection glMatrixMode(GL_PROJECTION) glPushMatrix() glMatrixMode(GL_PROJECTION) glPopMatrix() Change render mode MakeSelection

glRenderMode(GL_SELECT ) glRenderMode(GL_RENDER ) RenderScene() gluPickMatrix(…) Change render mode

glInitNames() glPushName() RenderScene glLoadName(…) Draw your object 1 glPassThrough(…) glLoadName(…) Draw your object 2 glPassThrough(…)

glRenderMode(GL_FEEDBACK ) glRenderMode(GL_RENDER ) RenderScene() glFeedbackBuffer(…) MakeSelection Parse the feedback buffer

void glFeedbackBuffer(GLsizei size, GLenum type, GLfloat *buffer);

GL_3D type

[0] GL_PASS_THROUGH_TOKEN [1] User defined name [2] GL_POLYGON_TOKEN [3] Number of vertices [4] x [5] y See MakeSelection(int nChoice) for detail