🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Using worldspace vertex position as translation for another mesh

Started by
2 comments, last by Programmer71 2 years, 3 months ago

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:

  1. Draw mesh B
  2. Fetch a vertex position in local space from mesh B, vertexPos.
  3. Create a matrix with translation, rotation and scaling based on mesh B, mat.
  4. Convert the vertex position to worldspace using the matrix, mat, created in step 3:
    auto pos = glm::vec3(mat * glm::vec4(vertexPos, 1));
  5. 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.

Advertisement

I resolved this my multiplying the model matrix form mesh B with the model matrix from mesh A, where the translation for mesh A ix based on vertexPos.

I think you could save several cycles because of matrix copies multipling directly the matrix B with the A , from what i have heard glm isn't that performant

This topic is closed to new replies.

Advertisement