示例#1
0
	static Poly Rectangle(const float X1, const float Y1, const float X2, const float Y2)
	{
		Poly poly;
		poly.Begin(GL_TRIANGLE_FAN);
		poly.AddVertex(X1, Y1, 0);
		poly.AddVertex(X2, Y1, 0);
		poly.AddVertex(X2, Y2, 0);
		poly.AddVertex(X1, Y2, 0);
		poly.End();
		return poly;
	}
示例#2
0
void Poly::SplitPoly ( Poly *pPoly_, Poly **ppFront_, Poly **ppBack_ )
{
	Plane::eCP	*pCP = new Plane::eCP[ pPoly_->GetNumberOfVertices ( ) ];

	//
	// Classify all points
	//
	for ( int i = 0; i < pPoly_->GetNumberOfVertices ( ); i++ )
	{
		pCP[ i ] = plane.ClassifyPoint ( pPoly_->verts[ i ].p );
	}

	//
	// Build fragments
	//
	Poly		*pFront = new Poly;
	Poly		*pBack	= new Poly;

	pFront->TextureID	= pPoly_->TextureID;
	pBack->TextureID	= pPoly_->TextureID;
	pFront->plane		= pPoly_->plane;
	pBack->plane		= pPoly_->plane;

	for ( i = 0; i < pPoly_->GetNumberOfVertices ( ); i++ )
	{
		//
		// Add point to appropriate list
		//
		switch ( pCP[ i ] )
		{
		case Plane::eCP::FRONT:
			{
				pFront->AddVertex ( pPoly_->verts[ i ] );
			} break;

		case Plane::eCP::BACK:
			{
				pBack->AddVertex ( pPoly_->verts[ i ] );
			} break;

		case Plane::eCP::ONPLANE:
			{
				pFront->AddVertex ( pPoly_->verts[ i ] );
				pBack->AddVertex ( pPoly_->verts[ i ] );
			} break;
		}

		//
		// Check if edges should be split
		//
		int		iNext	= i + 1;
		bool	bIgnore	= false;

		if ( i == ( pPoly_->GetNumberOfVertices ( ) - 1 ) )
		{
			iNext = 0;
		}

		if ( ( pCP[ i ] == Plane::eCP::ONPLANE ) && ( pCP[ iNext ] != Plane::eCP::ONPLANE ) )
		{
			bIgnore = true;
		}
		else if ( ( pCP[ iNext ] == Plane::eCP::ONPLANE ) && ( pCP[ i ] != Plane::eCP::ONPLANE ) )
		{
			bIgnore = true;
		}

		if ( ( !bIgnore ) && ( pCP[ i ] != pCP[ iNext ] ) )
		{
			Vertex	v;	// New vertex created by splitting
			double	p;	// Percentage between the two points

			plane.GetIntersection ( pPoly_->verts[ i ].p, pPoly_->verts[ iNext ].p, v.p, p );

			v.tex[ 0 ] = pPoly_->verts[ iNext ].tex[ 0 ] - pPoly_->verts[ i ].tex[ 0 ];
			v.tex[ 1 ] = pPoly_->verts[ iNext ].tex[ 1 ] - pPoly_->verts[ i ].tex[ 1 ];

			v.tex[ 0 ] = pPoly_->verts[ i ].tex[ 0 ] + ( p * v.tex[ 0 ] );
			v.tex[ 1 ] = pPoly_->verts[ i ].tex[ 1 ] + ( p * v.tex[ 1 ] );

			pFront->AddVertex ( v );
			pBack->AddVertex ( v );
		}
	}

	delete [] pCP;

	pFront->CalculatePlane ( );
	pBack->CalculatePlane ( );

	*ppFront_ = pFront;
	*ppBack_ = pBack;
}