ULRE/inc/hgl/graph/Camera.h

124 lines
4.3 KiB
C
Raw Normal View History

2019-05-21 21:28:33 +08:00
#ifndef HGL_GRAPH_CAMERA_INCLUDE
#define HGL_GRAPH_CAMERA_INCLUDE
#include<hgl/math/Math.h>
namespace hgl
{
namespace graph
{
2019-05-27 22:45:38 +08:00
enum class CameraType
{
Perspective,
Ortho
};//
2019-05-21 21:28:33 +08:00
/**
*
*/
struct Camera
{
2019-05-27 22:45:38 +08:00
CameraType type=CameraType::Perspective;
2019-05-21 21:28:33 +08:00
float width; ///<视图宽
float height; ///<视图高
float fov; ///<水平FOV
float znear,zfar; ///<Z轴上离眼睛的距离
2019-06-11 15:51:13 +08:00
Vector4f eye; ///<眼睛坐标
Vector4f center; ///<视点坐标
Vector4f up_vector; ///<向上量(默认0,0,1)
Vector4f forward_vector; ///<向前量(默认1,0,0)
Vector4f right_vector; ///<向右量(默认0,1,0)
2019-05-21 21:28:33 +08:00
2019-05-27 22:45:38 +08:00
public:
2019-05-21 21:28:33 +08:00
WorldMatrix matrix;
2019-05-27 22:45:38 +08:00
Frustum frustum;
public:
void Refresh();
};//struct Camera
2019-05-21 21:28:33 +08:00
/**
*
*/
class WalkerCamera:public Camera
{
2019-06-11 15:51:13 +08:00
protected:
/**
*
* @param move_dist
*/
void Move(const Vector4f &move_dist)
{
eye += move_dist;
center += move_dist;
}
/**
*
* @param ang
* @param axis
*/
void Rotate(double ang,const Vector4f &axis)
{
center=eye+(center-eye)*rotate(hgl_ang2rad(ang),axis);
}
/**
*
* @param ang
* @param axis
*/
void WrapRotate(double ang,const Vector4f &axis)
{
eye=center+(eye-center)*rotate(hgl_ang2rad(ang),axis);
}
2019-05-21 21:28:33 +08:00
public: //方法
2019-06-11 15:51:13 +08:00
virtual void Backward(float step=0.01){Move(forward_vector*step);} ///<向后
2019-05-21 21:28:33 +08:00
virtual void Forward(float step=0.01){Backward(-step);} ///<向前
2019-06-11 15:51:13 +08:00
virtual void Up(float step=0.01){Move(up_vector*step);} ///<向上
2019-05-21 21:28:33 +08:00
virtual void Down(float step=0.01){Up(-step);} ///<向下
2019-06-11 15:51:13 +08:00
virtual void Right(float step=0.01){Move(right_vector);} ///<向右
2019-05-21 21:28:33 +08:00
virtual void Left(float step=0.01){Right(-step);} ///<向左
public: //以自身为中心旋转
2019-06-11 15:51:13 +08:00
virtual void RightDumping(float ang=5){Rotate(ang,forward_vector);} ///<右倾倒
virtual void LeftDumping(float ang=5){RightDumping(-ang);} ///<左倾倒
2019-05-21 21:28:33 +08:00
2019-06-11 15:51:13 +08:00
virtual void LeaningBack(float ang=5){Rotate(ang,right_vector);} ///<后仰
virtual void ForwardTilt(float ang=5){LeaningBack(-ang);} ///<前倾
2019-05-21 21:28:33 +08:00
2019-06-11 15:51:13 +08:00
virtual void RightRotate(float ang=5){Rotate(ang,up_vector);} ///<右转
virtual void LeftRotate(float ang=5){RightRotate(-ang);} ///<左转
2019-05-21 21:28:33 +08:00
public: //以目标点为中心旋转
2019-06-11 15:51:13 +08:00
virtual void WrapUpRotate(float ang=5){WrapRotate(ang,right_vector);} ///<以目标点为中心向上旋转
virtual void WrapDownRotate(float ang=5){WrapUpRotate(-ang);} ///<以目标点为中心向下旋转
2019-05-21 21:28:33 +08:00
2019-06-11 15:51:13 +08:00
virtual void WrapRightRotate(float ang=5){WrapRotate(ang,up_vector);} ///<以目标点为中心向右旋转
virtual void WrapLeftRotate(float ang=5){WrapRightRotate(-ang);} ///<以目标点为中心向左旋转
2019-05-21 21:28:33 +08:00
public: //距离
2019-06-11 15:51:13 +08:00
virtual void Distance(float pos) ///<调整距离
{
if(pos==1.0)return;
eye=center+(eye-center)*pos;
}
2019-05-21 21:28:33 +08:00
};//class WalkerCamera
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_CAMERA_INCLUDE