[info-performer] Problem with normals and TRISTRIPS

Date view Thread view Subject view Author view

From: LE ROUX Olivier (olivier.le-roux++at++c-s.fr)
Date: 09/22/2005 09:29:20


hi,

I have a mesh (a TRISTRIP that looks like a plane) and I would like to
compute a "global" normal
for this mesh

Here's my code :

pfVec3 computeNormal(int pPrimType,
                     int pNumPrims,
                     pfVec3 *pVertice,
                     int *pPrimLength)
{
    pfVec3 lGlobalNormal(0.0f, 0.0f, 0.0f);

    pfVec3 lEdge1;
    pfVec3 lEdge2;
    pfVec3 lNormal;
    int lIndex = 0;

    switch(pPrimType)
    {
    //...
    case PFGS_TRISTRIPS:
    {
            for (int i=0; i<pNumPrims; i++)
            {
                for (int k=0; k<(pPrimLength[i]-2); k++)
                {
                    lEdge1 = pVertice[lIndex+k+1] - pVertice[lIndex+k];
                    lEdge2 = pVertice[lIndex+k+2] - pVertice[lIndex+k];

                    if (k%2==0) lNormal.cross(lEdge2, lEdge1);
                                lNormal.cross(lEdge1, lEdge2);

                   lNormal.normalize();
                   lGlobalNormal += lNormal;
                }
                lIndex += pPrimLength[i];
            }
    }
    break;

   } // end switch

  lGlobalNormal.normalize();
  return lGlobalNormal;
}

When I display individual "lNormal" to check the result, some normals seem
to be in the wrong way
=> my final result is wrong !

What's wrong in my code?

Thanks for help.

Olivier


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Thu Sep 22 2005 - 09:29:48 PDT