john-chapman / im3d

Immediate mode rendering and 3d gizmos.
MIT License
1.21k stars 63 forks source link

Deal with transformed world coordinates. #56

Closed saedrna closed 2 years ago

saedrna commented 2 years ago

Currently, my scene has already been translated, scaled, and rotated and I want to place a gizmo in such a scene. For example, if my scene is a bounding box of size 2000, I already translate (1000, 1000, 1000) and scale (0.001, 0.001, 0.001) to the scene (get the model matrix), and view the scene from (0, 0, 5) to (0, 0, 0) (get the view matrix) with a perspective camera (get the 'proj' matrix).

How do I fill the AppData correctly? I can already calculate the camera position and direction and cursor origin and direction in world space. How can I place a gizmo at the location of the original (1100, 1100, 1100) coordinate? Thanks!

saedrna commented 2 years ago

I answered the question myself. Just do the following.

  1. fill the AppData with coordinates in the world space.
  2. Put the gizmo at the transformation like Im3d::Gizmo("Gizmo", xform) with xform = translate(1100, 1100, 1100).
  3. Draw the vertexData with 'uViewProjMatrix' set to the MVP matrix as proj x view x model.