john-chapman / im3d

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

Question: How to draw multiple shapes in different locations? #44

Closed Ravbug closed 4 years ago

Ravbug commented 4 years ago

I'm confused about how to draw primitives in different locations. If I run the following code:

Im3d::PushMatrix(/* a valid non-identity matrix here*/);
Im3d::DrawCylinder(Im3d::Vec3(0,0,0), Im3d::Vec3(0,height,0), radius);
Im3d::PopMatrix();

Im3d::PushMatrix(/* a different valid non-identity matrix here*/);
Im3d::DrawSphere(Im3d::Vec3(0,0,0), radius);
Im3d::PopMatrix();

The resulting primitive's vertices in the draw callback are always exactly the same, regardless of the matrix I pass in. What is the correct way to transform a primitive so that its vertices are transformed? I can of course pass a different matrix directly into the shader, but this translates all of the shapes I draw, and not each one individually.

john-chapman commented 4 years ago

Hi - the code you've shown is correct and should work. I suspect there might be an issue with your transforms, possibly there is an error in the conversion between your application matrix type and Im3d::Mat4. Note that by default Im3d uses a column major internal matrix layout unless you define IM3D_MATRIX_ROW_MAJOR 1 (see im3d_config.h).

Ravbug commented 4 years ago

Transposing to column-major fixed it, thank you!