Make something face the screen? Yes, this is exactly what the osg::Billboard
class has done for you, and the osgText::Text
class has a similar feature that rotates the text to screen automatically. But this time we will work on a node, and show how to alter transformation nodes according to the global model-view matrix. The method used here can also be extended to implement other small functionalities, for instance, to show small XYZ axes for reference in a model editor window, or a front sight following the mouse in a shooting game.
This recipe will be simple enough for reading and understanding. But the usage of cull callbacks here may also help in the following chapters to implement some complex examples. Just keep it in mind or place a bookmark if you can.
1. Include necessary headers:
#include <osg/MatrixTransform> #include <osgDB/ReadFile> #include <osgUtil/CullVisitor> #include <osgViewer/Viewer>
2. Declare...