Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Not clipping properly

$
0
0
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?

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>