新的Camera与Frustum关系
This commit is contained in:
parent
82b9563d97
commit
dd6b45294a
@ -6,11 +6,19 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
namespace graph
|
namespace graph
|
||||||
{
|
{
|
||||||
|
enum class CameraType
|
||||||
|
{
|
||||||
|
Perspective,
|
||||||
|
Ortho
|
||||||
|
};//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 摄像机数据结构
|
* 摄像机数据结构
|
||||||
*/
|
*/
|
||||||
struct Camera
|
struct Camera
|
||||||
{
|
{
|
||||||
|
CameraType type=CameraType::Perspective;
|
||||||
|
|
||||||
float width; ///<视图宽
|
float width; ///<视图宽
|
||||||
float height; ///<视图高
|
float height; ///<视图高
|
||||||
|
|
||||||
@ -21,12 +29,19 @@ namespace hgl
|
|||||||
Vector3f center; ///<视点坐标
|
Vector3f center; ///<视点坐标
|
||||||
Vector3f up_vector; ///<向上量
|
Vector3f up_vector; ///<向上量
|
||||||
Vector3f forward_vector; ///<向前量
|
Vector3f forward_vector; ///<向前量
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Matrix4f projection;
|
||||||
|
Matrix4f modelview;
|
||||||
|
|
||||||
|
Frustum frustum;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
void Refresh();
|
||||||
};//struct Camera
|
};//struct Camera
|
||||||
|
|
||||||
void CameraToFrustum(Frustum *,const Camera *);
|
|
||||||
|
|
||||||
void MakeCameraMatrix(Matrix4f *proj,Matrix4f *mv,const Camera *cam);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 行走模拟像机
|
* 行走模拟像机
|
||||||
*/
|
*/
|
||||||
|
@ -260,6 +260,7 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
struct { T x,y; };
|
struct { T x,y; };
|
||||||
struct { T r,g; };
|
struct { T r,g; };
|
||||||
|
struct { T u,v; };
|
||||||
T data[2];
|
T data[2];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -285,6 +286,7 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
struct { T x,y,z; };
|
struct { T x,y,z; };
|
||||||
struct { T r,g,b; };
|
struct { T r,g,b; };
|
||||||
|
struct { T u,v,w; };
|
||||||
T data[3];
|
T data[3];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
glslangValidator -V -o FlatColor.vert.spv FlatColor.vert
|
glslangValidator -V -o FlatColor.vert.spv FlatColor.vert
|
||||||
glslangValidator -V -o OnlyPosition.vert.spv OnlyPosition.vert
|
glslangValidator -V -o OnlyPosition.vert.spv OnlyPosition.vert
|
||||||
|
glslangValidator -V -o OnlyPosition3D.vert.spv OnlyPosition3D.vert
|
||||||
glslangValidator -V -o FlatColor.frag.spv FlatColor.frag
|
glslangValidator -V -o FlatColor.frag.spv FlatColor.frag
|
||||||
|
|
||||||
glslangValidator -V -o FlatTexture.vert.spv FlatTexture.vert
|
glslangValidator -V -o FlatTexture.vert.spv FlatTexture.vert
|
||||||
|
@ -23,20 +23,17 @@ namespace hgl
|
|||||||
return result*translate(-eye);
|
return result*translate(-eye);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraToFrustum(Frustum *f,const Camera *cam)
|
void Camera::Refresh()
|
||||||
{
|
{
|
||||||
if(!f||!cam)return;
|
if(type==CameraType::Perspective)
|
||||||
|
projection=perspective(width/height,fov,znear,zfar);
|
||||||
|
else
|
||||||
|
projection=ortho(width,height,znear,zfar);
|
||||||
|
|
||||||
f->SetVerticalFovAndAspectRatio(DegToRad(cam->fov),cam->width/cam->height);
|
modelview=hgl::graph::LookAt(eye,center,up_vector);
|
||||||
f->SetViewPlaneDistances(cam->znear,cam->zfar);
|
|
||||||
|
|
||||||
//Matrix4f projection_matrix=f->ProjectionMatrix(); //可以用Frustum来算projection matrix
|
frustum.SetVerticalFovAndAspectRatio(DegToRad(fov),width/height);
|
||||||
}
|
frustum.SetViewPlaneDistances(znear,zfar);
|
||||||
|
|
||||||
void MakeCameraMatrix(Matrix4f *proj,Matrix4f *mv,const Camera *cam)
|
|
||||||
{
|
|
||||||
*proj=perspective(cam->width/cam->height,cam->fov,cam->znear,cam->zfar);
|
|
||||||
*mv=hgl::graph::LookAt(cam->eye,cam->center,cam->up_vector);
|
|
||||||
}
|
}
|
||||||
}//namespace graph
|
}//namespace graph
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
Loading…
x
Reference in New Issue
Block a user