update
This commit is contained in:
parent
b58af7ac23
commit
f57a7afb74
2
CMCore
2
CMCore
@ -1 +1 @@
|
|||||||
Subproject commit 16f8e89f5b72387d1ca49457558235834d8e9e49
|
Subproject commit a6ca121707e249368d9fe5b0573ed50ed1684106
|
@ -1 +1 @@
|
|||||||
Subproject commit 656dabd560b5f27e190baf3899104c38019ae9e2
|
Subproject commit 11a4d0cc6b01b65c88b3db83d2ee9f54354dc00d
|
@ -5,6 +5,7 @@
|
|||||||
#include<hgl/graph/InlineGeometry.h>
|
#include<hgl/graph/InlineGeometry.h>
|
||||||
#include<hgl/graph/VKRenderResource.h>
|
#include<hgl/graph/VKRenderResource.h>
|
||||||
#include<hgl/graph/RenderList.h>
|
#include<hgl/graph/RenderList.h>
|
||||||
|
#include<hgl/graph/Camera.h>
|
||||||
|
|
||||||
using namespace hgl;
|
using namespace hgl;
|
||||||
using namespace hgl::graph;
|
using namespace hgl::graph;
|
||||||
@ -105,7 +106,7 @@ private:
|
|||||||
ro_round_rectangle=CreateRenderableRoundRectangle(db,m2d.material,&rrci);
|
ro_round_rectangle=CreateRenderableRoundRectangle(db,m2d.material,&rrci);
|
||||||
}
|
}
|
||||||
|
|
||||||
camera.pos.Set(200,200,200,1.0);
|
camera->pos.Set(200,200,200,1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InitScene()
|
bool InitScene()
|
||||||
|
@ -296,6 +296,74 @@ public:
|
|||||||
}
|
}
|
||||||
};//class VulkanApplicationFramework
|
};//class VulkanApplicationFramework
|
||||||
|
|
||||||
|
class WalkerCamera:public Camera
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
using Camera::Camera;
|
||||||
|
virtual ~WalkerCamera()=default;
|
||||||
|
|
||||||
|
void ComputeViewMatrix() override
|
||||||
|
{
|
||||||
|
matrix.view=lookat(pos,target,world_up);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向前移动指定距离(延视线)
|
||||||
|
*/
|
||||||
|
virtual void Backward(const float move_length)
|
||||||
|
{
|
||||||
|
Move(camera_direction*move_length/view_distance.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向后移动指定距离(延视线)
|
||||||
|
*/
|
||||||
|
virtual void Forward(const float move_length){Backward(-move_length);}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向上移动指定距离(和视线垂直90度)
|
||||||
|
*/
|
||||||
|
virtual void Up(const float move_length)
|
||||||
|
{
|
||||||
|
Move(camera_up*move_length/view_distance.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向下移动指定距离(和视线垂直90度)
|
||||||
|
*/
|
||||||
|
virtual void Down(const float move_length){Up(-move_length);}
|
||||||
|
|
||||||
|
virtual void Left(const float move_length)
|
||||||
|
{
|
||||||
|
Move(camera_right*move_length/view_distance.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Right(const float move_length){Left(-move_length);}
|
||||||
|
|
||||||
|
virtual void HoriRotate(const float ang)
|
||||||
|
{
|
||||||
|
Rotate(ang,camera_up);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void VertRotate(const float ang)
|
||||||
|
{
|
||||||
|
Rotate(ang,camera_right);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void WrapHoriRotate(const float ang)
|
||||||
|
{
|
||||||
|
WrapRotate(ang,camera_up);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void WrapVertRotate(const float ang)
|
||||||
|
{
|
||||||
|
WrapRotate(ang,camera_right);
|
||||||
|
}
|
||||||
|
};//class WalkerCamera:public Camera
|
||||||
|
|
||||||
class CameraAppFramework:public VulkanApplicationFramework
|
class CameraAppFramework:public VulkanApplicationFramework
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@ -304,8 +372,7 @@ private:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Camera camera;
|
WalkerCamera * camera;
|
||||||
FreeCameraControl * fcc=nullptr;
|
|
||||||
float move_speed=1;
|
float move_speed=1;
|
||||||
|
|
||||||
Vector2f mouse_last_pos;
|
Vector2f mouse_last_pos;
|
||||||
@ -314,7 +381,7 @@ public:
|
|||||||
|
|
||||||
virtual ~CameraAppFramework()
|
virtual ~CameraAppFramework()
|
||||||
{
|
{
|
||||||
SAFE_CLEAR(fcc);
|
SAFE_CLEAR(camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool Init(int w,int h)
|
virtual bool Init(int w,int h)
|
||||||
@ -328,25 +395,26 @@ public:
|
|||||||
|
|
||||||
virtual void InitCamera(int w,int h)
|
virtual void InitCamera(int w,int h)
|
||||||
{
|
{
|
||||||
camera.type=CameraType::Perspective;
|
camera=new WalkerCamera;
|
||||||
camera.width=w;
|
|
||||||
camera.height=h;
|
|
||||||
camera.vp_width=w;
|
|
||||||
camera.vp_height=h;
|
|
||||||
camera.target.Set(0,0,0,1);
|
|
||||||
camera.pos.Set(10,10,10,1); //xyz三个值不要一样,以方便调试
|
|
||||||
|
|
||||||
camera.Refresh(); //更新矩阵计算
|
camera->type=CameraType::Perspective;
|
||||||
|
camera->width=w;
|
||||||
|
camera->height=h;
|
||||||
|
camera->vp_width=w;
|
||||||
|
camera->vp_height=h;
|
||||||
|
|
||||||
fcc=new FreeCameraControl(&camera);
|
camera->pos=Vector4f(10,10,10,1);
|
||||||
|
camera->target=Vector4f(0,0,0,1);
|
||||||
|
|
||||||
|
camera->Refresh(); //更新矩阵计算
|
||||||
|
|
||||||
ubo_world_matrix=db->CreateUBO(sizeof(WorldMatrix),&camera.matrix);
|
ubo_world_matrix=db->CreateUBO(sizeof(WorldMatrix),&camera->matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resize(int w,int h)override
|
void Resize(int w,int h)override
|
||||||
{
|
{
|
||||||
camera.width=w;
|
camera->width=w;
|
||||||
camera.height=h;
|
camera->height=h;
|
||||||
}
|
}
|
||||||
|
|
||||||
GPUBuffer *GetCameraMatrixBuffer()
|
GPUBuffer *GetCameraMatrixBuffer()
|
||||||
@ -358,8 +426,8 @@ public:
|
|||||||
|
|
||||||
virtual void Draw()override
|
virtual void Draw()override
|
||||||
{
|
{
|
||||||
camera.Refresh(); //更新相机矩阵
|
camera->Refresh(); //更新相机矩阵
|
||||||
ubo_world_matrix->Write(&camera.matrix); //写入缓冲区
|
ubo_world_matrix->Write(&camera->matrix); //写入缓冲区
|
||||||
|
|
||||||
const uint32_t index=AcquireNextImage();
|
const uint32_t index=AcquireNextImage();
|
||||||
|
|
||||||
@ -367,17 +435,17 @@ public:
|
|||||||
|
|
||||||
SubmitDraw(index);
|
SubmitDraw(index);
|
||||||
|
|
||||||
if(key_status[kbW])fcc->Forward (move_speed);else
|
if(key_status[kbW])camera->Up (move_speed);else
|
||||||
if(key_status[kbS])fcc->Backward (move_speed);else
|
if(key_status[kbS])camera->Down (move_speed);else
|
||||||
if(key_status[kbA])fcc->Left (move_speed);else
|
if(key_status[kbA])camera->Left (move_speed);else
|
||||||
if(key_status[kbD])fcc->Right (move_speed);else
|
if(key_status[kbD])camera->Right (move_speed);else
|
||||||
if(key_status[kbR])fcc->Up (move_speed);else
|
if(key_status[kbR])camera->Forward (move_speed);else
|
||||||
if(key_status[kbF])fcc->Down (move_speed);else
|
if(key_status[kbF])camera->Backward (move_speed);else
|
||||||
|
|
||||||
//if(key_status[kbLeft ])camera.WrapHorzRotate( move_speed);else
|
if(key_status[kbLeft ])camera->HoriRotate( move_speed);else
|
||||||
//if(key_status[kbRight ])camera.WrapHorzRotate(-move_speed);else
|
if(key_status[kbRight ])camera->HoriRotate(-move_speed);else
|
||||||
//if(key_status[kbUp ])camera.WrapVertRotate( move_speed);else
|
if(key_status[kbUp ])camera->VertRotate( move_speed);else
|
||||||
//if(key_status[kbDown ])camera.WrapVertRotate(-move_speed);else
|
if(key_status[kbDown ])camera->VertRotate(-move_speed);else
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,14 +468,14 @@ public:
|
|||||||
Vector2f gap=mouse_pos-mouse_last_pos;
|
Vector2f gap=mouse_pos-mouse_last_pos;
|
||||||
|
|
||||||
bool update=false;
|
bool update=false;
|
||||||
// if(gap.x!=0){update=true;if(mouse_key&mbLeft)camera.HorzRotate(-gap.x/10.0f);else camera.WrapHorzRotate(gap.x);}
|
if(gap.x!=0){update=true;if(mouse_key&mbLeft)camera->HoriRotate(-gap.x/10.0f);else camera->WrapHoriRotate(gap.x);}
|
||||||
// if(gap.y!=0){update=true;if(mouse_key&mbLeft)camera.VertRotate(-gap.y/10.0f);else camera.WrapVertRotate(gap.y);}
|
if(gap.y!=0){update=true;if(mouse_key&mbLeft)camera->VertRotate( gap.y/10.0f);else camera->WrapVertRotate(gap.y);}
|
||||||
|
|
||||||
mouse_last_pos=mouse_pos;
|
mouse_last_pos=mouse_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void MouseWheel(int v,int h,uint)
|
virtual void MouseWheel(int v,int h,uint)
|
||||||
{
|
{
|
||||||
camera.Distance(1+(v/1000.0f));
|
camera->Distance(1+(v/1000.0f));
|
||||||
}
|
}
|
||||||
};//class CameraAppFramework
|
};//class CameraAppFramework
|
||||||
|
Loading…
x
Reference in New Issue
Block a user