/******************************************************************************** * OpenGL-Framework * * Copyright (c) 2013 Daniel Chappuis * ********************************************************************************* * * * This software is provided 'as-is', without any express or implied warranty. * * In no event will the authors be held liable for any damages arising from the * * use of this software. * * * * Permission is granted to anyone to use this software for any purpose, * * including commercial applications, and to alter it and redistribute it * * freely, subject to the following restrictions: * * * * 1. The origin of this software must not be misrepresented; you must not claim * * that you wrote the original software. If you use this software in a * * product, an acknowledgment in the product documentation would be * * appreciated but is not required. * * * * 2. Altered source versions must be plainly marked as such, and must not be * * misrepresented as being the original software. * * * * 3. This notice may not be removed or altered from any source distribution. * * * ********************************************************************************/ // Libraries #include "Mesh.h" // Namespaces using namespace openglframework; using namespace std; // Constructor Mesh::Mesh() { } // Destructor Mesh::~Mesh() { } // Destroy the mesh void Mesh::destroy() { mVertices.clear(); mNormals.clear(); mTangents.clear(); mIndices.clear(); mColors.clear(); mUVs.clear(); mTextures.clear(); } // Compute the normals of the mesh void Mesh::calculateNormals() { mNormals = vector(getNbVertices(), Vector3(0, 0, 0)); // For each triangular face for (uint i=0; i(getNbVertices(), Vector3(0, 0, 0)); // For each face for (uint i=0; i::const_iterator it(mVertices.begin()); // For each vertex of the mesh for (; it != mVertices.end(); ++it) { if( (*it).x < min.x ) min.x = (*it).x; else if ( (*it).x > max.x ) max.x = (*it).x; if( (*it).y < min.y ) min.y = (*it).y; else if ( (*it).y > max.y ) max.y = (*it).y; if( (*it).z < min.z ) min.z = (*it).z; else if ( (*it).z > max.z ) max.z = (*it).z; } } else { std::cerr << "Error : Impossible to calculate the bounding box of the mesh because there" << "are no vertices !" << std::endl; assert(false); } } // Scale of vertices of the mesh using a given factor void Mesh::scaleVertices(float factor) { // For each vertex for (uint i=0; i