diff --git a/Code/include/Animation/AnimatedMesh.hpp b/Code/include/Animation/AnimatedMesh.hpp index 41dc4c5..039c8ab 100644 --- a/Code/include/Animation/AnimatedMesh.hpp +++ b/Code/include/Animation/AnimatedMesh.hpp @@ -32,7 +32,7 @@ class AnimatedMesh /// \return the associated segment for each point /// ///////////////////////////////////////////////////////////////////// - void associateBranches(std::vector> segments, geo::Mesh& mesh); + void associateBranches(std::vector> const& segments, geo::Mesh& mesh); ////////////////////////////////////////////////////////////////////// /// @@ -44,7 +44,7 @@ class AnimatedMesh /// \return nearest segment index /// ////////////////////////////////////////////////////////////////////// - unsigned int findNearestSegment(std::vector> segments, geo::Point p); + unsigned int findNearestSegment(std::vector> const& segments, geo::Point const& p); ////////////////////////////////////////////////////////////////////// /// @@ -57,7 +57,7 @@ class AnimatedMesh /// \return faces associated to each segment /// ////////////////////////////////////////////////////////////////////// - void findFaces(std::vector associatedSegments, geo::Mesh& mesh, unsigned int nbSegments); + void findFaces(std::vector const& associatedSegments, geo::Mesh& mesh, unsigned int nbSegments); std::vector> vertices; ///< Vertices of the mesh diff --git a/Code/include/Geometry/MathFunctions.inl b/Code/include/Geometry/MathFunctions.inl index f830c04..05b6727 100644 --- a/Code/include/Geometry/MathFunctions.inl +++ b/Code/include/Geometry/MathFunctions.inl @@ -150,9 +150,9 @@ struct distance_to_segment_helper auto scal2 = x12 * x2v + y12 * y2v + z12 * z2v; auto norm12 = x12 * x12 + y12 * y12 + z12 * z12; - auto xH = get_x(p1) + scal1 / norm12 * x12; - auto yH = get_y(p1) + scal1 / norm12 * y12; - auto zH = get_z(p1) + scal1 / norm12 * z12; + auto xH = get_x(p1) + (scal1 / norm12) * x12; + auto yH = get_y(p1) + (scal1 / norm12) * y12; + auto zH = get_z(p1) + (scal1 / norm12) * z12; float dist; @@ -163,7 +163,7 @@ struct distance_to_segment_helper else { dist = std::min( (get_x(v)-get_x(p1))*(get_x(v)-get_x(p1)) + (get_y(v)-get_y(p1))*(get_y(v)-get_y(p1)) + (get_z(v)-get_z(p1))*(get_z(v)-get_z(p1)), - (get_x(v)-get_x(p2))*(get_x(v)-get_x(p2)) + (get_y(v)-get_y(p2))*(get_y(v)-get_y(p2)) + (get_z(v)-get_z(p2))*(get_z(v)-get_z(p2))); + (get_x(v)-get_x(p2))*(get_x(v)-get_x(p2)) + (get_y(v)-get_y(p2))*(get_y(v)-get_y(p2)) + (get_z(v)-get_z(p2))*(get_z(v)-get_z(p2))); } return dist; diff --git a/Code/src/Animation/AnimatedMain.cpp b/Code/src/Animation/AnimatedMain.cpp index 553e5d2..e1eccf9 100644 --- a/Code/src/Animation/AnimatedMain.cpp +++ b/Code/src/Animation/AnimatedMain.cpp @@ -23,6 +23,8 @@ void drawScene(sft::FreeFlyCamera const& camera, pae::AnimatedMesh const& mesh); int main(int argc, char *argv[]) { + std::srand(std::time(nullptr)); + // Init mesh pae::Skeleton3D, float> skeleton; diff --git a/Code/src/Animation/AnimatedMesh.cpp b/Code/src/Animation/AnimatedMesh.cpp index 0bf6fe5..4baf46e 100644 --- a/Code/src/Animation/AnimatedMesh.cpp +++ b/Code/src/Animation/AnimatedMesh.cpp @@ -12,6 +12,9 @@ AnimatedMesh::AnimatedMesh(Skeleton3D,float> const& skeleton findFaces(associatedSegment, mesh, segments.size()); vertices = mesh.vertices; + for (auto const& s : segments) + std::cout << s.first << "\n" << s.second << std::endl << std::endl; + for (unsigned int i = 0; i < facesPerSegment.size()-1; i++) { colors.push_back({static_cast(std::rand())/RAND_MAX, @@ -20,7 +23,7 @@ AnimatedMesh::AnimatedMesh(Skeleton3D,float> const& skeleton } } -void AnimatedMesh::associateBranches(std::vector> segments, geo::Mesh& mesh) +void AnimatedMesh::associateBranches(std::vector> const& segments, geo::Mesh& mesh) { // stock each point at the index corresponding to the nearest segment for(unsigned int i=0;i> segments } //finds the nearest segment to a point -unsigned int AnimatedMesh::findNearestSegment(std::vector> segments, geo::Point p) +unsigned int AnimatedMesh::findNearestSegment(std::vector> const& segments, geo::Point const& p) { unsigned int nearestSegment = 0; - float shortest_distance; - float distance; + float shortest_distance = std::numeric_limits::max(); for(unsigned int i=0;i distance) { shortest_distance = distance; @@ -49,7 +51,7 @@ unsigned int AnimatedMesh::findNearestSegment(std::vector return nearestSegment; } -void AnimatedMesh::findFaces(std::vector associatedSegments, geo::Mesh& mesh, unsigned int nbSegments) +void AnimatedMesh::findFaces(std::vector const& associatedSegments, geo::Mesh& mesh, unsigned int nbSegments) { for (unsigned int i=0;i associatedSegments, geo: for(unsigned int i=0;i