diff --git a/sources/reactphysics3d/mathematics/Polygon3D.cpp b/sources/reactphysics3d/mathematics/Polygon3D.cpp new file mode 100644 index 00000000..349ad3df --- /dev/null +++ b/sources/reactphysics3d/mathematics/Polygon3D.cpp @@ -0,0 +1,35 @@ +/**************************************************************************** +* Copyright (C) 2009 Daniel Chappuis * +**************************************************************************** +* This file is part of ReactPhysics3D. * +* * +* ReactPhysics3D is free software: you can redistribute it and/or modify * +* it under the terms of the GNU Lesser General Public License as published * +* by the Free Software Foundation, either version 3 of the License, or * +* (at your option) any later version. * +* * +* ReactPhysics3D is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU Lesser General Public License for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with ReactPhysics3D. If not, see . * +***************************************************************************/ + +// Libraries +#include "Polygon3D.h" + +// We want to use the ReactPhysics3D namespace +using namespace reactphysics3d; + +// Constructor +Polygon3D::Polygon3D(const std::vector& vertexList) + :vertexList(vertexList) { + +} + +// Destructor +Polygon3D::~Polygon3D() { + +} diff --git a/sources/reactphysics3d/mathematics/Polygon3D.h b/sources/reactphysics3d/mathematics/Polygon3D.h new file mode 100644 index 00000000..51ce9518 --- /dev/null +++ b/sources/reactphysics3d/mathematics/Polygon3D.h @@ -0,0 +1,71 @@ +/**************************************************************************** +* Copyright (C) 2009 Daniel Chappuis * +**************************************************************************** +* This file is part of ReactPhysics3D. * +* * +* ReactPhysics3D is free software: you can redistribute it and/or modify * +* it under the terms of the GNU Lesser General Public License as published * +* by the Free Software Foundation, either version 3 of the License, or * +* (at your option) any later version. * +* * +* ReactPhysics3D is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU Lesser General Public License for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with ReactPhysics3D. If not, see . * +***************************************************************************/ + +#ifndef POLYGON3D_H +#define POLYGON3D_H + +// Libraries +#include +#include +#include "Vector3D.h" + +// ReactPhysics3D namespace +namespace reactphysics3d { + +/* ------------------------------------------------------------------- + Class Polygon3D : + This class represents a 3D polygon. + ------------------------------------------------------------------- +*/ +class Polygon3D { + private : + std::vector vertexList; // Ordered list of all vertices of the polygon + + public : + Polygon3D(const std::vector& vertexList); // Constructor + ~Polygon3D(); // Destructor + + int getNbVertex() const; // Return the number of vertex of the polygon + Vector3D getVertex(unsigned int index) const throw(std::invalid_argument); // Return a vertex of the polygon +}; + +// TODO : Test the Polygon3D class + +// Return the number of vertex of the polygon +inline int Polygon3D::getNbVertex() const { + return vertexList.size(); +} + +// Return a vertex of the polygon +inline Vector3D Polygon3D::getVertex(unsigned int index) const throw(std::invalid_argument) { + // Check if the index argument is valid + if (index >= 0 && index < vertexList.size()) { + return vertexList[index]; + } + else { + // The index is invalid, we throw an exception + throw std::invalid_argument("Exception : The index argument has to be between zero and the number of vertex of the polygon"); + } +} + +} // End of the ReactPhysics3D + +#endif + +