RenderFramework接入键盘鼠标控制
This commit is contained in:
@@ -216,5 +216,5 @@ public:
|
||||
|
||||
int os_main(int,os_char **)
|
||||
{
|
||||
return RunFramework<TestApp>(OS_TEXT("AutoInstance"),1280,720);
|
||||
return RunFramework<TestApp>(OS_TEXT("Billboard"),1280,720);
|
||||
}
|
||||
|
@@ -346,125 +346,6 @@ public:
|
||||
}
|
||||
};//class VulkanApplicationFramework
|
||||
|
||||
class CameraKeyboardControl:public KeyboardStateEvent
|
||||
{
|
||||
FirstPersonCameraControl *camera;
|
||||
float move_speed;
|
||||
|
||||
public:
|
||||
|
||||
CameraKeyboardControl(FirstPersonCameraControl *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
|
||||
{
|
||||
FirstPersonCameraControl *camera;
|
||||
double cur_time;
|
||||
double last_time;
|
||||
|
||||
Vector2f mouse_pos;
|
||||
Vector2f mouse_last_pos;
|
||||
|
||||
protected:
|
||||
|
||||
bool OnPressed(int x,int y,MouseButton) override
|
||||
{
|
||||
mouse_last_pos.x=x;
|
||||
mouse_last_pos.y=y;
|
||||
|
||||
last_time=cur_time;
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool OnWheel(int,int y) override
|
||||
{
|
||||
if(y==0)return(false);
|
||||
|
||||
camera->Forward(float(y)/10.0f);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool OnMove(int x,int y) override
|
||||
{
|
||||
mouse_pos.x=x;
|
||||
mouse_pos.y=y;
|
||||
|
||||
bool left=HasPressed(MouseButton::Left);
|
||||
bool right=HasPressed(MouseButton::Right);
|
||||
|
||||
Vector2f pos(x,y);
|
||||
Vector2f gap=pos-mouse_last_pos;
|
||||
|
||||
if(left)
|
||||
{
|
||||
gap/=-5.0f;
|
||||
|
||||
camera->Rotate(gap);
|
||||
}
|
||||
else
|
||||
if(right)
|
||||
{
|
||||
gap/=10.0f;
|
||||
|
||||
camera->Move(Vector3f(gap.x,0,gap.y));
|
||||
}
|
||||
|
||||
last_time=cur_time;
|
||||
mouse_last_pos=Vector2f(x,y);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
CameraMouseControl(FirstPersonCameraControl *wc)
|
||||
{
|
||||
camera=wc;
|
||||
cur_time=0;
|
||||
last_time=0;
|
||||
}
|
||||
|
||||
const Vector2f &GetMouseCoord()const{return mouse_pos;}
|
||||
|
||||
void Update()
|
||||
{
|
||||
cur_time=GetPreciseTime();
|
||||
}
|
||||
};
|
||||
|
||||
class CameraAppFramework:public VulkanApplicationFramework
|
||||
{
|
||||
protected:
|
||||
|
Reference in New Issue
Block a user