Archived

This topic is now archived and is closed to further replies.

Point in poly test

This topic is 6616 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

I'm trying to write a point in poly function for my lightmap creator.
Before I used a 2d point-in-poly test, but I want to use planes instead.
I tried this:

code:

int CPoly::GetPointInPoly(CVector p)
{
CVector v1, v2, cNormal, tmp;
CPlane plane;

cNormal = GetNormal( NULL );

for(int i = 0; i < m_iNumVertices; i++)
{
v1 = m_pPolyVert->m_pVertices[ m_iVertices[i] ].cCoord;
tmp = cNormal.Crossproduct( v1 );
tmp.Normalize();
plane.m_cNormal = tmp;
plane.m_fDistance = - ( tmp.Dotproduct( p ) );
if( plane.m_fDistance < 0 )
plane.m_cNormal.Invert();
if( plane.PlaneSide( p ) < 0)
return 0;
}
return 1;
}



But that doesn't work at all

Greets Tobias

Share this post


Link to post
Share on other sites