HudCallback.cpp 1.1 KB

1234567891011121314151617181920212223242526272829
  1. // Include own headers
  2. #include "HudCallback.hpp"
  3. // Include dependencies
  4. #include <osg/MatrixTransform>
  5. HudCallback::HudCallback(osg::Camera* camera) {
  6. _camera = camera;
  7. }
  8. void HudCallback::operator()(osg::Node* node, osg::NodeVisitor* nv) {
  9. osg::MatrixTransform* pTM = dynamic_cast<osg::MatrixTransform*>(node);
  10. if (pTM) {
  11. osg::Camera* camera = _camera;
  12. osg::Vec3 translate = pTM->getMatrix().getTrans();
  13. osg::Vec3 scale = pTM->getMatrix().getScale();
  14. osg::Matrix mv = camera->getViewMatrix();
  15. osg::Matrix inv_mv = camera->getInverseViewMatrix(); // Convert the view matrix to a normal transformation matrix
  16. osg::Quat inv_q = inv_mv.getRotate();
  17. osg::Quat q = mv.getRotate();
  18. // The current rotating coordinate system of the model, and the coordinate system in which the camera is located, rotates clockwise 90 degrees around the x-axis.
  19. osg::Quat dq(osg::DegreesToRadians(90.0f), osg::Vec3(1.0f, 0.0f, 0.0f));
  20. static osg::Matrix mm = osg::Matrix::rotate(dq);
  21. mv.setTrans(translate);
  22. pTM->setMatrix(osg::Matrix::scale(scale) * mv /** mm*/);
  23. }
  24. }