Skip to content

Commit

Permalink
[#27] QHull DOD refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ilia-glushchenko committed Nov 1, 2018
1 parent 640b830 commit 47dbe6c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
17 changes: 17 additions & 0 deletions Epona/include/Epona/QuickhullConvexHull.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@

namespace epona
{
struct ConvexHull
{
HalfEdgeDataStructure heds;
std::vector<glm::uvec3> faces;
std::vector<uint32_t> vertices;
};

inline ConvexHull CalculateConvexHull(std::vector<glm::vec3> const& vertices)
{
return {};
}

inline bool InsertVertexConvexHull(ConvexHull& qhull, std::vector<glm::vec3> const& vertices, uint32_t index)
{
return false;
}

/**
* @brief Quickhull convex hull calculation algorithm
* @tparam VerticesType STL compatible random access glm::vec3 container
Expand Down
16 changes: 12 additions & 4 deletions Epona/sources/Analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* This code is licensed under the MIT license (MIT)
* (http://opensource.org/licenses/MIT)
*/
#include <Epona/FloatingPoint.hpp>
#include <Epona/Analysis.hpp>
#include <glm/glm.hpp>

Expand All @@ -29,10 +30,17 @@ glm::vec3 epona::CalculateBarycentricCoordinates(glm::vec3 p, glm::vec3 a, glm::
float const d21 = glm::dot(v2, v1);
float const denominator = d00 * d11 - d01 * d01;

glm::vec3 coordinates;
coordinates.y = (d11 * d20 - d01 * d21) / denominator;
coordinates.z = (d00 * d21 - d01 * d20) / denominator;
coordinates.x = 1.0f - coordinates.y - coordinates.z;
glm::vec3 coordinates{ 1, 0, 0 };

if (!fp::IsZero(denominator))
{
coordinates.y = (d11 * d20 - d01 * d21) / denominator;
coordinates.z = (d00 * d21 - d01 * d20) / denominator;
coordinates.x = 1.0f - coordinates.y - coordinates.z;
}

assert(!isnan(coordinates.x) && !isnan(coordinates.y) && !isnan(coordinates.z));
assert(!isinf(coordinates.x) && !isinf(coordinates.y) && !isinf(coordinates.z));

return coordinates;
}

0 comments on commit 47dbe6c

Please sign in to comment.