RenderingHandler Class Reference

#include <RenderingHandler.h>

Collaboration diagram for RenderingHandler:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 RenderingHandler (WindowHandler *window_handler, RadialLayout *radial_layout, Graph *graph, GLuint screen_width, GLuint screen_height)
 ~RenderingHandler ()
void runMainLoop ()
void handleKeyPressEvent (SDL_keysym *keysym)
void renderScene ()
int RetrieveObjectID (int x, int y)

Protected Member Functions

 RenderingHandler ()

Protected Attributes

WindowHandlerwindow_handler_
 This holds the window handler.

RadialLayoutradial_layout_
 This holds the Radial Layout for it's drawing.

Graphgraph_
 The graph to render.

GLuint screen_width_
 The screen width.

GLuint screen_height_
 The screen height.

bool is_animation_mode_active_
 Sets the animation mode.


Detailed Description

This class contains methods and member variables to handle rendering of a scene and quering and processing of events (like mouse or keyboard events).

Definition at line 22 of file RenderingHandler.h.


Constructor & Destructor Documentation

RenderingHandler::RenderingHandler  )  [inline, protected]
 

The default constructor.

Definition at line 43 of file RenderingHandler.h.

References radial_layout_, and window_handler_.

00043 : 00044 window_handler_(NULL), 00045 radial_layout_(NULL) 00046 { 00047 }

RenderingHandler::RenderingHandler WindowHandler window_handler,
RadialLayout radial_layout,
Graph graph,
GLuint  screen_width,
GLuint  screen_height
[inline]
 

The constructor.

Parameters:
window_handler This is the window hanlder that has to be stored.

Definition at line 55 of file RenderingHandler.h.

References graph_, is_animation_mode_active_, radial_layout_, screen_height_, screen_width_, and window_handler_.

00056 : 00057 window_handler_(window_handler), 00058 radial_layout_(radial_layout), 00059 graph_(graph), 00060 screen_width_(screen_width), 00061 screen_height_(screen_height), 00062 is_animation_mode_active_(false) 00063 { 00064 }

RenderingHandler::~RenderingHandler  )  [inline]
 

The destructor.

Definition at line 70 of file RenderingHandler.h.

00071 { 00072 }


Member Function Documentation

void RenderingHandler::handleKeyPressEvent SDL_keysym *  keysym  ) 
 

This handles the key-press-events.

Parameters:
keysym The SDL-internal key symbol.
Precondition:
keysym != NULL window_handler_ != NULL

Definition at line 78 of file RenderingHandler.cpp.

References graph_, handleKeyPressEvent(), is_animation_mode_active_, num_iterations_, Graph::setAnimationMode(), WindowHandler::toggleFullScreen(), Graph::toggleRenderMode(), and window_handler_.

Referenced by handleKeyPressEvent(), and runMainLoop().

00079 { 00080 switch (keysym -> sym) 00081 { 00082 case SDLK_F1 : 00083 window_handler_->toggleFullScreen(); 00084 break; 00085 case SDLK_ESCAPE : 00086 quitApplication(0); 00087 case SDLK_a : 00088 if (is_animation_mode_active_ == false) 00089 { 00090 num_iterations_ = 1; 00091 is_animation_mode_active_ = true; 00092 is_animation_running = true; 00093 graph_->setAnimationMode(true); 00094 } 00095 else 00096 { 00097 is_animation_mode_active_ = false; 00098 } 00099 break; 00100 case SDLK_m : 00101 graph_->toggleRenderMode(); 00102 break; 00103 default : 00104 break; 00105 } 00106 }

Here is the call graph for this function:

void RenderingHandler::renderScene  ) 
 

This renders the whole scene.

Definition at line 112 of file RenderingHandler.cpp.

References Graph::drawGraph(), graph_, num_iterations_, and radial_layout_.

Referenced by RetrieveObjectID(), and runMainLoop().

