コード例 #1
0
void ClipPlaneManager::setClipPlanes(bool navigationEnabled,DisplayState* displayState,GLContextData& contextData) const
	{
	/* Get the clipping plane state tracker: */
	GLClipPlaneTracker* cpt=contextData.getClipPlaneTracker();
	
	/* Process all physical clipping planes first: */
	GLsizei clipPlaneIndex=0;
	bool haveNavigationalClipPlanes=false;
	for(const ClipPlaneListItem* cpPtr=firstClipPlane;cpPtr!=0&&clipPlaneIndex<cpt->getMaxNumClipPlanes();cpPtr=cpPtr->succ)
		{
		if(cpPtr->isEnabled())
			{
			/* Only set clipping plane now if it is physical, or if there is no navigation transformation: */
			if(cpPtr->physical||!navigationEnabled)
				{
				/* Set the clipping plane in the clipping plane tracker and OpenGL: */
				GLClipPlaneTracker::Plane plane;
				for(int i=0;i<3;++i)
					plane[i]=cpPtr->getPlane().getNormal()[i];
				plane[3]=-cpPtr->getPlane().getOffset();
				cpt->enableClipPlane(clipPlaneIndex,plane);
				
				/* Increment the clipping plane index: */
				++clipPlaneIndex;
				}
			else
				haveNavigationalClipPlanes=true;
			}
		}
	
	if(haveNavigationalClipPlanes&&clipPlaneIndex<cpt->getMaxNumClipPlanes())
		{
		/* Temporarily go to navigational coordinates: */
		glPushMatrix();
		glLoadIdentity();
		glMultMatrix(displayState->modelviewNavigational);
		
		/* Process all navigational clipping planes: */
		for(const ClipPlaneListItem* cpPtr=firstClipPlane;cpPtr!=0&&clipPlaneIndex<cpt->getMaxNumClipPlanes();cpPtr=cpPtr->succ)
			{
			if(cpPtr->isEnabled()&&!cpPtr->physical)
				{
				/* Set the clipping plane in the clipping plane tracker and OpenGL: */
				GLClipPlaneTracker::Plane plane;
				for(int i=0;i<3;++i)
					plane[i]=cpPtr->getPlane().getNormal()[i];
				plane[3]=-cpPtr->getPlane().getOffset();
				cpt->enableClipPlane(clipPlaneIndex,plane);
				
				/* Increment the clipping plane index: */
				++clipPlaneIndex;
				}
			}
		
		/* Return to physical coordinates: */
		glPopMatrix();
		}
	
	/* Disable all unused clipping planes still enabled from the last pass: */
	while(clipPlaneIndex<cpt->getMaxNumClipPlanes())
		{
		cpt->disableClipPlane(clipPlaneIndex);
		++clipPlaneIndex;
		}
	}