Forum: Poser - OFFICIAL


Subject: New Reality (lux render) Plugin over at Daz...time for Poser Plugin Update?

Ridley5 opened this issue on Jul 26, 2010 · 1724 posts


kawecki posted Tue, 10 August 2010 at 11:38 PM

Quote - > Quote - @kawecki:

Actually, on closer inspection, this bit in your code puzzles me:

   
            Begin<br></br>
           
      va = pol->vertex[j];<br></br>
           
      vb = ((j+1) == nv) ? pol->vertex[0] :
pol->vertex[j+1];<br></br>
           
      normal.x += (vertices[va].pos.y -
vertices[vb].pos.y) *<br></br>
           
           
          (vertices[va].pos.z +
vertices[vb].pos.z);<br></br>
           
      normal.y += (vertices[va].pos.z -
vertices[vb].pos.z) *<br></br>
           
           
          (vertices[va].pos.x +
vertices[vb].pos.x);<br></br>
           
      normal.z += (vertices[va].pos.x -
vertices[vb].pos.x) *<br></br>
           
           
          (vertices[va].pos.y +
vertices[vb].pos.y);<br></br>
           
    End<br></br>

Could you explain why this works or give me a reference?

This looks like an attempt to do cross product, but the second terms all have + instead of -.

I don't get it.

In mathematics you get the normal of a plane by mean of the vector product of two lines that belong to the plane. In case on a triangle you can get the normal by a vector product of two edges.
But this code looks a little different to a vector product, but it is.
The guys of CG invented a method that produce better normals for polygons. The result will be the same as the classic method if all the vertices of a polygon are in the same plane, but this is not always true. This method produce the average of the normals with less computation.
In case of a triangle, all the vertices always are on the same plane, so both methods give exactly the same result.

For a triangle ABC what this code does is;
N = ABxAC + BCxBA + CAxCB  removing all the terms that cancels itself.

Stupidity also evolves!