vec4 Scene::processHitListAndGetColor() { #ifdef _DEBUG_SCENE if (mHitList.size() == 0) { std::cout << "\n+++++++++++++++++++++++++++++++++++++++++++++++++++\n"; std::cout << "\nFrom: " << __FILE__; std::cout << "\n HitList is zero!"; std::cout << "\n+++++++++++++++++++++++++++++++++++++++++++++++++++\n"; } #endif if (mHitList.size() == 0) return vec4(0.5, 0.5, 0.5, 0.0); // TODO: Do some calculations and get a color Hit winHit; double min = 0xFFFFFFFF; for (int i = 0; i < mHitList.size(); i++) { if (mHitList[i].intersectDis < min) { winHit.obj = mHitList[i].obj; winHit.intersectDis = mHitList[i].intersectDis; winHit.intersectPoint = mHitList[i].intersectPoint; min = winHit.intersectDis; } } #ifdef _DEBUG_SCENE std::cout << "\nWinning object: " << OBJ_STR[winHit.obj->getObjectType()]; std::cout << "\nReturning color:"; #endif return lightScene(winHit); }
void DebuggingView::draw() { if (!valid()) { glShadeModel( GL_SMOOTH ); glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); glEnable( GL_LIGHT1 ); glEnable( GL_NORMALIZE ); } glViewport( 0, 0, w(), h() ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(30.0,-float(w())/float(h()),1.0,100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_camera->applyViewingTransform(); // Need to apply an extra transform so that our camera 'approximately' // lines up with the scene camera, initially, and to correct for our // definition of "up." { Vec3d uAxis = raytracer->getScene().getCamera().getU(); Vec3d vAxis = raytracer->getScene().getCamera().getV(); Vec3d wAxis = uAxis ^ vAxis; uAxis = wAxis ^ vAxis; uAxis.normalize(); vAxis.normalize(); wAxis.normalize(); GLdouble rotMat[16]; rotMat[0] = uAxis[0]; rotMat[1] = vAxis[0]; rotMat[2] = wAxis[0]; rotMat[3] = 0.0; rotMat[4] = uAxis[1]; rotMat[5] = vAxis[1]; rotMat[6] = wAxis[1]; rotMat[7] = 0.0; rotMat[8] = uAxis[2]; rotMat[9] = vAxis[2]; rotMat[10] = wAxis[2]; rotMat[11] = 0.0; rotMat[12] = 0.0; rotMat[13] = 0.0; rotMat[14] = 0.0; rotMat[15] = 1.0; glMultMatrixd( rotMat ); } if( m_showAxes ) drawAxes(); if( raytracer == 0 || !raytracer->sceneLoaded() ) return; if( m_showLights ) drawLights(); if( m_showGeometry ) { lightScene(); drawScene(); } drawRays(); if( m_showCamera ) drawCamera(); }