- Use the mVariable syntax for member variables - Every lines contain at most 100 characters - Add private copy-constructor and assignment operators when needed
145 lines
4.7 KiB
C++
145 lines
4.7 KiB
C++
/********************************************************************************
|
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/ *
|
|
* Copyright (c) 2010-2012 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. *
|
|
* *
|
|
********************************************************************************/
|
|
|
|
#ifndef TRIANGLES_STORE_H
|
|
#define TRIANGLES_STORE_H
|
|
|
|
#include "TriangleEPA.h"
|
|
|
|
|
|
// Libraries
|
|
#include <cassert>
|
|
|
|
// ReactPhysics3D namespace
|
|
namespace reactphysics3d {
|
|
|
|
// Constants
|
|
const unsigned int MAX_TRIANGLES = 200; // Maximum number of triangles
|
|
|
|
|
|
/* -------------------------------------------------------------------
|
|
Class TrianglesStore :
|
|
This class stores several triangles of the polytope in the EPA
|
|
algorithm.
|
|
-------------------------------------------------------------------
|
|
*/
|
|
class TrianglesStore {
|
|
|
|
private:
|
|
|
|
// -------------------- Attributes -------------------- //
|
|
|
|
// Triangles
|
|
TriangleEPA mTriangles[MAX_TRIANGLES];
|
|
|
|
// Number of triangles
|
|
int mNbTriangles;
|
|
|
|
// -------------------- Methods -------------------- //
|
|
|
|
// Private copy-constructor
|
|
TrianglesStore(const TrianglesStore& triangleStore);
|
|
|
|
// Private assignment operator
|
|
TrianglesStore& operator=(const TrianglesStore& triangleStore);
|
|
|
|
public:
|
|
|
|
// -------------------- Methods -------------------- //
|
|
|
|
// Constructor
|
|
TrianglesStore();
|
|
|
|
// Destructor
|
|
~TrianglesStore();
|
|
|
|
// Clear all the storage
|
|
void clear();
|
|
|
|
// Return the number of triangles
|
|
int getNbTriangles() const;
|
|
|
|
// Set the number of triangles
|
|
void setNbTriangles(int backup);
|
|
|
|
// Return the last triangle
|
|
TriangleEPA& last();
|
|
|
|
// Create a new triangle
|
|
TriangleEPA* newTriangle(const Vector3* vertices, uint v0, uint v1, uint v2);
|
|
|
|
// Access operator
|
|
TriangleEPA& operator[](int i);
|
|
};
|
|
|
|
// Clear all the storage
|
|
inline void TrianglesStore::clear() {
|
|
mNbTriangles = 0;
|
|
}
|
|
|
|
// Return the number of triangles
|
|
inline int TrianglesStore::getNbTriangles() const {
|
|
return mNbTriangles;
|
|
}
|
|
|
|
|
|
inline void TrianglesStore::setNbTriangles(int backup) {
|
|
mNbTriangles = backup;
|
|
}
|
|
|
|
// Return the last triangle
|
|
inline TriangleEPA& TrianglesStore::last() {
|
|
assert(mNbTriangles > 0);
|
|
return mTriangles[mNbTriangles - 1];
|
|
}
|
|
|
|
// Create a new triangle
|
|
inline TriangleEPA* TrianglesStore::newTriangle(const Vector3* vertices,
|
|
uint v0,uint v1, uint v2) {
|
|
TriangleEPA* newTriangle = 0;
|
|
|
|
// If we have not reached the maximum number of triangles
|
|
if (mNbTriangles != MAX_TRIANGLES) {
|
|
newTriangle = &mTriangles[mNbTriangles++];
|
|
new (newTriangle) TriangleEPA(v0, v1, v2);
|
|
if (!newTriangle->computeClosestPoint(vertices)) {
|
|
mNbTriangles--;
|
|
newTriangle = 0;
|
|
}
|
|
}
|
|
|
|
// Return the new triangle
|
|
return newTriangle;
|
|
}
|
|
|
|
// Access operator
|
|
inline TriangleEPA& TrianglesStore::operator[](int i) {
|
|
return mTriangles[i];
|
|
}
|
|
|
|
} // End of ReactPhysics3D namespace
|
|
|
|
#endif
|