Added camera position moved with midlle mouse button, fixed mouse button press and release events on linux
This commit is contained in:
parent
cf1532dcc5
commit
bb4d348ccd
3 changed files with 33 additions and 5 deletions
|
|
@ -923,6 +923,7 @@ void VulkanExampleBase::handleMessages(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR
|
|||
break;
|
||||
case WM_RBUTTONDOWN:
|
||||
case WM_LBUTTONDOWN:
|
||||
case WM_MBUTTONDOWN:
|
||||
mousePos.x = (float)LOWORD(lParam);
|
||||
mousePos.y = (float)HIWORD(lParam);
|
||||
break;
|
||||
|
|
@ -951,6 +952,16 @@ void VulkanExampleBase::handleMessages(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR
|
|||
mousePos = glm::vec2((float)posx, (float)posy);
|
||||
viewChanged();
|
||||
}
|
||||
if (wParam & MK_MBUTTON)
|
||||
{
|
||||
int32_t posx = LOWORD(lParam);
|
||||
int32_t posy = HIWORD(lParam);
|
||||
cameraPos.x -= (mousePos.x - (float)posx) * 0.01f;
|
||||
cameraPos.y -= (mousePos.y - (float)posy) * 0.01f;
|
||||
viewChanged();
|
||||
mousePos.x = (float)posx;
|
||||
mousePos.y = (float)posy;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -1108,22 +1119,36 @@ void VulkanExampleBase::handleEvent(const xcb_generic_event_t *event)
|
|||
zoom += (mousePos.y - (float)motion->event_y) * .005f;
|
||||
viewChanged();
|
||||
}
|
||||
if (mouseButtons.middle)
|
||||
{
|
||||
cameraPos.x -= (mousePos.x - (float)motion->event_x) * 0.01f;
|
||||
cameraPos.y -= (mousePos.y - (float)motion->event_y) * 0.01f;
|
||||
viewChanged();
|
||||
mousePos.x = (float)motion->event_x;
|
||||
mousePos.y = (float)motion->event_y;
|
||||
}
|
||||
mousePos = glm::vec2((float)motion->event_x, (float)motion->event_y);
|
||||
}
|
||||
break;
|
||||
case XCB_BUTTON_PRESS:
|
||||
{
|
||||
xcb_button_press_event_t *press = (xcb_button_press_event_t *)event;
|
||||
mouseButtons.left = (press->detail & XCB_BUTTON_INDEX_1);
|
||||
mouseButtons.right = (press->detail & XCB_BUTTON_INDEX_3);
|
||||
if (press->detail == XCB_BUTTON_INDEX_1)
|
||||
mouseButtons.left = true;
|
||||
if (press->detail == XCB_BUTTON_INDEX_1)
|
||||
mouseButtons.middle = true;
|
||||
if (press->detail == XCB_BUTTON_INDEX_3)
|
||||
mouseButtons.right = true;
|
||||
}
|
||||
break;
|
||||
case XCB_BUTTON_RELEASE:
|
||||
{
|
||||
xcb_button_press_event_t *press = (xcb_button_press_event_t *)event;
|
||||
if (press->detail & XCB_BUTTON_INDEX_1)
|
||||
if (press->detail == XCB_BUTTON_INDEX_1)
|
||||
mouseButtons.left = false;
|
||||
if (press->detail & XCB_BUTTON_INDEX_3)
|
||||
if (press->detail == XCB_BUTTON_INDEX_1)
|
||||
mouseButtons.middle = false;
|
||||
if (press->detail == XCB_BUTTON_INDEX_3)
|
||||
mouseButtons.right = false;
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -137,6 +137,7 @@ public:
|
|||
float zoomSpeed = 1.0f;
|
||||
|
||||
glm::vec3 rotation = glm::vec3();
|
||||
glm::vec3 cameraPos = glm::vec3();
|
||||
glm::vec2 mousePos;
|
||||
|
||||
std::string title = "Vulkan Example";
|
||||
|
|
@ -172,6 +173,7 @@ public:
|
|||
struct {
|
||||
bool left = false;
|
||||
bool right = false;
|
||||
bool middle = false;
|
||||
} mouseButtons;
|
||||
bool quit;
|
||||
xcb_connection_t *connection;
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ public:
|
|||
zoom = -7.5f;
|
||||
zoomSpeed = 2.5f;
|
||||
rotation = { 0.0f, -90.0f, 0.0f };
|
||||
cameraPos = glm::vec3(2.5f, 2.5f, 0.0f);
|
||||
title = "Vulkan Example - Multisampling";
|
||||
}
|
||||
|
||||
|
|
@ -667,7 +668,7 @@ public:
|
|||
float offset = 0.5f;
|
||||
int uboIndex = 1;
|
||||
uboVS.model = glm::mat4();
|
||||
uboVS.model = viewMatrix * glm::translate(uboVS.model, glm::vec3(2.5f, 2.5f, 0.0f));
|
||||
uboVS.model = viewMatrix * glm::translate(uboVS.model, cameraPos);
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue