Changeset 20227
- Timestamp:
- 05/15/07 16:14:57 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
juggler/trunk/modules/vrjuggler/vrj/Draw/OGL/GlBasicSimulator.cpp
r20137 r20227 173 173 174 174 /** Update internal simulator data */ 175 void GlBasicSimulator::updateInternalData( float positionScale)175 void GlBasicSimulator::updateInternalData(const float positionScale) 176 176 { 177 177 mHeadPos = mSimViewport->getUser()->getHeadPosProxy()->getData(positionScale); … … 209 209 } 210 210 211 212 211 /** 213 212 * Draw the projections. … … 217 216 * If !withApex, then just draws the surfaces in all white. 218 217 */ 219 void GlBasicSimulator::drawProjections(bool drawFrustum, gmtl::Vec3f surfColor, const float scaleFactor) 218 void GlBasicSimulator::drawProjections(const bool drawFrustum, 219 const gmtl::Vec3f& surfColor, 220 const float scaleFactor) 220 221 { 221 222 const float ALPHA_VALUE(0.25f); 222 223 223 DisplayManager* display_man = vrj::GlDrawManager::instance()->getDisplayManager(); 224 DisplayManager* display_man = 225 vrj::GlDrawManager::instance()->getDisplayManager(); 224 226 display_man->updateProjections(scaleFactor); // Update all projections for drawing 225 227 … … 229 231 ProjectionPtr proj; 230 232 231 for ( unsigned int i=0;i<disps.size();i++)233 for ( unsigned int i = 0; i < disps.size(); ++i ) 232 234 { 233 for ( unsigned int v=0;v<disps[i]->getNumViewports();v++)235 for ( unsigned int v = 0; v < disps[i]->getNumViewports(); ++v ) 234 236 { 235 237 ViewportPtr view_port = disps[i]->getViewport(v); 236 238 237 if ( view_port->isSurface())239 if ( view_port->isSurface() ) 238 240 { 239 for(unsigned proj_num=0;proj_num<2;++proj_num) 241 // Get a pointer to the surface viewport. 242 SurfaceViewportPtr surf_vp = 243 boost::dynamic_pointer_cast<SurfaceViewport>(view_port); 244 vprASSERT(surf_vp.get() != NULL); 245 246 for ( unsigned int proj_num = 0; proj_num < 2; ++proj_num ) 240 247 { 241 // Get a pointer to the surface 242 SurfaceViewportPtr surf_vp = 243 boost::dynamic_pointer_cast<SurfaceViewport>(view_port); 244 vprASSERT(surf_vp.get() != NULL); 245 246 if(0 == proj_num) 248 if ( 0 == proj_num ) 247 249 { 248 250 proj = surf_vp->getLeftProj(); … … 254 256 255 257 // Create color values that are unique 256 // Basically count in binary (skipping 0), and use the first 3 digits. That will give six colors 257 int red_on = (i & 0x1); int green_on = ((i >> 1) & 0x1); int blue_on = ((i >> 2) & 0x1); 258 // Basically count in binary (skipping 0), and use the first 3 259 // digits. That will give six colors 260 const int red_on = i & 0x1; 261 const int green_on = (i >> 1) & 0x1; 262 const int blue_on = (i >> 2) & 0x1; 258 263 259 264 float red(0.0f), green(0.0f), blue(0.0f); 260 if (red_on > 0) red = 1.0f; 261 if (green_on > 0) green = 1.0f; 262 if (blue_on > 0) blue = 1.0f; 263 264 if ((!red_on) && (!blue_on) && (!green_on)) // Case of 0's (black is bad) 265 if ( red_on > 0 ) 266 { 267 red = 1.0f; 268 } 269 if ( green_on > 0 ) 270 { 271 green = 1.0f; 272 } 273 if ( blue_on > 0 ) 274 { 275 blue = 1.0f; 276 } 277 278 if ( ! red_on && ! blue_on && ! green_on ) // Case of 0's (black is bad) 279 { 265 280 red = blue = green = 0.75f; 281 } 266 282 267 283 gmtl::Vec3f surf_color; 268 gmtl::Vec3f apex_color; 269 if (drawFrustum) 270 { 271 surf_color = gmtl::Vec3f(red,blue,green); 284 if ( drawFrustum ) 285 { 286 surf_color = gmtl::Vec3f(red, blue, green); 272 287 } 273 288 else … … 275 290 surf_color = surfColor; 276 291 } 277 apex_color = surf_color; 278 if(1 == proj_num) // Right eye 292 293 gmtl::Vec3f apex_color(surf_color); 294 295 if ( 1 == proj_num ) // Right eye 279 296 { 280 297 apex_color = gmtl::Vec3f(1.0f, 1.0f, 1.0f) - apex_color; // Invert it 281 298 } 282 299 283 // Compute scaled colors for the corners 284 // ll is going to be lighter and upper right is going to be darker 300 // Compute scaled colors for the corners. 301 // The lower left is going to be lighter, and the upper right 302 // is going to be darker. 285 303 const float ll_scale(0.10f); 286 304 const float ul_scale(0.55f); 287 305 const float ur_scale(1.0f); 288 gmtl::Vec4f ll_clr(ll_scale*surf_color[0],ll_scale*surf_color[1],ll_scale*surf_color[2],ALPHA_VALUE); 289 gmtl::Vec4f ul_clr(ul_scale*surf_color[0],ul_scale*surf_color[1],ul_scale*surf_color[2],ALPHA_VALUE); 290 gmtl::Vec4f lr_clr(ul_scale*surf_color[0],ul_scale*surf_color[1],ul_scale*surf_color[2],ALPHA_VALUE); 291 gmtl::Vec4f ur_clr(ur_scale*surf_color[0],ur_scale*surf_color[1],ur_scale*surf_color[2],ALPHA_VALUE); 306 const gmtl::Vec4f ll_clr(ll_scale * surf_color[0], 307 ll_scale * surf_color[1], 308 ll_scale * surf_color[2], 309 ALPHA_VALUE); 310 const gmtl::Vec4f ul_clr(ul_scale * surf_color[0], 311 ul_scale * surf_color[1], 312 ul_scale * surf_color[2], 313 ALPHA_VALUE); 314 const gmtl::Vec4f lr_clr(ul_scale * surf_color[0], 315 ul_scale * surf_color[1], 316 ul_scale * surf_color[2], 317 ALPHA_VALUE); 318 const gmtl::Vec4f ur_clr(ur_scale * surf_color[0], 319 ur_scale * surf_color[1], 320 ur_scale * surf_color[2], 321 ALPHA_VALUE); 292 322 293 323 // Draw the thingy 294 324 proj->getFrustumApexAndCorners(apex, ur, lr, ul, ll); 295 vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_STATE_LVL) << "apex: " << apex296 << std::endl << vprDEBUG_FLUSH;297 298 glColor4fv(& (apex_color[0]));325 vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_STATE_LVL) 326 << "apex: " << apex << std::endl << vprDEBUG_FLUSH; 327 328 glColor4fv(&apex_color[0]); 299 329 glPushMatrix(); 300 if ( drawFrustum)330 if ( drawFrustum ) 301 331 { 302 drawLine(apex, ur); drawLine(apex, lr); drawLine(apex, ul); drawLine(apex, ll); 332 drawLine(apex, ur); 333 drawLine(apex, lr); 334 drawLine(apex, ul); 335 drawLine(apex, ll); 303 336 } 304 337 305 glColor4fv(& (ur_clr[0]));338 glColor4fv(&ur_clr[0]); 306 339 // Draw the outline 307 drawLine(ur, lr); drawLine(lr, ll); drawLine(ll, ul); drawLine(ul, ur); 340 drawLine(ur, lr); 341 drawLine(lr, ll); 342 drawLine(ll, ul); 343 drawLine(ul, ur); 308 344 309 345 // Draw the surface … … 435 471 } 436 472 437 void GlBasicSimulator::drawLine(gmtl::Vec3f& start, gmtl::Vec3f& end) 473 void GlBasicSimulator::drawLine(const gmtl::Vec3f& start, 474 const gmtl::Vec3f& end) 438 475 { 439 476 glBegin(GL_LINES); … … 443 480 } 444 481 445 void GlBasicSimulator::drawBox( float size,GLenum type)482 void GlBasicSimulator::drawBox(const float size, const GLenum type) 446 483 { 447 484 static GLfloat n[6][3] = … … 486 523 487 524 488 void GlBasicSimulator::drawWireCube( float size)525 void GlBasicSimulator::drawWireCube(const float size) 489 526 { 490 527 drawBox(size, GL_LINE_LOOP); 491 528 } 492 529 493 void GlBasicSimulator::drawSolidCube( float size)530 void GlBasicSimulator::drawSolidCube(const float size) 494 531 { 495 532 drawBox(size, GL_QUADS); juggler/trunk/modules/vrjuggler/vrj/Draw/OGL/GlBasicSimulator.h
r20080 r20227 99 99 100 100 public: 101 const gmtl::Matrix44f& getCameraPos() 101 const gmtl::Matrix44f& getCameraPos() const 102 102 { 103 103 return mCameraPos; 104 104 } 105 105 106 const gmtl::Matrix44f& getHeadPos() 106 const gmtl::Matrix44f& getHeadPos() const 107 107 { 108 108 return mHeadPos; 109 109 } 110 110 111 const gmtl::Matrix44f& getWandPos() 111 const gmtl::Matrix44f& getWandPos() const 112 112 { 113 113 return mWandPos; … … 119 119 120 120 /** Update internal simulator data */ 121 void updateInternalData( float positionScale);121 void updateInternalData(const float positionScale); 122 122 123 123 public: // Sim Drawing parameters 124 bool shouldDrawProjections() 124 bool shouldDrawProjections() const 125 125 { 126 126 return mDrawProjections; 127 127 } 128 128 129 gmtl::Vec3f getSurfaceColor()129 const gmtl::Vec3f& getSurfaceColor() const 130 130 { 131 131 return mSurfaceColor; … … 140 140 141 141 /** Draws projections in OpenGL. */ 142 void drawProjections( bool drawFrustum, gmtl::Vec3fsurfColor,142 void drawProjections(const bool drawFrustum, const gmtl::Vec3f& surfColor, 143 143 const float scaleFactor); 144 144 … … 170 170 protected: // --- Geom helpers --- // 171 171 void initQuadObj(); 172 void drawLine( gmtl::Vec3f& start,gmtl::Vec3f& end);173 void drawBox( float size,GLenum type);174 void drawWireCube( float size);175 void drawSolidCube( float size);172 void drawLine(const gmtl::Vec3f& start, const gmtl::Vec3f& end); 173 void drawBox(const float size, const GLenum type); 174 void drawWireCube(const float size); 175 void drawSolidCube(const float size); 176 176 //void drawGlove(gadget::GloveProxy* gloveProxy); 177 177
