Public Group

# Not clipping properly

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

## Recommended Posts

Im been trying to get this clipping thing right for quite awhile. The triangle is not getting clipped correctly .Here are some images. The second image is how it should clipped while the first is wrong. Click here for video

The algorithm is:

ClipVertex( const Vector3& end )
{
float BCend = mPlane.Test(end);
bool endInside = ( BCend >= 0.0f );

if (!mFirstVertex)
{
// if one of the points is inside
if ( mStartInside || endInside )
{
// if the start is inside, just output it
if (mStartInside)
mClipVertices[mNumVertices++] = mStart;

// if one of them is outside, output clip point
if ( !(mStartInside && endInside) )
{
float t;
Vector3 output;
if (endInside)
{
t = BCend/(BCend - mBCStart);
output =  end - t*(end - mStart);
}
else
{
t = mBCStart/(mBCStart - BCend);
output = mStart + t*(end - mStart);
}
mClipVertices[mNumVertices++] = output;
}
}
}
mStart = end;
mBCStart = BCend;
mStartInside = endInside;
mFirstVertex = false;

} 

And the plane or the normal is

Plane clipPlane( 1.0f, 0.0f, 0.0f, 0.0f );

Are there any mistakes you can spot?

Edited by terrysworkstations

##### Share on other sites

Doesn't the debugger tell you how it's wrong, ie step through the code to check where it makes a wrong move.

##### Share on other sites

Cant be the Sutherland–Hodgman algorithm,(I checked to see if the vertices were right and they are).I try alittle harder.

Edited by terrysworkstations

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
633715
• Total Posts
3013494
×