Not clipping properly

Started by
2 comments, last by terrysworkstations 6 years, 9 months ago

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

N9mtp.pngAuSOb.png

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?

Advertisement

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

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

This topic is closed to new replies.

Advertisement