Good day. I want to do a clipping on the front plane using the clipping function from the documentation BSP OpenGL (just using clipping function Split_Polygon), I am after multiplying by the world matrix and view matrix, the front plane is m_Frustum_Near, and the clipping function is Split_Polygon, but not working. What to do? I used this code without Split_Polygon and it works fine. Thanks in advance.
for ( int j = 0; j < tree->polygons.PolygonCount; j++)
{
vertex v0, v1, v2;
v0 = tree->polygons.PolyList[j].Vertex[0];
v1 = tree->polygons.PolyList[j].Vertex[1];
v2 = tree->polygons.PolyList[j].Vertex[2];
v0 = mWorld * v0;
v1 = mWorld * v1;
v2 = mWorld * v2;
v0 = mView * v0;
v1 = mView * v1;
v2 = mView * v2;
polygon poly;
poly.Vertex[0] = v0;
poly.Vertex[1] = v1;
poly.Vertex[2] = v2;
poly.Texture.TexID = tree->polygons.PolyList[j].Texture.TexID;
list front_list;
int cf = 0, cb = 0;
polygon *front_piece=NULL, *back_piece=NULL;
m_Frustum_Near.a = 0.0f;
m_Frustum_Near.b = 0.0f;
m_Frustum_Near.c = 1.0f;
m_Frustum_Near.d = 0.01f;
int res = m_Frustum_Near.Classify_Polygon(&poly);
if(res == SPANNING)
{
Split_Polygon (&poly, &m_Frustum_Near, front_piece, back_piece, cf, cb);
if(cf == 1)
{
front_list.Add_To_List(&front_piece[0]);
}
else if (cf == 2)
{
front_list.Add_To_List(&front_piece[0]);
front_list.Add_To_List(&front_piece[1]);
}
}
else
{
front_list.Add_To_List(&poly);
}
for ( int i = 0; i < front_list.PolygonCount; i++)
{
vertex v0, v1, v2;
v0 = front_list.PolyList[i].Vertex[0];
v1 = front_list.PolyList[i].Vertex[1];
v2 = front_list.PolyList[i].Vertex[2];
v0 = mProj * v0;
v0.x = v0.x / v0.z;
v0.y = v0.y / v0.z;
v1 = mProj * v1;
v1.x = v1.x / v1.z;
v1.y = v1.y / v1.z;
v2 = mProj * v2;
v2.x = v2.x / v2.z;
v2.y = v2.y / v2.z;
v0 = mScreen * v0;
v1 = mScreen * v1;
v2 = mScreen * v2;
polygon pt;
pt.Texture.TexID = front_list.PolyList[i].Texture.TexID;
pt.Vertex[0] = v0;
pt.Vertex[1] = v1;
pt.Vertex[2] = v2;
tree->transformed_polygons.Add_To_List(&pt);
}
}