|
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osg/Node>
#include <osg/MatrixTransform>
class RotateCallback: public osg::NodeCallback {
public:
RotateCallback(): osg::NodeCallback(), enabled_(true) {}
void operator()(osg::Node* node, osg::NodeVisitor *nv)
{
osg::MatrixTransform *xform = dynamic_cast<osg::MatrixTransform *>(node);
if (xform && enabled_) {
double t = nv->getFrameStamp()->getSimulationTime();
xform->setMatrix(osg::Matrix::rotate(t, osg::Vec3(0, 0, 1)));
}
traverse(node, nv);
}
bool enabled_;
};
RotateCallback *rotate_cb;
void main()
{
osgViewer::Viewer viewer;
osg::ref_ptr<osg::Node> node = new osg::Node;
node = osgDB::readNodeFile("cow.osg");
osg::ref_ptr<osg::MatrixTransform> xform = new osg::MatrixTransform;
rotate_cb = new RotateCallback;
xform->setUpdateCallback(rotate_cb);
xform->addChild(node.get());
viewer.setSceneData(node.get());
viewer.realize();
viewer.run();
}
哪里写的不对呀 为啥那头牛不转呀。。 |
|