00113 { 00114 if (num_iterations_ != 0) 00115 { 00116 ++num_iterations_; 00117 } 00118 glClearColor(1.0f, 1.0f, 1.0f, 1.0f); 00119 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00120 glLoadIdentity(); // reset the view 00121 00122 // position view up vector 00123 gluLookAt(0, 0, 6, 0, 0, 0, 0, 1, 0); 00124 00125 // number of circles 00126 GLint num_circles = 10; 00127 00128 // radius of the starting circle 00129 GLfloat radius = -0.1f; 00130 GLUquadricObj *qobj; 00131 qobj = gluNewQuadric(); 00133 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); 00134 glEnable(GL_LINE_SMOOTH); 00136 gluQuadricNormals(qobj, GLU_SMOOTH); 00137 glDisable(GL_BLEND); 00138 radial_layout_ -> setNumberDisplayedRings(num_circles); 00139 radial_layout_ -> setRadiusOfRing(1, radius); 00140 radial_layout_ -> renderRadialLayout(qobj); 00141 glInitNames(); 00142 glPushName(0); 00143 graph_->drawGraph(qobj); 00144 glColor3f(1.0f, 1.0f, 1.0f); 00145 glDisable(GL_LINE_SMOOTH); 00146 // swap buffers 00147 SDL_GL_SwapBuffers(); 00148 gluDeleteQuadric(qobj); 00149 }

Here is the call graph for this function:

int RenderingHandler::RetrieveObjectID int  x,
int  y
 

Definition at line 153 of file RenderingHandler.cpp.

References renderScene(), RetrieveObjectID(), screen_height_, and screen_width_.

Referenced by RetrieveObjectID(), and runMainLoop().

00154 { 00155 int objectsFound = 0; // This will hold the amount of objects clicked 00156 int viewportCoords[4] = {0}; // We need an array to hold our view port coordinates 00157 00158 // This will hold the ID's of the objects we click on. 00159 // We make it an arbitrary number of 32 because openGL also stores other information 00160 // that we don't care about. There is about 4 slots of info for every object ID taken up. 00161 unsigned int selectBuffer[1024] = {0}; 00162 00163 // glSelectBuffer is what we register our selection buffer with. The first parameter 00164 // is the size of our array. The next parameter is the buffer to store the information found. 00165 // More information on the information that will be stored in selectBuffer is further below. 00166 00167 glSelectBuffer(1024, selectBuffer); // Setup our selection buffer to accept object ID's 00168 00169 // This function returns information about many things in OpenGL. We pass in GL_VIEWPORT 00170 // to get the view port coordinates. It saves it like a RECT with {top, left, bottom, right} 00171 00172 glGetIntegerv(GL_VIEWPORT, viewportCoords); // Get the current view port coordinates 00173 00174 // Now we want to get out of our GL_MODELVIEW matrix and start effecting our 00175 // GL_PROJECTION matrix. This allows us to check our X and Y coords against 3D space. 00176 00177 glMatrixMode(GL_PROJECTION); // We want to now effect our projection matrix 00178 00179 glPushMatrix(); // We push on a new matrix so we don't effect our 3D projection 00180 00181 // This makes it so it doesn't change the frame buffer if we render into it, instead, 00182 // a record of the names of primitives that would have been drawn if the render mode was 00183 // GL_RENDER are now stored in the selection array (selectBuffer). 00184 00185 glRenderMode(GL_SELECT); // Allows us to render the objects, but not change the frame buffer 00186 00187 glLoadIdentity(); // Reset our projection matrix 00188 00189 // gluPickMatrix allows us to create a projection matrix that is around our 00190 // cursor. This basically only allows rendering in the region that we specify. 00191 // If an object is rendered into that region, then it saves that objects ID for us (The magic). 00192 // The first 2 parameters are the X and Y position to start from, then the next 2 00193 // are the width and height of the region from the starting point. The last parameter is 00194 // of course our view port coordinates. You will notice we subtract "y" from the 00195 // BOTTOM view port coordinate. We do this to flip the Y coordinates around. The 0 y 00196 // coordinate starts from the bottom, which is opposite to window's coordinates. 00197 // We also give a 2 by 2 region to look for an object in. This can be changed to preference. 00198 00199 gluPickMatrix(x, viewportCoords[3] - y, 2, 2, viewportCoords); 00200 00201 // Next, we just call our normal gluPerspective() function, exactly as we did on startup. 00202 // This is to multiply the perspective matrix by the pick matrix we created up above. 00203 00204 gluPerspective(45.0f,(float)screen_width_/(float)screen_height_,0.1f,150.0f); 00205 00206 glMatrixMode(GL_MODELVIEW); // Go back into our model view matrix 00207 00208 renderScene(); // Now we render into our selective mode to pinpoint clicked objects 00209 00210 // If we return to our normal render mode from select mode, glRenderMode returns 00211 // the number of objects that were found in our specified region (specified in gluPickMatrix()) 00212 00213 objectsFound = glRenderMode(GL_RENDER); // Return to render mode and get the number of objects found 00214 00215 glMatrixMode(GL_PROJECTION); // Put our projection matrix back to normal. 00216 glPopMatrix(); // Stop effecting our projection matrix 00217 00218 glMatrixMode(GL_MODELVIEW); // Go back to our normal model view matrix 00219 00220 // PHEW! That was some stuff confusing stuff. Now we are out of the clear and should have 00221 // an ID of the object we clicked on. objectsFound should be at least 1 if we found an object. 00222 00223 if (objectsFound > 0) 00224 { 00225 // If we found more than one object, we need to check the depth values 00226 // of all the objects found. The object with the LEAST depth value is 00227 // the closest object that we clicked on. Depending on what you are doing, 00228 // you might want ALL the objects that you clicked on (if some objects were 00229 // behind the closest one), but for this tutorial we just care about the one 00230 // in front. So, how do we get the depth value? Well, The selectionBuffer 00231 // holds it. For every object there is 4 values. The first value is 00232 // "the number of names in the name stack at the time of the event, followed 00233 // by the minimum and maximum depth values of all vertices that hit since the 00234 // previous event, then followed by the name stack contents, bottom name first." - MSDN 00235 // The only ones we care about are the minimum depth value (the second value) and 00236 // the object ID that was passed into glLoadName() (This is the fourth value). 00237 // So, [0 - 3] is the first object's data, [4 - 7] is the second object's data, etc... 00238 // Be carefull though, because if you are displaying 2D text in front, it will 00239 // always find that as the lowest object. So make sure you disable text when 00240 // rendering the screen for the object test. I use a flag for RenderScene(). 00241 // So, lets get the object with the lowest depth! 00242 00243 // Set the lowest depth to the first object to start it off. 00244 // 1 is the first object's minimum Z value. 00245 // We use an unsigned int so we don't get a warning with selectBuffer below. 00246 unsigned int lowestDepth = selectBuffer[1]; 00247 00248 // Set the selected object to the first object to start it off. 00249 // 3 is the first object's object ID we passed into glLoadName(). 00250 int selectedObject = selectBuffer[3]; 00251 00252 // Go through all of the objects found, but start at the second one 00253 // for(int i = 1; i < objectsFound; i++) 00254 // { 00255 // // Check if the current objects depth is lower than the current lowest 00256 // // Notice we times i by 4 (4 values for each object) and add 1 for the depth. 00257 // if(selectBuffer[(i * 4) + 1] < lowestDepth) 00258 // { 00259 // // Set the current lowest depth 00260 // lowestDepth = selectBuffer[(i * 4) + 1]; 00261 00262 // // Set the current object ID 00263 // selectedObject = selectBuffer[(i * 4) + 3]; 00264 // } 00265 // } 00266 00267 // Return the selected object 00268 return selectedObject; 00269 } 00270 00271 // We didn't click on any objects so return 0 00272 return 0; 00273 }

Here is the call graph for this function:

void RenderingHandler::runMainLoop  ) 
 

This handles the main loop of the application.

Definition at line 17 of file RenderingHandler.cpp.

References clicked_object_id_, Graph::createGraph(), graph_, handleKeyPressEvent(), Graph::highlightNodeIfSelected(), is_animation_mode_active_, is_animation_running_, Graph::isANodeClicked(), motion_object_id_, num_iterations_, renderScene(), WindowHandler::resizeVideoMode(), RetrieveObjectID(), Graph::setAnimationMode(), Graph::setCenterNode(), and window_handler_.

00018 { 00019 bool done = false; 00020 SDL_Event event; 00021 graph_->createGraph("Hallo"); 00022 GLuint clicked_object_id_ = 0; 00023 GLuint motion_object_id_ = 0; 00024 00025 while (!done) 00026 { 00027 while (SDL_PollEvent(&event)) 00028 { 00029 switch (event.type) 00030 { 00031 case SDL_QUIT : 00032 done = true; 00033 break; 00034 case SDL_KEYDOWN : 00035 handleKeyPressEvent(&event.key.keysym); 00036 break; 00037 case SDL_VIDEORESIZE : 00038 window_handler_->resizeVideoMode(event.resize.w, event.resize.h); 00039 // window_handler_->initOpenGL(); // this resizes the window 00040 case SDL_MOUSEBUTTONDOWN : // If the left mouse button was clicked 00041 cout << event.button.x << " " << event.button.y << endl; 00042 // Here we pass in the cursors X and Y co-ordinates to test 00043 // an object under the mouse. 00044 clicked_object_id_ = RetrieveObjectID(event.button.x,event.button.y); 00045 graph_->highlightNodeIfSelected(clicked_object_id_); 00046 if ((graph_->isANodeClicked(clicked_object_id_)) 00047 && (is_animation_running_ == false)) 00048 { 00049 num_iterations__ = 1; 00050 is_animation_running_ = true; 00051 00052 graph_->setCenterNode(clicked_object_id_); 00053 } 00054 /*case SDL_MOUSEMOTION : 00055 motion_object_id_ = RetrieveObjectID(event.motion.x, event.motion.y); 00056 graph_->highlightNodeIfSelected(motion_object_id_); 00057 break; 00058 default :*/ 00059 break; 00060 } 00061 } 00062 if ((is_animation_running == false) && (is_animation_mode_active_ == true)) 00063 { 00064 num_iterations_ = 1; 00065 is_animation_running = true; 00066 graph_->setAnimationMode(true); 00067 } 00068 renderScene(); 00069 } 00070 }

Here is the call graph for this function:


Member Data Documentation

Graph* RenderingHandler::graph_ [protected]
 

The graph to render.

Definition at line 30 of file RenderingHandler.h.

Referenced by handleKeyPressEvent(), RenderingHandler(), renderScene(), and runMainLoop().

bool RenderingHandler::is_animation_mode_active_ [protected]
 

Sets the animation mode.

Definition at line 36 of file RenderingHandler.h.

Referenced by handleKeyPressEvent(), RenderingHandler(), and runMainLoop().

RadialLayout* RenderingHandler::radial_layout_ [protected]
 

This holds the Radial Layout for it's drawing.

Definition at line 28 of file RenderingHandler.h.

Referenced by RenderingHandler(), and renderScene().

GLuint RenderingHandler::screen_height_ [protected]
 

The screen height.

Definition at line 34 of file RenderingHandler.h.

Referenced by RenderingHandler(), and RetrieveObjectID().

GLuint RenderingHandler::screen_width_ [protected]
 

The screen width.

Definition at line 32 of file RenderingHandler.h.

Referenced by RenderingHandler(), and RetrieveObjectID().

WindowHandler* RenderingHandler::window_handler_ [protected]
 

This holds the window handler.

Definition at line 26 of file RenderingHandler.h.

Referenced by handleKeyPressEvent(), RenderingHandler(), and runMainLoop().


The documentation for this class was generated from the following files:
Generated on Mon Jun 14 12:49:12 2004 for InfoVis by doxygen 1.3.7