Changeset View
Changeset View
Standalone View
Standalone View
extern/bullet2/src/LinearMath/btConvexHullComputer.h
| Show All 17 Lines | |||||
| #include "btVector3.h" | #include "btVector3.h" | ||||
| #include "btAlignedObjectArray.h" | #include "btAlignedObjectArray.h" | ||||
| /// Convex hull implementation based on Preparata and Hong | /// Convex hull implementation based on Preparata and Hong | ||||
| /// See http://code.google.com/p/bullet/issues/detail?id=275 | /// See http://code.google.com/p/bullet/issues/detail?id=275 | ||||
| /// Ole Kniemeyer, MAXON Computer GmbH | /// Ole Kniemeyer, MAXON Computer GmbH | ||||
| class btConvexHullComputer | class btConvexHullComputer | ||||
| { | { | ||||
| private: | private: | ||||
| btScalar compute(const void* coords, bool doubleCoords, int stride, int count, btScalar shrink, btScalar shrinkClamp); | btScalar compute(const void* coords, bool doubleCoords, int stride, int count, btScalar shrink, btScalar shrinkClamp); | ||||
| public: | public: | ||||
| class Edge | class Edge | ||||
| { | { | ||||
| private: | private: | ||||
| int next; | int next; | ||||
| int reverse; | int reverse; | ||||
| int targetVertex; | int targetVertex; | ||||
| friend class btConvexHullComputer; | friend class btConvexHullComputer; | ||||
| public: | public: | ||||
| int getSourceVertex() const | int getSourceVertex() const | ||||
| { | { | ||||
| return (this + reverse)->targetVertex; | return (this + reverse)->targetVertex; | ||||
| } | } | ||||
| int getTargetVertex() const | int getTargetVertex() const | ||||
| { | { | ||||
| return targetVertex; | return targetVertex; | ||||
| } | } | ||||
| const Edge* getNextEdgeOfVertex() const // clockwise list of all edges of a vertex | const Edge* getNextEdgeOfVertex() const // clockwise list of all edges of a vertex | ||||
| { | { | ||||
| return this + next; | return this + next; | ||||
| } | } | ||||
| const Edge* getNextEdgeOfFace() const // counter-clockwise list of all edges of a face | const Edge* getNextEdgeOfFace() const // counter-clockwise list of all edges of a face | ||||
| { | { | ||||
| return (this + reverse)->getNextEdgeOfVertex(); | return (this + reverse)->getNextEdgeOfVertex(); | ||||
| } | } | ||||
| const Edge* getReverseEdge() const | const Edge* getReverseEdge() const | ||||
| { | { | ||||
| return this + reverse; | return this + reverse; | ||||
| } | } | ||||
| }; | }; | ||||
| // Vertices of the output hull | // Vertices of the output hull | ||||
| btAlignedObjectArray<btVector3> vertices; | btAlignedObjectArray<btVector3> vertices; | ||||
| // The original vertex index in the input coords array | |||||
| btAlignedObjectArray<int> original_vertex_index; | btAlignedObjectArray<int> original_vertex_index; | ||||
| // Edges of the output hull | // Edges of the output hull | ||||
| btAlignedObjectArray<Edge> edges; | btAlignedObjectArray<Edge> edges; | ||||
| // Faces of the convex hull. Each entry is an index into the "edges" array pointing to an edge of the face. Faces are planar n-gons | // Faces of the convex hull. Each entry is an index into the "edges" array pointing to an edge of the face. Faces are planar n-gons | ||||
| btAlignedObjectArray<int> faces; | btAlignedObjectArray<int> faces; | ||||
| /* | /* | ||||
| Compute convex hull of "count" vertices stored in "coords". "stride" is the difference in bytes | Compute convex hull of "count" vertices stored in "coords". "stride" is the difference in bytes | ||||
| between the addresses of consecutive vertices. If "shrink" is positive, the convex hull is shrunken | between the addresses of consecutive vertices. If "shrink" is positive, the convex hull is shrunken | ||||
| by that amount (each face is moved by "shrink" length units towards the center along its normal). | by that amount (each face is moved by "shrink" length units towards the center along its normal). | ||||
| If "shrinkClamp" is positive, "shrink" is clamped to not exceed "shrinkClamp * innerRadius", where "innerRadius" | If "shrinkClamp" is positive, "shrink" is clamped to not exceed "shrinkClamp * innerRadius", where "innerRadius" | ||||
| is the minimum distance of a face to the center of the convex hull. | is the minimum distance of a face to the center of the convex hull. | ||||
| The returned value is the amount by which the hull has been shrunken. If it is negative, the amount was so large | The returned value is the amount by which the hull has been shrunken. If it is negative, the amount was so large | ||||
| that the resulting convex hull is empty. | that the resulting convex hull is empty. | ||||
| The output convex hull can be found in the member variables "vertices", "edges", "faces". | The output convex hull can be found in the member variables "vertices", "edges", "faces". | ||||
| */ | */ | ||||
| btScalar compute(const float* coords, int stride, int count, btScalar shrink, btScalar shrinkClamp) | btScalar compute(const float* coords, int stride, int count, btScalar shrink, btScalar shrinkClamp) | ||||
| { | { | ||||
| return compute(coords, false, stride, count, shrink, shrinkClamp); | return compute(coords, false, stride, count, shrink, shrinkClamp); | ||||
| } | } | ||||
| // same as above, but double precision | // same as above, but double precision | ||||
| btScalar compute(const double* coords, int stride, int count, btScalar shrink, btScalar shrinkClamp) | btScalar compute(const double* coords, int stride, int count, btScalar shrink, btScalar shrinkClamp) | ||||
| { | { | ||||
| return compute(coords, true, stride, count, shrink, shrinkClamp); | return compute(coords, true, stride, count, shrink, shrinkClamp); | ||||
| } | } | ||||
| }; | }; | ||||
| #endif //BT_CONVEX_HULL_COMPUTER_H | #endif //BT_CONVEX_HULL_COMPUTER_H | ||||