PDA

View Full Version : Near plane clipping



Nil_z
04-09-2001, 04:02 PM
I am working on an algorithm of clipping part of triangle at the near plane. It can work right now, but I feel it is far from effecient. The main idea is:
I have 3 vertex in count clockwise order.
for each vertex
{
if vertex.z > 0 // vertex within the frustum
{
store it
if the next vertex.z < 0
{
calculate the intersect point
calculate color, texture coordinate...
store that
}
}
else // vertex out of the frustum
{
if the next vertex.z > 0
{
calculate the intersect point
calculate color, texture coordinate
store it
}
}
}

draw all the vertex in a triangle strip

as you can see, there are a lot of "if" in it(there are more in the real code). Is there a more effecient way to do it?