|
发表于 2015-7-16 10:43:11
|
显示全部楼层
#ifndef HUDAXIS_H
#define HUDAXIS_H 1
#include <osg/Camera>
#include <osg/MatrixTransform>
using namespace osg;
class HUDAxis:public Camera
{
public:
HUDAxis();
HUDAxis(HUDAxis const& copy, CopyOp copyOp = CopyOp::SHALLOW_COPY);
META_Node(osg, HUDAxis);
inline void setMainCamera(Camera* camera){ _mainCamera = camera;}
virtual void traverse(NodeVisitor& nv);
protected:
virtual ~HUDAxis();
observer_ptr<Camera> _mainCamera;
};
/////////////////////////////////////cpp///////////////////////////////////////////////////
HUDAxis::HUDAxis()
{
//可以在这直接读取axes.osgt;
// this->addChild(osgDB::readNodeFile("axes.osgt"));
}
HUDAxis::HUDAxis(HUDAxis const& copy, CopyOp copyOp /* = CopyOp::SHALLOW_COPY */):Camera(copy, copyOp),
_mainCamera(copy._mainCamera)
{
}
void HUDAxis::traverse(NodeVisitor& nv)
{
static Vec3 trans(0.0, 0.0, -8.0);
if(_mainCamera.valid() && nv.getVisitorType() == NodeVisitor::CULL_VISITOR)
{
Matrix matrix = _mainCamera->getViewMatrix();
matrix.setTrans(trans);
this->setViewMatrix(matrix);
}//if
osg::Camera::traverse(nv);
}
HUDAxis::~HUDAxis()
{
}
////使用这个类代码/////
ref_ptr<HUDAxis> hudAxes = new HUDAxis;
ref_ptr(Node) _axes = osgDB::readNodeFile("axes.osgt");
hudAxes->addChild(_axes);
hudAxes->setMainCamera(camera);
hudAxes->setViewport(0, 0, 200, 200);
hudAxes->setProjectionMatrix(osg::Matrixd::perspective(30.0f, 1.0, 1.0, 100.0));
hudAxes->setRenderOrder(Camera:OST_RENDER);
hudAxes->setClearMask(GL_DEPTH_BUFFER_BIT);
hudAxes->setAllowEventFocus(false);
hudAxes->setReferenceFrame(Transform::ABSOLUTE_RF);
scene->asGroup()->addChild(hudAxes);
/////////////////////////////截图//////////////////////
|
|