Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3075 in orxonox.OLD for orxonox


Ignore:
Timestamp:
Dec 4, 2004, 2:50:49 AM (20 years ago)
Author:
bensch
Message:

orxonox/trunk/importer: auto-Vertex-Normals implemented

Location:
orxonox/trunk/importer
Files:
2 edited

Legend:

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

    r3073 r3075  
    658658  vertices->finalizeArray();
    659659  vTexture->finalizeArray();
     660  if (normals->getCount() == 0) // vertices-Array must be uilt for this
     661    buildVertexNormals();
    660662  normals->finalizeArray();
    661663
     
    766768
    767769
     770bool Object::buildVertexNormals ()
     771{
     772
     773  Vector* normArray = new Vector [vertices->getCount()/3];
     774  for (int i=0; i<=vertices->getCount()/3;i++)
     775    normArray[i] = Vector(.0,.0,.0);
     776
     777  int firstTouch;
     778  int secondTouch;
     779  Vector prevV;
     780  Vector nextV;
     781  Vector curV;
     782
     783  Group* tmpGroup = firstGroup;
     784  while (tmpGroup)
     785    {
     786      Face* tmpFace = tmpGroup->firstFace;
     787      while (tmpFace)
     788        {
     789          if (tmpFace->firstElem)
     790            {
     791              FaceElement* firstElem = tmpFace->firstElem;
     792              FaceElement* prevElem = firstElem;
     793              FaceElement* curElem = prevElem->next;
     794             
     795              for (int j=1; j<tmpFace->vertexCount-1; j++)
     796                {
     797                  curElem->normalNumber = curElem->vertexNumber;
     798                 
     799                  curV = Vector (vertices->getArray()[curElem->vertexNumber*3], vertices->getArray()[curElem->vertexNumber*3+1], vertices->getArray()[curElem->vertexNumber*3+2]);
     800                  prevV = Vector (vertices->getArray()[prevElem->vertexNumber*3], vertices->getArray()[prevElem->vertexNumber*3+1], vertices->getArray()[prevElem->vertexNumber*3+2]) - curV;
     801                  nextV = Vector (vertices->getArray()[curElem->next->vertexNumber*3], vertices->getArray()[curElem->next->vertexNumber*3+1], vertices->getArray()[curElem->next->vertexNumber*3+2]) - curV;
     802                  normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + *(nextV.cross(prevV).getNormalized());
     803
     804                  // prevV.x, nextV.cross(prevV).x);
     805                 
     806                  prevElem = curElem;
     807                  curElem = curElem->next;
     808                }
     809              firstElem->normalNumber = firstElem->vertexNumber;
     810             
     811              curV = Vector (vertices->getArray()[firstElem->vertexNumber*3], vertices->getArray()[firstElem->vertexNumber*3+1], vertices->getArray()[firstElem->vertexNumber*3+2]);
     812              prevV = Vector (vertices->getArray()[prevElem->vertexNumber*3], vertices->getArray()[prevElem->vertexNumber*3+1], vertices->getArray()[prevElem->vertexNumber*3+2]) - curV;
     813              nextV = Vector (vertices->getArray()[firstElem->next->vertexNumber*3], vertices->getArray()[firstElem->next->vertexNumber*3+1], vertices->getArray()[firstElem->next->vertexNumber*3+2]) - curV;
     814              normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + *(prevV.cross(nextV).getNormalized());
     815             
     816            }
     817          tmpFace = tmpFace->next;
     818        }
     819      tmpGroup = tmpGroup->next;
     820    }
     821
     822  for (int i=0; i<vertices->getCount()/3;i++)
     823    {
     824      normArray[i].normalize();
     825      //      printf("%f, %f, %f.\n",normArray[i].x, normArray[i].y, normArray[i].z );
     826      normals->addEntry(normArray[i].x, normArray[i].y, normArray[i].z);
     827
     828    }
     829}
     830
     831
    768832/**
    769833   \brief Includes a default object
  • orxonox/trunk/importer/object.h

    r3072 r3075  
    1212#include "array.h"
    1313#include "material.h"
     14#include "vector.h"
    1415#include <fstream>
    1516
     
    112113  bool addGLElement (FaceElement* elem);
    113114
     115  bool buildVertexNormals ();
     116
    114117  void BoxObject (void);
    115118};
Note: See TracChangeset for help on using the changeset viewer.