|
本帖最后由 zhoujiajun2010 于 2011-3-18 11:28 编辑
我自己编写了一个类老是有错误,
头文件
pian.h
#include<osg/Shape>
#include<osg/ShapeDrawable>
#include<iostream>
#include<osg/AnimationPath>
#include<osgGA/AnimationPathManipulator>
#include<osgSim/Impostor>
#include<osg/Quat>
class PickHandler:public osgGA::GUIEventHandler
{
public:
//构造函数
PickHandler();
//析构函数
~PickHandler();
public:
void PianTouShiDian(osgViewer::Viewer*vt);
osg::AnimationPath*CreatePath();
private:
float GetRunTime(osg::Vec3&res,osg::Vec3&des);
osgViewer::Viewer*viewer;
osg::ref_ptr<osg::Vec3Array> controls;
float time;
float angle;
float roll;
};
cpp文件、、、、、、
#include"pian.h"
PickHandler:ickHandler()
{
time=0.0;
angle=0.0;
roll=1.57;
}
PickHandler::~PickHandler()
{
}
PickHandler::PianTouShiDian(osg::ref_ptr<osgViewer::Viewer>vt)
{
viewer=vt;
controls =new osg::Vec3Array;
//插入坐标点
controls->push_back(osg::Vec3f(-16,-3200,5000));
controls->push_back(osg::Vec3f(-8,-1600,2500));
controls->push_back(osg::Vec3f(-4,-800,1250));
controls->push_back(osg::Vec3f(-2,-400,600));
controls->push_back(osg::Vec3f(-1,-200,300));
controls->push_back(osg::Vec3f(0,0,-100));
osgGA::AnimationPathManipulator*apm=new osgGA::AnimationPathManipulator;
apm->setAnimationPath(CreatePath());
viewer->setCameraManipulator(amp);
}
float PickHandler::GetRunTime(osg::Vec3&res,osg::Vec3&des)
{
float distant =sqrt((des.x()-res.x())*(des.x()-res.x())+(des.y()-res.y())*(des.y()-res.y())+(des.z()-res.z())*(des.z()-res.z())+(des.z()-res.z())*(des.z()-res.z()));
return distant*0.001;
}
osg::AnimationPath PickHandler::CreatePath()
{
osg::ref_ptr<osg::AnimationPath> animationPath=new osg::AnimationPath;
animationPath->setLoopMode(osg::AnimationPath::NO_LOOPING);
if(controls.valid())
{
osg::Vec3Array::iterator iter=controls->begin();
for(; ;)
{
osg::Vec3 position(*iter);
iter++;
if(iter!=controls->end())
{
if(iter->x()>position.x())
{
angle=1.57-atan((iter->y()-position.y())/(iter->x()-position.x()));
if(angle<0)
angle=1.57+angle;
}
else
{
angle=-(1.57+atan(iter->y()-position.y())/(iter->x()-position.x()));
if(angle>0)
{
angle=-(1.57-angle);
}
}
osg:uat rotation(osg::Quat(roll,osg::Vec3(1.0,0.0,0.0))*osg::Quat(-angle,osg::Vec3(0.0,0.0,1.0)));
animationPath->insert(time,osg::AnimationPath::ControlPoint(position,rotation));
time+=GetRunTime(position,*iter);
roll+=0.3;
}
else
{
break;
}
}
}
return animationPath.release();
}
请高手看一下是那地方的错误啊,谢谢 |
|