|
本帖最后由 xiacanni 于 2012-10-7 00:24 编辑
我刚开始通过《OSG程序设计教程》学习osg。
《OSG程序设计教程》第五章 例子13,编译不通过,是一个交互的pick例子。(之前的例子都是能通过的。)
这个例子是这样的:(和源代码略有区别,把一个【i】改成了【i 】,要不然系统会识别这个【i】把后面的字都变成斜体.......)
//by FreeSouth 2008 6 16
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osg/Group>
#include <osgFX/Scribe>
#include <osgGA/GUIEventHandler>
#include <osgUtil/LineSegmentIntersector>
class CPickHandler : public osgGA::GUIEventHandler
{
public:
CPickHandler(osgViewer::Viewer* viewer):mViewer(viewer){}
virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
switch(ea.getEventType())
{
case(osgGA::GUIEventAdapter::PUSH):
if (ea.getButton()==1)
{
Pick(ea.getX(), ea.getY());
}
return true;
}
return false;
}
protected:
void Pick(float x, float y)
{
osgUtil::LineSegmentIntersector::Intersections intersections;
if (mViewer->computeIntersections(x, y, intersections))
{
for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
hitr != intersections.end();
++hitr)
{
if (!hitr->nodePath.empty() && !(hitr->nodePath.back()->getName().empty()))
{
osg::NodePath& np = hitr ->nodePath ;
for (int i=np.size()-1; i>=0; --i)
{
osgFX::Scribe* sc= dynamic_cast<osgFX::Scribe *>(np[i ]);
if (sc!= NULL)
{
if(sc ->getNodeMask() != 0)
sc ->setNodeMask(0) ;
}
}
}
}
}
}
osgViewer::Viewer* mViewer ;
};
int main(int, char**)
{
osgViewer::Viewer viewer;
osg::ref_ptr<osg::Group> root = new osg::Group();
root ->addChild(osgDB::readNodeFile("cessna.osg"));
osg::ref_ptr<osg::Node> cow = osgDB::readNodeFile("cow.osg") ;
osg::ref_ptr<osgFX::Scribe> sc = new osgFX::Scribe() ;
sc ->addChild(cow.get()) ;
root->addChild(cow.get ());
root->addChild(sc.get ()) ;
viewer.setSceneData(root.get ());
viewer.addEventHandler(new CPickHandler(&viewer)) ;
viewer.realize();
viewer.run();
return 0;
}
如果照这个代码直接编译,会说这一句
osg::NodePath& np = hitr ->nodePath ;
无法从“const osg::NodePath”转换为“osg::NodePath &”
我就去掉了&,改成了osg::NodePath np = hitr ->nodePath ;
如果这样编译的话,会有14个 error LNK2001,这里列举其中4个
y_main.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall osgFX::Scribe::Scribe(void)" (__imp_??0Scribe@osgFX@@QAE@XZ)
1>my_main.obj : error LNK2001: 无法解析的外部符号 "public: virtual class osg::Object * __thiscall osgFX::Scribe::cloneType(void)const " (?cloneType@Scribe@osgFX@@UBEPAVObject@osg@@XZ)
1>my_main.obj : error LNK2001: 无法解析的外部符号 "public: virtual class osg::Object * __thiscall osgFX::Scribe::clone(class osg::CopyOp const &)const " (?clone@Scribe@osgFX@@UBEPAVObject@osg@@ABVCopyOp@4@@Z)
1>my_main.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall osgFX::Scribe::isSameKindAs(class osg::Object const *)const " (?isSameKindAs@Scribe@osgFX@@UBE_NPBVObject@osg@@@Z)
请问大家是怎么回事?
是因为我osg没配置好?虽然之前的例子没问题,但是之前的例子没有用到过 <osgFX/Scribe>,<osgUtil/LineSegmentIntersector>这两个头文件,因为用了这两个头文件而dll、lib什么的不对所以会通不过?(我的系统是win7 64,按照论坛里http://bbs.osgchina.org/forum.ph ... &extra=page%3D1配置的 32位osg)
还是因为osg::NodePath& np = hitr ->nodePath ;这一句不应该改? |
|