|
本人按照教程视频上讲的内容输入代码,怎么就一堆错误呢?
Travel.h
#pragma once
#include "../Common/Common.h"
#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osgGA/GUIEventAdapter>
#include <osgViewer/ViewerEventHandlers>
#include <osg/MatrixTransform>
#include <osg/AnimationPath>
#include <osg/PositionAttitudeTransform>
#include <osg/AnimationPath>
#include <osg/Matrixd>
#include <osgGA/TrackballManipulator>
#include <iostream>
#ifdef _DEBUG
#pragma comment(lib, "../Debug/Commond.lib")
#else
#pragma comment(lib, "../Release/Common.lib")
#endif
class TravelManipulator : public osgGA::OrbitManipulator //例子中用的是MatirxManipulator,但是运行时说是osg::GA没有该类{
public:
TravelManipulator();
public:
//实现得到和设置矩阵接口
//设置当前视口
virtual void setByMatrix(const osg::Matrix &matrix);
//设置当前逆向窗口
virtual void setByInverseMatrix(const osg::Matrix &matrix);
//得到当前的矩阵
virtual osg::Matrixd getMatrix() const;
//得到当前的逆矩阵
virtual osg::Matrixd getInverseMatrix() const;
//响应事件
virtual bool handle (const osgGA::GUIEventAdapter& ea,osgGA::GUIEventAdapter& us);
private:
//视点
osg::Vec3 m_vPosotion;
//朝向
osg::Vec3 m_vRotation;
//移动步长
int m_vStep;
//旋转步长
float m_vRotateStep;
}
Travel.cpp
#include "Travel.h"
TravelManipulator::TravelManipulator()
{
m_vPosotion = osg::Vec3(0,0,0);
m_vRotation = osg::Vec3(0,0,0);//给视点和朝向初始化
m_vStep = 0;
m_vRotateStep = 0.0;
}
void TravelManipulator::setByMatrix(const osg::Matrixd &matrix)
{
}
void TravelManipulator::setByInverseMatrix(const osg::Matrixd &matrix)
{
}
osg::Matrixd TravelManipulator::getMatrix() const
{
osg::Matrixd mat;
mat.makeTranslate(m_vPosotion);
return mat * osg::Matrixd::rotate(m_vRotation[0], osg::X_AXIS,m_vRotation[1],osg::Y_AXIS, m_vRotation[2],osg::Z_AXIS);
}
osg::Matrixd TravelManipulator::getInverseMatrix() const
{
osg::Matrixd mat;
mat.makeTranslate(m_vPosotion);
return osg::Matrixd::inverse(mat * osg::Matrixd::rotate(m_vRotation[0], osg::X_AXIS,m_vRotation[1],osg::Y_AXIS, m_vRotation[2],osg::Z_AXIS));
}
bool TravelManipulator::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIEventAdapter &us)
{
switch (ea.getEventType())
{
case osgGA::GUIEventAdapter::KEYDOWN:
{
if (ea.getKey() == 'w')
{
m_vPosotion[2] +=2;//按w模型往前移两个单位
}
else if (ea.getKey() == 's')
{
m_vPosotion[2] -= 2;//按S模型往后移两个单位
}
}
}
return false;
}
main.cpp
#include "Travel.h"
int main()
{
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
osg::ref_ptr<osg::Node> node = osgDB::readNodeFile("glider.osg");
viewer->setSceneData(node.get());
return viewer->run();
}
错误在哪里啊?????
main.cpp(4): error C2628: “TravelManipulator”后面接“int”是非法的(是否忘记了“;”?)
1>main.cpp(5): error C3874: “main”的返回类型应为“int”而非“TravelManipulator”
1>main.cpp(13): error C2664: “TravelManipulator::TravelManipulator(const TravelManipulator &)”: 不能将参数 1 从“int”转换为“const TravelManipulator &”
1> 原因如下: 无法从“int”转换为“const TravelManipulator”
1> 无构造函数可以接受源类型,或构造函数重载决策不明确
1> Travel.cpp
1>Travel.cpp(4): error C2533: “TravelManipulator::{ctor}”: 构造函数不能有返回类型
|
|