An overview of one approach … Compute angle between each polygon normal and a vector from one of the poly vertices to the eyepoint. If angle > 180 degs (i.e. negative dot product), processing of that poly is complete. If angle < 180, add each edge of poly selectively to an edge list. By ‘selectively’ I mean only add it to the list if it isn’t already in the list. If it is already there, remove it. You will be left with a list of silhouette edges only.
Thank to both. I’m now getting an idea of how to idea, but I’d appreciate some help with the code.
Something like:
for(each polygon)
angle= ...
if(angle<180)
for(each edge on the list)
if(edge1 is on the list) remove it
else add it
if(edge2 is on the list) remove it
else add it
if(edge3 is on the list) remove it
else add it
I’d like help with the angle calculation, I’m not very good at 3d math
You’re not going to actually compute the angle, that’s not worth it. Instead, as MaxH says, use the dot product of the normal and the vector from the vertices to the eye point. The dot product of two vectors, a and b, is a_xb_x+a_yb_y+a_z*b_z (multiply corresponding components and add them all up). Through some nifty math, this is equal to the product of the magnitudes of the vectors times the cosine of the angle between them. Since the cosine of angles between 90 and 270 (angles facing away from the camera) is negative, any negative dot product means that the poly is facing away from the camera.
I think tomorrow and the day after tomorrow I’ll have some free time to spend on the code.
I’ve been thinking which could be the best way to organize the edge list.
Are linked lists the best option? It’s the only way I can think about which is easy to “remove” and “add” edges easy and fast during runtime