Jump to content
  • Advertisement
Sign in to follow this  

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.

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

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);
                    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 this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!