git-svn-id: https://scorched3d.svn.sourceforge.net/svnroot/scorched3d/trunk/scorched...
[scorched3d/parasti.git] / src / common / 3dsparse / MeshLODTri.cpp
blobd263cbc4d44531019effb82757bbab6e0ced7a38
1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
3 //
4 // This file is part of Scorched3D.
5 //
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
22 // MeshLODTri.cpp: implementation of the MeshLODTri class.
24 //////////////////////////////////////////////////////////////////////
26 #include <common/Defines.h>
27 #include <3dsparse/MeshLODVector.h>
28 #include <3dsparse/MeshLODTri.h>
30 //////////////////////////////////////////////////////////////////////
31 // Construction/Destruction
32 //////////////////////////////////////////////////////////////////////
34 MeshLODTri::MeshLODTri(MeshLODVector *v0,MeshLODVector *v1,MeshLODVector *v2)
36 vertex[0]=v0;
37 vertex[1]=v1;
38 vertex[2]=v2;
40 //DIALOG_ASSERT(vertex[0]!=vertex[1] && vertex[0]!=vertex[2] && vertex[1]!=vertex[2]);
42 for(int i=0;i<3;i++)
44 vertex[i]->face.push_back(this);
45 for(int j=0;j<3;j++)
47 vertex[i]->addNeighbour(vertex[j]);
51 computeNormal();
54 MeshLODTri::~MeshLODTri()
56 int i;
57 for(i=0;i<3;i++)
59 vertex[i]->removeFace(this);
62 for(i=0;i<3;i++)
64 int i2 = (i+1)%3;
65 vertex[i ]->removeIfNonNeighbor(vertex[i2]);
66 vertex[i2]->removeIfNonNeighbor(vertex[i ]);
69 for (i=0;i<3;i++)
71 vertex[i] = 0;
75 void MeshLODTri::computeNormal()
77 normal = ((*vertex[1] - *vertex[0]) * (*vertex[2] - *vertex[1])).Normalize();
80 bool MeshLODTri::hasVertex(MeshLODVector *v)
82 return (v==vertex[0] || v==vertex[1] || v==vertex[2]);
85 void MeshLODTri::replaceVertex(MeshLODVector *vold, MeshLODVector *vnew)
87 DIALOG_ASSERT(vold && vnew);
88 DIALOG_ASSERT(vold==vertex[0] || vold==vertex[1] || vold==vertex[2]);
89 //DIALOG_ASSERT(vnew!=vertex[0] && vnew!=vertex[1] && vnew!=vertex[2]);
91 if(vold==vertex[0])
93 vertex[0]=vnew;
95 else if(vold==vertex[1])
97 vertex[1]=vnew;
99 else
101 DIALOG_ASSERT(vold==vertex[2]);
102 vertex[2]=vnew;
105 vold->removeFace(this);
106 vnew->face.push_back(this);
108 int i;
109 for(i=0;i<3;i++)
111 vold->removeIfNonNeighbor(vertex[i]);
112 vertex[i]->removeIfNonNeighbor(vold);
115 for(i=0;i<3;i++)
117 for(int j=0;j<3;j++)
119 vertex[i]->addNeighbour(vertex[j]);
123 computeNormal();