Пример #1
0
void DebuggingView::drawRays()
{
	glDisable( GL_LIGHTING );
	// Now draw all the rays
	for( std::vector< std::pair<ray, isect> >::const_iterator rayItr = 
		raytracer->getScene().intersectCache.begin();
		rayItr != raytracer->getScene().intersectCache.end();
		++rayItr )
	{
		switch( rayItr->first.type() )
		{
		case ray::VISIBILITY:
			if( !m_showVisibilityRays ) continue;
			glColor4f( 0.4f, 0.4f, 1.0f, 1.0f );
			break;
			
		case ray::REFLECTION:
			if( !m_showReflectionRays ) continue;
			glColor4f( 1.0f, 1.0f, 0.0f, 1.0f );
			break;

		case ray::REFRACTION:
			if( !m_showRefractionRays ) continue;
			glColor4f( 1.0f, 1.0f, 0.0f, 1.0f );
			break;

		case ray::SHADOW:
			if( !m_showShadowRays ) continue;
			glColor4f( 0.20f, 0.45f, 0.72f, 1.0f );
			break;
		}
		Vec3d p = rayItr->first.getPosition();
		Vec3d d = rayItr->first.getDirection();
		Vec3d isectPoint = p + rayItr->second.t*d;

		glEnable( GL_LINE_STIPPLE );
		glLineStipple( 1, 0x3333 );

		glBegin( GL_LINES );
			glVertex3dv( p.getPointer() );
			glVertex3dv( isectPoint.getPointer() );
		glEnd();

		glDisable(GL_LINE_STIPPLE);

		if( m_showNormals )
		{
			glPushMatrix();
				glTranslatef( isectPoint[0], isectPoint[1], isectPoint[2] );
				glBegin( GL_LINES );
					glColor4f( 0.5f, 1.0f, 0.5f, 1.0f );
					glVertex3d( 0.0, 0.0, 0.0 );
					glVertex3dv( rayItr->second.N.getPointer() );
				glEnd();
			glPopMatrix();
		}
	}
	glEnd();
	glEnable( GL_LIGHTING );
}