查看: 1362|回复: 5

编写类的问题

[复制链接]

该用户从未签到

发表于 2011-3-18 11:17:55 | 显示全部楼层 |阅读模式
本帖最后由 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();
}

请高手看一下是那地方的错误啊,谢谢

该用户从未签到

 楼主| 发表于 2011-3-18 11:19:37 | 显示全部楼层
本帖最后由 zhoujiajun2010 于 2011-3-18 11:26 编辑

这是程序出现的错误
1>d:\我的文档\visual studio 2005\projects\项目\项目\piantou.cpp(17) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\我的文档\visual studio 2005\projects\项目\项目\piantou.cpp(17) : error C2511: 'int PickHandler:ianTouShiDian(osg::ref_ptr<T>)' : overloaded member function not found in 'PickHandler'
1>        with
1>        [
1>            T=osgViewer::Viewer
1>        ]

1> error C2556: 'osg::AnimationPath PickHandler::CreatePath(void)' : overloaded function differs only by return type from 'osg::AnimationPath *PickHandler::CreatePath(void)'
1> error C2040: 'PickHandler::CreatePath' : 'osg::AnimationPath (void)' differs in levels of indirection from 'osg::AnimationPath *(void)'

1>d:\我的文档\visual studio 2005\projects\cegui\渐进融合\lizi.cpp(36) : error C2664: 'osgViewer::View::setCameraManipulator' : cannot convert parameter 1 from 'PickHandler *' to 'osgGA::MatrixManipulator *'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

该用户从未签到

发表于 2011-3-18 13:28:56 | 显示全部楼层
本帖最后由 qingfeng5211 于 2011-3-18 13:32 编辑

继承自GUIEventHandler,怎么连handle函数都没有实现?

把析构函数删了,或者改成protected看看

该用户从未签到

 楼主| 发表于 2011-3-19 11:04:41 | 显示全部楼层
回复 3# qingfeng5211


error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2511: 'int PickHandler:ianTouShiDian(osg::ref_ptr<T>)' : overloaded member function not found in 'PickHandler'
1>        with
1>        [
1>            T=osgViewer::Viewer
1>        ]

error C2556: 'osg::AnimationPath PickHandler::CreatePath(void)' : overloaded function differs only by return type from 'osg::AnimationPath *PickHandler::CreatePath(void)'
error C2040: 'PickHandler::CreatePath' : 'osg::AnimationPath (void)' differs in levels of indirection from 'osg::AnimationPath *(void)'

请问怎么还是有这样的错误啊,我是不是函数定义的不对啊,还是那个地方的参数传错了,请指正,非常感谢

该用户从未签到

发表于 2011-3-19 21:37:22 | 显示全部楼层
overloaded member function not found in 'PickHandler'

该用户从未签到

 楼主| 发表于 2011-3-20 16:54:36 | 显示全部楼层
恩,这个问题解决了,请问有没有osg编写类规则的材料啊,我的这方面还是有点欠缺啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表