Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3081 in orxonox.OLD for orxonox/trunk


Ignore:
Timestamp:
Dec 4, 2004, 11:05:15 AM (20 years ago)
Author:
bensch
Message:

orxonox/trunk/importer: better algoritym for normals-calculation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/importer/object.cc

    r3080 r3081  
    777777bool Object::buildVertexNormals ()
    778778{
     779 
    779780  if (verbose >=2)
    780781    printf("Normals are being calculated.\n");
     
    783784  for (int i=0; i<vertices->getCount()/3;i++)
    784785    normArray[i] = Vector(.0,.0,.0);
    785 
     786 
    786787  int firstTouch;
    787788  int secondTouch;
     
    801802              FaceElement* prevElem = firstElem;
    802803              FaceElement* curElem = prevElem->next;
     804              FaceElement* lastElem;
     805              // close the Chain. !! IMPORTANT:the last Element of the Chain must point to NULL, or it will resolv into an infinity-loop.
     806              while (curElem)
     807                {
     808                  prevElem = curElem;
     809                  curElem = curElem->next;
     810                }
     811              lastElem = prevElem;
     812              prevElem->next = firstElem;
    803813             
    804               for (int j=1; j<tmpFace->vertexCount-1; j++)
     814              curElem = firstElem;
     815              for (int j=0; j<tmpFace->vertexCount; j++)
    805816                {
    806817                  curElem->normalNumber = curElem->vertexNumber;
     
    809820                  prevV = Vector (vertices->getArray()[prevElem->vertexNumber*3], vertices->getArray()[prevElem->vertexNumber*3+1], vertices->getArray()[prevElem->vertexNumber*3+2]) - curV;
    810821                  nextV = Vector (vertices->getArray()[curElem->next->vertexNumber*3], vertices->getArray()[curElem->next->vertexNumber*3+1], vertices->getArray()[curElem->next->vertexNumber*3+2]) - curV;
    811                   normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + *(nextV.cross(prevV).getNormalized());
    812 
    813                   // prevV.x, nextV.cross(prevV).x);
    814                  
     822                  normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + nextV.cross(prevV);
     823
     824                  if (curElem == firstElem )
     825                    printf ("schnitt, %d\n", j);
    815826                  prevElem = curElem;
    816827                  curElem = curElem->next;
    817828                }
    818               firstElem->normalNumber = firstElem->vertexNumber;
    819              
    820               curV = Vector (vertices->getArray()[firstElem->vertexNumber*3], vertices->getArray()[firstElem->vertexNumber*3+1], vertices->getArray()[firstElem->vertexNumber*3+2]);
    821               prevV = Vector (vertices->getArray()[prevElem->vertexNumber*3], vertices->getArray()[prevElem->vertexNumber*3+1], vertices->getArray()[prevElem->vertexNumber*3+2]) - curV;
    822               nextV = Vector (vertices->getArray()[firstElem->next->vertexNumber*3], vertices->getArray()[firstElem->next->vertexNumber*3+1], vertices->getArray()[firstElem->next->vertexNumber*3+2]) - curV;
    823               normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + *(nextV.cross(prevV).getNormalized());
    824              
     829              // reopening the Chain again.
     830              lastElem->next = NULL;
    825831            }
    826832          tmpFace = tmpFace->next;
     
    839845    }
    840846  delete []normArray;
     847 
    841848}
    842849
     
    871878  readVertexTexture ("-1.000000 0.000000");
    872879  readVertexTexture ("-1.000000 1.000000");
    873  
     880
     881  /* 
    874882  readVertexNormal ("0.000000 0.000000 1.000000");
    875883  readVertexNormal ("0.000000 0.000000 1.000000");
     
    896904  readVertexNormal ("-1.000000 0.000000 0.000000");
    897905  readVertexNormal ("-1.000000 0.000000 0.000000");
    898 
     906  */
     907
     908  readFace ("1 2 4 3");
     909  readFace ("3 4 6 5");
     910  readFace ("5 6 8 7");
     911  readFace ("7 8 2 1");
     912  readFace ("2 8 6 4");
     913  readFace ("7 1 3 5");
     914
     915  /*
    899916  readFace ("1/1/1 2/2/2 4/4/3 3/3/4");
    900917  readFace ("3/3/5 4/4/6 6/6/7 5/5/8");
     
    903920  readFace ("2/2/17 8/11/18 6/12/19 4/4/20");
    904921  readFace ("7/13/21 1/1/22 3/3/23 5/14/24");
    905 }
     922  */
     923}
Note: See TracChangeset for help on using the changeset viewer.