void MatrixInverseTranspose( const VMatrix& src, VMatrix& dst )
{
	src.InverseGeneral( dst );
	dst = dst.Transpose();
}
Beispiel #2
0
void EmitClipPortalGeometry( node_t *pHeadNode, portal_t *pPortal, int iSrcArea, dareaportal_t *dp )
{
	// Build a list of all the points in portals from the same original face.
	CUtlVector<portal_t*> portals;
	FindPortalsLeadingToArea_R( 
		pHeadNode, 
		iSrcArea, 
		dp->otherarea, 
		&pPortal->plane,
		portals );

	CUtlVector<Vector> points;
	for( int iPortal=0; iPortal < portals.Size(); iPortal++ )
	{
		portal_t *pPointPortal = portals[iPortal];
		winding_t *pWinding = pPointPortal->winding;
		for( int i=0; i < pWinding->numpoints; i++ )
		{
			points.AddToTail( pWinding->p[i] );
		}
	}

	// Get the 2D convex hull.

	//// First transform them into a plane.
	QAngle vAngles;
	Vector vecs[3];

	VectorAngles( pPortal->plane.normal, vAngles );
	AngleVectors( vAngles, &vecs[0], &vecs[1], &vecs[2] );
	VMatrix mTransform;
	mTransform.Identity();
	mTransform.SetBasisVectors( vecs[0], vecs[1], vecs[2] );
	VMatrix mInvTransform = mTransform.Transpose();

	int i;
	CUtlVector<Vector2D> points2D;
	for( i=0; i < points.Size(); i++ )
	{
		Vector vTest = mTransform * points[i];
		points2D.AddToTail( Vector2D( vTest.y, vTest.z ) );
	}

	// Build the hull.
	int indices[512];
	int nIndices = Convex2D( points2D.Base(), points2D.Size(), indices, 512 );

	// Output the hull.
	dp->m_FirstClipPortalVert = g_nClipPortalVerts;
	dp->m_nClipPortalVerts = nIndices;

	if ( nIndices >= 32 )
	{
		Warning( "Warning: area portal has %d verts. Could be a vbsp bug.\n", nIndices );
	}

	if( dp->m_FirstClipPortalVert + dp->m_nClipPortalVerts >= MAX_MAP_PORTALVERTS )
	{
		Vector *p = pPortal->winding->p;
		Error( "MAX_MAP_PORTALVERTS (probably a broken areaportal near %.1f %.1f %.1f ", p->x, p->y, p->z );
	}
	
	for( i=0; i < nIndices; i++ )
	{
		g_ClipPortalVerts[g_nClipPortalVerts] = points[ indices[i] ];
		++g_nClipPortalVerts;
	}
}