supported newly trans for input event.
This commit is contained in:
parent
1d81121d30
commit
b2e52cb9fe
2
CMCore
2
CMCore
@ -1 +1 @@
|
|||||||
Subproject commit caaefe206bcea74aa1e4ed6f3fd7e8dec1b1ab45
|
Subproject commit 6280ace5a5a27edb6dab026be2a323a21dca63d8
|
@ -1 +1 @@
|
|||||||
Subproject commit 72b59fc22ece0a2e76b2319060dd99490297a238
|
Subproject commit 4f63548fc234d2dd4b2d9bdd2a70cd42cb66fa63
|
@ -149,7 +149,6 @@ private:
|
|||||||
ro_axis=CreateRenderableAxis(db,axis_mi->GetVAB(),&aci);
|
ro_axis=CreateRenderableAxis(db,axis_mi->GetVAB(),&aci);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
struct CubeCreateInfo cci;
|
struct CubeCreateInfo cci;
|
||||||
|
|
||||||
|
@ -20,31 +20,22 @@
|
|||||||
#include<hgl/graph/VKRenderTarget.h>
|
#include<hgl/graph/VKRenderTarget.h>
|
||||||
#include<hgl/graph/VKRenderResource.h>
|
#include<hgl/graph/VKRenderResource.h>
|
||||||
#include<hgl/graph/RenderList.h>
|
#include<hgl/graph/RenderList.h>
|
||||||
|
#include<hgl/Time.h>
|
||||||
|
|
||||||
|
#include<hgl/io/event/KeyboardEvent.h>
|
||||||
|
#include<hgl/io/event/MouseEvent.h>
|
||||||
|
|
||||||
using namespace hgl;
|
using namespace hgl;
|
||||||
|
using namespace hgl::io;
|
||||||
using namespace hgl::graph;
|
using namespace hgl::graph;
|
||||||
|
|
||||||
class VulkanApplicationFramework
|
class VulkanApplicationFramework:WindowEvent
|
||||||
{
|
{
|
||||||
private:
|
protected:
|
||||||
|
|
||||||
Window * win =nullptr;
|
Window * win =nullptr;
|
||||||
VulkanInstance * inst =nullptr;
|
VulkanInstance * inst =nullptr;
|
||||||
|
|
||||||
void OnKeyPressed (KeyboardButton kb){key_status[size_t(kb)]=true;}
|
|
||||||
void OnKeyReleased (KeyboardButton kb){key_status[size_t(kb)]=false;}
|
|
||||||
void OnKeyRepeat (KeyboardButton kb){KeyRepeat(kb);}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
uint mouse_key=0;
|
|
||||||
Vector2f mouse_pos;
|
|
||||||
|
|
||||||
void OnMousePressed (int,int,uint mk){mouse_key=mk;MousePressed(mk);}
|
|
||||||
void OnMouseReleased(int,int,uint mk){mouse_key=0;MouseReleased(mk);}
|
|
||||||
void OnMouseMove (int x,int y){mouse_pos.x=x;mouse_pos.y=y;MouseMove();}
|
|
||||||
void OnMouseWheel (int v,int h,uint mk){MouseWheel(v,h,mk);}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
GPUDevice * device =nullptr;
|
GPUDevice * device =nullptr;
|
||||||
@ -63,12 +54,12 @@ protected:
|
|||||||
|
|
||||||
RenderResource * db =nullptr;
|
RenderResource * db =nullptr;
|
||||||
|
|
||||||
bool key_status[size_t(KeyboardButton::RANGE_SIZE)];
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~VulkanApplicationFramework()
|
virtual ~VulkanApplicationFramework()
|
||||||
{
|
{
|
||||||
|
win->Unjoin(this);
|
||||||
|
|
||||||
SAFE_CLEAR(db);
|
SAFE_CLEAR(db);
|
||||||
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
|
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
|
||||||
|
|
||||||
@ -79,8 +70,6 @@ public:
|
|||||||
|
|
||||||
virtual bool Init(int w,int h)
|
virtual bool Init(int w,int h)
|
||||||
{
|
{
|
||||||
hgl_zero(key_status);
|
|
||||||
|
|
||||||
clear_color.Zero();
|
clear_color.Zero();
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
@ -125,32 +114,19 @@ public:
|
|||||||
|
|
||||||
InitCommandBuffer();
|
InitCommandBuffer();
|
||||||
|
|
||||||
SetEventCall(win->OnResize, this,VulkanApplicationFramework,OnResize );
|
win->Join(this);
|
||||||
SetEventCall(win->OnKeyPressed, this,VulkanApplicationFramework,OnKeyPressed );
|
|
||||||
SetEventCall(win->OnKeyReleased, this,VulkanApplicationFramework,OnKeyReleased );
|
|
||||||
SetEventCall(win->OnKeyRepeat, this,VulkanApplicationFramework,OnKeyRepeat );
|
|
||||||
|
|
||||||
SetEventCall(win->OnMousePressed, this,VulkanApplicationFramework,OnMousePressed );
|
|
||||||
SetEventCall(win->OnMouseReleased, this,VulkanApplicationFramework,OnMouseReleased );
|
|
||||||
SetEventCall(win->OnMouseMove, this,VulkanApplicationFramework,OnMouseMove );
|
|
||||||
SetEventCall(win->OnMouseWheel, this,VulkanApplicationFramework,OnMouseWheel );
|
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Resize(int,int)=0;
|
virtual void Resize(int,int)=0;
|
||||||
virtual void KeyRepeat(KeyboardButton){}
|
|
||||||
virtual void MousePressed(uint){}
|
|
||||||
virtual void MouseReleased(uint){}
|
|
||||||
virtual void MouseMove(){}
|
|
||||||
virtual void MouseWheel(int,int,uint){}
|
|
||||||
|
|
||||||
void SetClearColor(COLOR cc)
|
void SetClearColor(COLOR cc)
|
||||||
{
|
{
|
||||||
clear_color.Use(cc,1.0);
|
clear_color.Use(cc,1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnResize(int w,int h)
|
void OnResize(uint w,uint h) override
|
||||||
{
|
{
|
||||||
if(w>0&&h>0)
|
if(w>0&&h>0)
|
||||||
device->Resize(w,h);
|
device->Resize(w,h);
|
||||||
@ -300,6 +276,103 @@ public:
|
|||||||
}
|
}
|
||||||
};//class VulkanApplicationFramework
|
};//class VulkanApplicationFramework
|
||||||
|
|
||||||
|
class CameraKeyboardControl:public KeyboardStateEvent
|
||||||
|
{
|
||||||
|
WalkerCamera *camera;
|
||||||
|
float move_speed;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
CameraKeyboardControl(WalkerCamera *wc)
|
||||||
|
{
|
||||||
|
camera=wc;
|
||||||
|
move_speed=1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OnPressed(const KeyboardButton &kb)override
|
||||||
|
{
|
||||||
|
if(!KeyboardStateEvent::OnPressed(kb))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
if(kb==KeyboardButton::Minus )move_speed*=0.9f;else
|
||||||
|
if(kb==KeyboardButton::Equals )move_speed*=1.1f;
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
if(HasPressed(KeyboardButton::W ))camera->Forward (move_speed);else
|
||||||
|
if(HasPressed(KeyboardButton::S ))camera->Backward (move_speed);else
|
||||||
|
if(HasPressed(KeyboardButton::A ))camera->Left (move_speed);else
|
||||||
|
if(HasPressed(KeyboardButton::D ))camera->Right (move_speed);else
|
||||||
|
if(HasPressed(KeyboardButton::R ))camera->Up (move_speed);else
|
||||||
|
if(HasPressed(KeyboardButton::F ))camera->Down (move_speed);else
|
||||||
|
|
||||||
|
if(HasPressed(KeyboardButton::Left ))camera->HoriRotate( move_speed);else
|
||||||
|
if(HasPressed(KeyboardButton::Right ))camera->HoriRotate(-move_speed);else
|
||||||
|
if(HasPressed(KeyboardButton::Up ))camera->VertRotate( move_speed);else
|
||||||
|
if(HasPressed(KeyboardButton::Down ))camera->VertRotate(-move_speed);else
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class CameraMouseControl:public MouseEvent
|
||||||
|
{
|
||||||
|
WalkerCamera *camera;
|
||||||
|
double cur_time;
|
||||||
|
|
||||||
|
Vector2f mouse_last_pos;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
bool OnPressed(int x,int y,MouseButton) override
|
||||||
|
{
|
||||||
|
mouse_last_pos.x=x;
|
||||||
|
mouse_last_pos.y=y;
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OnMove(int x,int y) override
|
||||||
|
{
|
||||||
|
bool left=HasPressed(MouseButton::Left);
|
||||||
|
bool right=HasPressed(MouseButton::Right);
|
||||||
|
|
||||||
|
if(left||right)
|
||||||
|
{
|
||||||
|
Vector2f pos(x,y);
|
||||||
|
Vector2f gap=pos-mouse_last_pos;
|
||||||
|
|
||||||
|
bool update=false;
|
||||||
|
if(gap.x!=0){update=true;if(left)camera->HoriRotate( gap.x/10.0f);else camera->WrapHoriRotate(gap.x);}
|
||||||
|
if(gap.y!=0){update=true;if(left)camera->VertRotate(-gap.y/10.0f);else camera->WrapVertRotate(gap.y);}
|
||||||
|
}
|
||||||
|
|
||||||
|
mouse_last_pos=Vector2f(x,y);
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OnWheel(int v,int h)
|
||||||
|
{
|
||||||
|
camera->Distance(1+(h/1000.0f));
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
CameraMouseControl(WalkerCamera *wc)
|
||||||
|
{
|
||||||
|
camera=wc;
|
||||||
|
cur_time=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
cur_time=GetDoubleTime();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class CameraAppFramework:public VulkanApplicationFramework
|
class CameraAppFramework:public VulkanApplicationFramework
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@ -309,14 +382,16 @@ private:
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
WalkerCamera * camera =nullptr;
|
WalkerCamera * camera =nullptr;
|
||||||
float move_speed =1;
|
|
||||||
|
|
||||||
Vector2f mouse_last_pos;
|
CameraKeyboardControl * ckc=nullptr;
|
||||||
|
CameraMouseControl * cmc=nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~CameraAppFramework()
|
virtual ~CameraAppFramework()
|
||||||
{
|
{
|
||||||
|
SAFE_CLEAR(ckc);
|
||||||
|
SAFE_CLEAR(cmc);
|
||||||
SAFE_CLEAR(camera);
|
SAFE_CLEAR(camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,6 +419,12 @@ public:
|
|||||||
camera->Refresh(); //更新矩阵计算
|
camera->Refresh(); //更新矩阵计算
|
||||||
|
|
||||||
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&camera->info);
|
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&camera->info);
|
||||||
|
|
||||||
|
ckc=new CameraKeyboardControl(camera);
|
||||||
|
cmc=new CameraMouseControl(camera);
|
||||||
|
|
||||||
|
win->Join(ckc);
|
||||||
|
win->Join(cmc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resize(int w,int h)override
|
void Resize(int w,int h)override
|
||||||
@ -382,8 +463,6 @@ public:
|
|||||||
|
|
||||||
virtual void BuildCommandBuffer(uint32_t index)=0;
|
virtual void BuildCommandBuffer(uint32_t index)=0;
|
||||||
|
|
||||||
inline bool isPush(enum class KeyboardButton kb)const{return key_status[size_t(kb)];}
|
|
||||||
|
|
||||||
virtual void Draw()override
|
virtual void Draw()override
|
||||||
{
|
{
|
||||||
camera->Refresh(); //更新相机矩阵
|
camera->Refresh(); //更新相机矩阵
|
||||||
@ -395,47 +474,7 @@ public:
|
|||||||
|
|
||||||
SubmitDraw(index);
|
SubmitDraw(index);
|
||||||
|
|
||||||
if(isPush(KeyboardButton::W ))camera->Forward (move_speed);else
|
ckc->Update();
|
||||||
if(isPush(KeyboardButton::S ))camera->Backward (move_speed);else
|
cmc->Update();
|
||||||
if(isPush(KeyboardButton::A ))camera->Left (move_speed);else
|
|
||||||
if(isPush(KeyboardButton::D ))camera->Right (move_speed);else
|
|
||||||
if(isPush(KeyboardButton::R ))camera->Up (move_speed);else
|
|
||||||
if(isPush(KeyboardButton::F ))camera->Down (move_speed);else
|
|
||||||
|
|
||||||
if(isPush(KeyboardButton::Left ))camera->HoriRotate( move_speed);else
|
|
||||||
if(isPush(KeyboardButton::Right ))camera->HoriRotate(-move_speed);else
|
|
||||||
if(isPush(KeyboardButton::Up ))camera->VertRotate( move_speed);else
|
|
||||||
if(isPush(KeyboardButton::Down ))camera->VertRotate(-move_speed);else
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void KeyRepeat(KeyboardButton kb)override
|
|
||||||
{
|
|
||||||
if(kb==KeyboardButton::Minus )move_speed*=0.9f;else
|
|
||||||
if(kb==KeyboardButton::Equals )move_speed*=1.1f;else
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void MousePressed(uint) override
|
|
||||||
{
|
|
||||||
mouse_last_pos=mouse_pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void MouseMove() override
|
|
||||||
{
|
|
||||||
if(!(mouse_key&(mbLeft|mbRight)))return;
|
|
||||||
|
|
||||||
Vector2f gap=mouse_pos-mouse_last_pos;
|
|
||||||
|
|
||||||
bool update=false;
|
|
||||||
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);}
|
|
||||||
|
|
||||||
mouse_last_pos=mouse_pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void MouseWheel(int v,int h,uint)
|
|
||||||
{
|
|
||||||
camera->Distance(1+(v/1000.0f));
|
|
||||||
}
|
}
|
||||||
};//class CameraAppFramework
|
};//class CameraAppFramework
|
Loading…
x
Reference in New Issue
Block a user