Rework UI architecture and blendshape animation
[opengl.git] / model.cpp
index 0a1e3526c8297e20f19b24d8fc1082fd0afb5352..9e4cfc6ca026fb0e7e8ee6345acbdaf3bf90f98b 100644 (file)
--- a/model.cpp
+++ b/model.cpp
@@ -414,9 +414,9 @@ bool Model::Node::operator==(const Model::Node &rhs) const {
 
 // Returns closest vertex in world space and distance
 // a and b define the line in 3d space
-std::pair<glm::vec3, float> Model::closestVertex(Model::Node &n, glm::vec3 a, glm::vec3 b, glm::mat4 parentTrans) const {
-       float closestDist = FLT_MAX;
-       glm::vec3 closestVert;
+Model::VertexLookup Model::closestVertex(Model::Node &n, glm::vec3 a, glm::vec3 b, glm::mat4 parentTrans) const {
+       Model::VertexLookup closest;
+       closest.distance = FLT_MAX;
 
        for (int i = 0; i < n.ai.mNumMeshes; i++) {
                int meshIdx = n.ai.mMeshes[i];
@@ -433,20 +433,20 @@ std::pair<glm::vec3, float> Model::closestVertex(Model::Node &n, glm::vec3 a, gl
                        vPos = parentTrans * aiMatrixToMat4(n.ai.mTransformation) * vPos;
                        float dist = glm::distance(glm::vec3(vPos),
                                                        glm::closestPointOnLine(glm::vec3(vPos), a, b));
-                       if (dist < closestDist) {
-                               closestVert = glm::vec3(vPos);
-                               closestDist = dist;
+                       if (dist < closest.distance) {
+                               closest.pos = glm::vec3(vPos);
+                               closest.distance = dist;
+                               closest.meshIdx = i;
+                               closest.vertIdx = j;
                        }
                }
        }
        
        for (auto child: n.getChildren()) {
                auto childRes = closestVertex(*child, a, b, parentTrans * aiMatrixToMat4(n.ai.mTransformation));
-               if (childRes.second < closestDist) {
-                       closestVert = childRes.first;
-                       closestDist = childRes.second;
-               }
+               if (childRes.distance < closest.distance) 
+                       closest = childRes;
        }
 
-       return { closestVert, closestDist };
+       return closest;
 }