Adding a shader which renders a cone for visualizing rotation



I would like to add a shader to mrview which displays a cone(ish) object to visualize rotation. I read about OpenGL shaders and found the code for the crosshair rendering.

What is the appropriate location to add an additional shader. This functionality should reside in it’s own Tool which already has been added (Thanks again @jdtournier). Can I just add a method similar to render_crosshairs inside the tool source file and call it from draw?

Best Regards,


Hi @Darius,

That depends on exactly what you want to achieve, but in principle, yes. Bear in mind that tools (typically) get rendered one after the other in the order they appear in the menu, and the crosshairs and orientation labels are rendered immediately after that. So as long as what you’re trying to render doesn’t interfere with tools that would be rendered subsequently, you’d be fine.

The main thing to get right will be placement on the screen, when presumably your object will be defined relative to the scanner axes (as most primitives are in mrview, other than the text, crosshairs, colourbars, etc). For instance, you’ll probably want to show this cone in scanner coordinates (so it aligns with the geometry shown on screen), but positioned at some fixed location relative to the viewport. This where the Projection::model_to_screen() and Projection::screen_to_model() methods can come in handy.

Happy to help further if required – just let me know. :+1:

Good luck!

1 Like

Hey @jdtournier,

thanks for your reply. Do I need to have a similar calculation for the rotation and is there already a function for this?


It depends on exactly what you want to display here… What ‘rotation’ are you talking about? In general, the Projection::modelview_*() methods give you access to the current transformation, in a format directly usable in your shader. So if your rotation is that of the current viewport, then you can just render in that frame directly. If on the other hand you need to display the rotation of some other object, then you’d need to modify that transformation (or your vertices) accordingly. Hope that makes sense…?

1 Like