MeshLODTri.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 
00022 // MeshLODTri.cpp: implementation of the MeshLODTri class.
00023 //
00024 //////////////////////////////////////////////////////////////////////
00025 
00026 #include <common/Defines.h>
00027 #include <3dsparse/MeshLODVector.h>
00028 #include <3dsparse/MeshLODTri.h>
00029 
00030 //////////////////////////////////////////////////////////////////////
00031 // Construction/Destruction
00032 //////////////////////////////////////////////////////////////////////
00033 
00034 MeshLODTri::MeshLODTri(MeshLODVector *v0,MeshLODVector *v1,MeshLODVector *v2)
00035 {
00036         vertex[0]=v0;
00037         vertex[1]=v1;
00038         vertex[2]=v2;
00039 
00040         //DIALOG_ASSERT(vertex[0]!=vertex[1] && vertex[0]!=vertex[2] && vertex[1]!=vertex[2]);
00041 
00042         for(int i=0;i<3;i++) 
00043         {
00044                 vertex[i]->face.push_back(this);
00045                 for(int j=0;j<3;j++)
00046                 {
00047                         vertex[i]->addNeighbour(vertex[j]);
00048                 }
00049         }
00050 
00051         computeNormal();
00052 }
00053 
00054 MeshLODTri::~MeshLODTri()
00055 {
00056         int i;
00057         for(i=0;i<3;i++) 
00058         {
00059                 vertex[i]->removeFace(this);
00060         }
00061 
00062         for(i=0;i<3;i++) 
00063         {
00064                 int i2 = (i+1)%3;
00065                 vertex[i ]->removeIfNonNeighbor(vertex[i2]);
00066                 vertex[i2]->removeIfNonNeighbor(vertex[i ]);
00067         }
00068 
00069         for (i=0;i<3;i++)
00070         {
00071                 vertex[i] = 0;
00072         }
00073 }
00074 
00075 void MeshLODTri::computeNormal()
00076 {
00077         normal = ((*vertex[1] - *vertex[0]) * (*vertex[2] - *vertex[1])).Normalize();
00078 }
00079 
00080 bool MeshLODTri::hasVertex(MeshLODVector *v)
00081 {
00082         return (v==vertex[0] || v==vertex[1] || v==vertex[2]);
00083 }
00084 
00085 void MeshLODTri::replaceVertex(MeshLODVector *vold, MeshLODVector *vnew) 
00086 {
00087         DIALOG_ASSERT(vold && vnew);
00088         DIALOG_ASSERT(vold==vertex[0] || vold==vertex[1] || vold==vertex[2]);
00089         //DIALOG_ASSERT(vnew!=vertex[0] && vnew!=vertex[1] && vnew!=vertex[2]);
00090 
00091         if(vold==vertex[0])
00092         {
00093                 vertex[0]=vnew;
00094         }
00095         else if(vold==vertex[1])
00096         {
00097                 vertex[1]=vnew;
00098         }
00099         else 
00100         {
00101                 DIALOG_ASSERT(vold==vertex[2]);
00102                 vertex[2]=vnew;
00103         }
00104 
00105         vold->removeFace(this);
00106         vnew->face.push_back(this);
00107 
00108         int i;
00109         for(i=0;i<3;i++) 
00110         {
00111                 vold->removeIfNonNeighbor(vertex[i]);
00112                 vertex[i]->removeIfNonNeighbor(vold);
00113         }
00114 
00115         for(i=0;i<3;i++) 
00116         {
00117                 for(int j=0;j<3;j++) 
00118                 {
00119                         vertex[i]->addNeighbour(vertex[j]);
00120                 }
00121         }
00122 
00123         computeNormal();
00124 }

Generated on Mon Feb 16 15:14:48 2009 for Scorched3D by  doxygen 1.5.3