new FPCameraControl/LookAtCameraControl
This commit is contained in:
parent
0619460c1c
commit
5d368a689d
@ -1 +1 @@
|
|||||||
Subproject commit dd4f5c57355e4562fd94e863ffd0fcc48892073a
|
Subproject commit 569fc6c9ca5fbba277a70044871f2af045f2c6db
|
@ -200,9 +200,9 @@ public:
|
|||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
camera->pos=Vector3f(10,10,0);
|
camera->pos=Vector3f(10,10,0);
|
||||||
camera->target=Vector3f(0,0,0);
|
//camera->target=Vector3f(0,0,0);
|
||||||
|
|
||||||
camera->Refresh(); //更新矩阵计算
|
//camera->Refresh(); //更新矩阵计算
|
||||||
|
|
||||||
render_list=new RenderList(device);
|
render_list=new RenderList(device);
|
||||||
|
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
#include<hgl/graph/RenderList.h>
|
#include<hgl/graph/RenderList.h>
|
||||||
#include<hgl/Time.h>
|
#include<hgl/Time.h>
|
||||||
|
|
||||||
|
//#include<hgl/graph/LookAtCameraControl.h>
|
||||||
|
#include<hgl/graph/FirstPersonCameraControl.h>
|
||||||
|
|
||||||
#include<hgl/io/event/KeyboardEvent.h>
|
#include<hgl/io/event/KeyboardEvent.h>
|
||||||
#include<hgl/io/event/MouseEvent.h>
|
#include<hgl/io/event/MouseEvent.h>
|
||||||
|
|
||||||
@ -278,12 +281,12 @@ public:
|
|||||||
|
|
||||||
class CameraKeyboardControl:public KeyboardStateEvent
|
class CameraKeyboardControl:public KeyboardStateEvent
|
||||||
{
|
{
|
||||||
WalkerCamera *camera;
|
FirstPersonCameraControl *camera;
|
||||||
float move_speed;
|
float move_speed;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CameraKeyboardControl(WalkerCamera *wc)
|
CameraKeyboardControl(FirstPersonCameraControl *wc)
|
||||||
{
|
{
|
||||||
camera=wc;
|
camera=wc;
|
||||||
move_speed=1.0f;
|
move_speed=1.0f;
|
||||||
@ -306,21 +309,22 @@ public:
|
|||||||
if(HasPressed(KeyboardButton::S ))camera->Backward (move_speed);else
|
if(HasPressed(KeyboardButton::S ))camera->Backward (move_speed);else
|
||||||
if(HasPressed(KeyboardButton::A ))camera->Left (move_speed);else
|
if(HasPressed(KeyboardButton::A ))camera->Left (move_speed);else
|
||||||
if(HasPressed(KeyboardButton::D ))camera->Right (move_speed);else
|
if(HasPressed(KeyboardButton::D ))camera->Right (move_speed);else
|
||||||
if(HasPressed(KeyboardButton::R ))camera->Up (move_speed);else
|
//if(HasPressed(KeyboardButton::R ))camera->Up (move_speed);else
|
||||||
if(HasPressed(KeyboardButton::F ))camera->Down (move_speed);else
|
//if(HasPressed(KeyboardButton::F ))camera->Down (move_speed);else
|
||||||
|
|
||||||
if(HasPressed(KeyboardButton::Left ))camera->HoriRotate( move_speed);else
|
//if(HasPressed(KeyboardButton::Left ))camera->HoriRotate( move_speed);else
|
||||||
if(HasPressed(KeyboardButton::Right ))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::Up ))camera->VertRotate( move_speed);else
|
||||||
if(HasPressed(KeyboardButton::Down ))camera->VertRotate(-move_speed);else
|
//if(HasPressed(KeyboardButton::Down ))camera->VertRotate(-move_speed);else
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CameraMouseControl:public MouseEvent
|
class CameraMouseControl:public MouseEvent
|
||||||
{
|
{
|
||||||
WalkerCamera *camera;
|
FirstPersonCameraControl *camera;
|
||||||
double cur_time;
|
double cur_time;
|
||||||
|
double last_time;
|
||||||
|
|
||||||
Vector2f mouse_last_pos;
|
Vector2f mouse_last_pos;
|
||||||
|
|
||||||
@ -331,6 +335,8 @@ protected:
|
|||||||
mouse_last_pos.x=x;
|
mouse_last_pos.x=x;
|
||||||
mouse_last_pos.y=y;
|
mouse_last_pos.y=y;
|
||||||
|
|
||||||
|
last_time=cur_time;
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,23 +351,27 @@ protected:
|
|||||||
Vector2f gap=pos-mouse_last_pos;
|
Vector2f gap=pos-mouse_last_pos;
|
||||||
|
|
||||||
bool update=false;
|
bool update=false;
|
||||||
if(gap.x!=0){update=true;if(left)camera->HoriRotate( gap.x/10.0f);else camera->WrapHoriRotate(gap.x);}
|
//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);}
|
//if(gap.y!=0){update=true;if(left)camera->VertRotate(-gap.y/10.0f);else camera->WrapVertRotate(gap.y);}
|
||||||
|
|
||||||
|
camera->Rotate(gap,(cur_time-last_time)*5);
|
||||||
|
|
||||||
|
last_time=cur_time;
|
||||||
|
mouse_last_pos=Vector2f(x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
mouse_last_pos=Vector2f(x,y);
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OnWheel(int v,int h)
|
bool OnWheel(int v,int h)
|
||||||
{
|
{
|
||||||
camera->Distance(1+(h/1000.0f));
|
//camera->Distance(1+(h/1000.0f));
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CameraMouseControl(WalkerCamera *wc)
|
CameraMouseControl(FirstPersonCameraControl *wc)
|
||||||
{
|
{
|
||||||
camera=wc;
|
camera=wc;
|
||||||
cur_time=0;
|
cur_time=0;
|
||||||
@ -377,11 +387,12 @@ class CameraAppFramework:public VulkanApplicationFramework
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
GPUBuffer * ubo_camera_info =nullptr;
|
GPUBuffer *ubo_camera_info=nullptr;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
WalkerCamera * camera =nullptr;
|
Camera *camera=nullptr;
|
||||||
|
FirstPersonCameraControl *camera_control=nullptr;
|
||||||
|
|
||||||
CameraKeyboardControl * ckc=nullptr;
|
CameraKeyboardControl * ckc=nullptr;
|
||||||
CameraMouseControl * cmc=nullptr;
|
CameraMouseControl * cmc=nullptr;
|
||||||
@ -406,7 +417,7 @@ public:
|
|||||||
|
|
||||||
virtual void InitCamera(int w,int h)
|
virtual void InitCamera(int w,int h)
|
||||||
{
|
{
|
||||||
camera=new WalkerCamera;
|
camera=new Camera;
|
||||||
|
|
||||||
camera->width=w;
|
camera->width=w;
|
||||||
camera->height=h;
|
camera->height=h;
|
||||||
@ -414,14 +425,16 @@ public:
|
|||||||
camera->vp_height=h;
|
camera->vp_height=h;
|
||||||
|
|
||||||
camera->pos=Vector4f(10,10,10,1);
|
camera->pos=Vector4f(10,10,10,1);
|
||||||
camera->target=Vector4f(0,0,0,1);
|
|
||||||
|
|
||||||
camera->Refresh(); //更新矩阵计算
|
camera_control=new FirstPersonCameraControl(camera);
|
||||||
|
|
||||||
|
//camera_control->target=Vector4f(0,0,0,1);
|
||||||
|
camera_control->Refresh(); //更新矩阵计算
|
||||||
|
|
||||||
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&camera->info);
|
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&camera->info);
|
||||||
|
|
||||||
ckc=new CameraKeyboardControl(camera);
|
ckc=new CameraKeyboardControl(camera_control);
|
||||||
cmc=new CameraMouseControl(camera);
|
cmc=new CameraMouseControl(camera_control);
|
||||||
|
|
||||||
win->Join(ckc);
|
win->Join(ckc);
|
||||||
win->Join(cmc);
|
win->Join(cmc);
|
||||||
@ -432,7 +445,7 @@ public:
|
|||||||
camera->width=w;
|
camera->width=w;
|
||||||
camera->height=h;
|
camera->height=h;
|
||||||
|
|
||||||
camera->Refresh();
|
camera_control->Refresh();
|
||||||
|
|
||||||
ubo_camera_info->Write(&camera->info);
|
ubo_camera_info->Write(&camera->info);
|
||||||
}
|
}
|
||||||
@ -465,7 +478,7 @@ public:
|
|||||||
|
|
||||||
virtual void Draw()override
|
virtual void Draw()override
|
||||||
{
|
{
|
||||||
camera->Refresh(); //更新相机矩阵
|
camera_control->Refresh(); //更新相机矩阵
|
||||||
ubo_camera_info->Write(&camera->info); //写入缓冲区
|
ubo_camera_info->Write(&camera->info); //写入缓冲区
|
||||||
|
|
||||||
const uint32_t index=AcquireNextImage();
|
const uint32_t index=AcquireNextImage();
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
#include<hgl/graph/VKDescriptorSets.h>
|
#include<hgl/graph/VKDescriptorSets.h>
|
||||||
#include<hgl/type/Color4f.h>
|
#include<hgl/type/Color4f.h>
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
//push constant 一般只有128/256字节,仅能存在矩阵。
|
|
||||||
//所以我们将每个对象的独立变换矩阵存在push constant中
|
|
||||||
class GPUCmdBuffer
|
class GPUCmdBuffer
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
2
res
2
res
@ -1 +1 @@
|
|||||||
Subproject commit d7c22490949ff4b2f27aa3fd90d23e5c82639d1e
|
Subproject commit 91526330e1b7470a36d8651444709aa8a7da7efd
|
Loading…
x
Reference in New Issue
Block a user