Mesh.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 #include <3dsparse/Mesh.h>
00022 #include <3dsparse/ModelStore.h>
00023 #include <3dsparse/MeshLOD.h>
00024 #include <common/Defines.h>
00025 
00026 Mesh::Mesh(const char *name) : name_(name),
00027         referencesBones_(false), sphereMap_(false)
00028 {
00029 }
00030 
00031 Mesh::~Mesh()
00032 {
00033         while (!faces_.empty())
00034         {
00035                 Face *face = faces_.back();
00036                 faces_.pop_back();
00037                 delete face;
00038         }
00039         while (!vertexes_.empty())
00040         {
00041                 Vertex *vertex = vertexes_.back();
00042                 vertexes_.pop_back();
00043                 delete vertex;
00044         }
00045 }
00046 
00047 void Mesh::insertVertex(Vertex &vertex)
00048 { 
00049         if (vertexes_.empty())
00050         {
00051                 max_ = vertex.position;
00052                 min_ = vertex.position;
00053         }
00054         else
00055         {
00056                 max_[0] = MAX(max_[0], vertex.position[0]);
00057                 max_[1] = MAX(max_[1], vertex.position[1]);
00058                 max_[2] = MAX(max_[2], vertex.position[2]);
00059 
00060                 min_[0] = MIN(min_[0], vertex.position[0]);
00061                 min_[1] = MIN(min_[1], vertex.position[1]);
00062                 min_[2] = MIN(min_[2], vertex.position[2]);
00063         }
00064 
00065         vertexes_.push_back(new Vertex(vertex)); 
00066 }
00067 
00068 void Mesh::move(Vector &movement)
00069 {
00070         std::vector<Vertex *>::iterator itor;
00071         for (itor = vertexes_.begin();
00072                 itor != vertexes_.end();
00073                 itor++)
00074         {
00075                 (*itor)->position += movement;
00076         }
00077         max_ += movement;
00078         min_ += movement;
00079 }
00080 
00081 void Mesh::setTextureName(const char *t)
00082 { 
00083         if (0 != strcmp(t, "none"))
00084         {
00085                 sphereMap_ = (strstr(t, "/sphere_") != 0);
00086                 textureName_ = t; 
00087         }
00088 }
00089 
00090 void Mesh::setupCollapse()
00091 {
00092         MeshLOD::progressiveMesh(vertexes_, faces_, collapseMap_);
00093 }

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