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?