OSG程序设计教程,第六章漫游,矩阵操作器。
CSouth.cpp稍有不同:
1.将判断keydown值的多个if换成了switch。
2.button拖动的旋转增量*0.001
3.RIGHT/LEFT key的旋转增量*0.1
/************************************************************************/
/* Management Class of Manipulator */
/************************************************************************/
#pragma once
#include <osgViewer/Viewer>
#include <osgGA/MatrixManipulator>
#include <osgUtil/IntersectVisitor>
#include <osg/LineSegment>
class CSouth:public osgGA::MatrixManipulator
{
public:
CSouth();
~CSouth();
private:
osg::ref_ptr<osg::Node> m_node; // node for detect collide
unsigned int m_nID; // camera operator
float m_fMoveSpeed; // move speed
osg::Vec3 m_vPosition; // position
osg::Vec3 m_vRotation; // rotation;
bool m_bleftButtonDown; // if the left btn is down
float m_fpushX; // x when left btn was down
float m_fpushY; // y ....
bool m_bCollide; // switch for detect collide
public:
void setCollide(bool collide);
bool getCollide();
void setFcollide();
virtual void setNode(osg::Node*);
virtual void setByMatrix(const osg::Matrix &matrix);
virtual void setByInverseMatrix(const osg::Matrix &matrix);
virtual osg::Matrix getMatrix(void) const;
virtual osg::Matrix getInverseMatrix(void) const;
virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us);
float m_fAngle;
void ChangePosition(osg::Vec3 &delta);
float getSpeed();
void setSpeed(float);
void SetPosition(osg::Vec3 &position);
void SetPosition(double * );
osg::Vec3 GetPosition();
void computeHomePosition();
};
/* Management Class of Manipulator */
/************************************************************************/
#pragma once
#include <osgViewer/Viewer>
#include <osgGA/MatrixManipulator>
#include <osgUtil/IntersectVisitor>
#include <osg/LineSegment>
class CSouth:public osgGA::MatrixManipulator
{
public:
CSouth();
~CSouth();
private:
osg::ref_ptr<osg::Node> m_node; // node for detect collide
unsigned int m_nID; // camera operator
float m_fMoveSpeed; // move speed
osg::Vec3 m_vPosition; // position
osg::Vec3 m_vRotation; // rotation;
bool m_bleftButtonDown; // if the left btn is down
float m_fpushX; // x when left btn was down
float m_fpushY; // y ....
bool m_bCollide; // switch for detect collide
public:
void setCollide(bool collide);
bool getCollide();
void setFcollide();
virtual void setNode(osg::Node*);
virtual void setByMatrix(const osg::Matrix &matrix);
virtual void setByInverseMatrix(const osg::Matrix &matrix);
virtual osg::Matrix getMatrix(void) const;
virtual osg::Matrix getInverseMatrix(void) const;
virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us);
float m_fAngle;
void ChangePosition(osg::Vec3 &delta);
float getSpeed();
void setSpeed(float);
void SetPosition(osg::Vec3 &position);
void SetPosition(double * );
osg::Vec3 GetPosition();
void computeHomePosition();
};