Changeset 3075 in orxonox.OLD for orxonox/trunk/importer
- Timestamp:
- Dec 4, 2004, 2:50:49 AM (20 years ago)
- Location:
- orxonox/trunk/importer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/importer/object.cc
r3073 r3075 658 658 vertices->finalizeArray(); 659 659 vTexture->finalizeArray(); 660 if (normals->getCount() == 0) // vertices-Array must be uilt for this 661 buildVertexNormals(); 660 662 normals->finalizeArray(); 661 663 … … 766 768 767 769 770 bool 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 768 832 /** 769 833 \brief Includes a default object -
orxonox/trunk/importer/object.h
r3072 r3075 12 12 #include "array.h" 13 13 #include "material.h" 14 #include "vector.h" 14 15 #include <fstream> 15 16 … … 112 113 bool addGLElement (FaceElement* elem); 113 114 115 bool buildVertexNormals (); 116 114 117 void BoxObject (void); 115 118 };
Note: See TracChangeset
for help on using the changeset viewer.