|
#include <osgViewer/Viewer>
#include <osg/Group>
#include <osg/ref_ptr>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Array>
#include <osg/NodeCallback>
#include <osgGA/FirstPersonManipulator>
#include <osg/Drawable>
#include <osgdb/ReadFile>
FILE * fp;
class xxCallback : public osg::NodeCallback
{
public:
xxCallback(osgViewer::Viewer * v)
{
viewer = v;
}
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
osg::Vec3d eye,center,up;
viewer->getCamera()->getViewMatrixAsLookAt(eye,center,up);
fprintf(fp,"update %f,%f,%f %f,%f,%f %f,%f,%f\n",eye.x(),eye.y(),eye.z(),center.x(),center.y(),center.z(),up.x(),up.y(),up.z());
traverse(node,nv);
}
private:
osgViewer::Viewer * viewer;
};
int main()
{
osgViewer::Viewer viewer;
osg::Group * root = new osg::Group();
root->addChild(osgDB::readNodeFile("c:/osg_data/cow.osg"));
root->setUpdateCallback(new xxCallback(&viewer));
viewer.setCameraManipulator(new osgGA::FirstPersonManipulator());
viewer.setSceneData( root );
fp = fopen("G:\\1.txt","wt");
while(!viewer.done())
{
viewer.frame();
osg::Vec3d eye,center,up;
viewer.getCamera()->getViewMatrixAsLookAt(eye,center,up);
fprintf(fp,"frame执行后 %f,%f,%f %f,%f,%f %f,%f,%f\n",eye.x(),eye.y(),eye.z(),center.x(),center.y(),center.z(),up.x(),up.y(),up.z());
}
}
代码里两次打印视点参数,在移动鼠标的情况下,两次输出不一样。按理说不可能啊。 |
|