I'm trying to draw a small sphere mesh (mesh A) at an arbitary vertex position based on another mesh (mesh B) to visualize where a specific vertex is. I'm using OpenGl and GLM, but I think it's a math issue so it should probably be independant from any framework.
My approach is the following:
- Draw mesh B
- Fetch a vertex position in local space from mesh B, vertexPos.
- Create a matrix with translation, rotation and scaling based on mesh B, mat.
- Convert the vertex position to worldspace using the matrix, mat, created in step 3:
auto pos = glm::vec3(mat * glm::vec4(vertexPos, 1)); - Create a new matrix for drawing mesh A, using pos from step 4 as the translation:
auto modelA = glm::mat4(1.0f);
modelA = glm::translate(modelA, pos);
This seems to work partially but translations from mesh B is not picked up properly, only rotations.
I guess I have mixed up some math here, can anyone please guide me if I'm thinking totally wrong or if I have missed something relevant?
Thanks in advance.