git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@164 92aac97c-a6ce-11dd-a772-7fcde58d38e6
This commit is contained in:
parent
c0b4eaaccc
commit
0a058c266c
35
sources/reactphysics3d/mathematics/Polygon3D.cpp
Normal file
35
sources/reactphysics3d/mathematics/Polygon3D.cpp
Normal file
|
@ -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 <http://www.gnu.org/licenses/>. *
|
||||
***************************************************************************/
|
||||
|
||||
// Libraries
|
||||
#include "Polygon3D.h"
|
||||
|
||||
// We want to use the ReactPhysics3D namespace
|
||||
using namespace reactphysics3d;
|
||||
|
||||
// Constructor
|
||||
Polygon3D::Polygon3D(const std::vector<Vector3D>& vertexList)
|
||||
:vertexList(vertexList) {
|
||||
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Polygon3D::~Polygon3D() {
|
||||
|
||||
}
|
71
sources/reactphysics3d/mathematics/Polygon3D.h
Normal file
71
sources/reactphysics3d/mathematics/Polygon3D.h
Normal file
|
@ -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 <http://www.gnu.org/licenses/>. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef POLYGON3D_H
|
||||
#define POLYGON3D_H
|
||||
|
||||
// Libraries
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
#include "Vector3D.h"
|
||||
|
||||
// ReactPhysics3D namespace
|
||||
namespace reactphysics3d {
|
||||
|
||||
/* -------------------------------------------------------------------
|
||||
Class Polygon3D :
|
||||
This class represents a 3D polygon.
|
||||
-------------------------------------------------------------------
|
||||
*/
|
||||
class Polygon3D {
|
||||
private :
|
||||
std::vector<Vector3D> vertexList; // Ordered list of all vertices of the polygon
|
||||
|
||||
public :
|
||||
Polygon3D(const std::vector<Vector3D>& 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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user