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