新的Camera与Frustum关系

This commit is contained in:
hyzboy 2019-05-27 22:45:38 +08:00
parent 82b9563d97
commit dd6b45294a
4 changed files with 30 additions and 15 deletions

View File

@ -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);
/**
*
*/

View File

@ -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:

View File

@ -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

View File

@ -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