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;
|
break;
|
||||||
case WM_RBUTTONDOWN:
|
case WM_RBUTTONDOWN:
|
||||||
case WM_LBUTTONDOWN:
|
case WM_LBUTTONDOWN:
|
||||||
|
case WM_MBUTTONDOWN:
|
||||||
mousePos.x = (float)LOWORD(lParam);
|
mousePos.x = (float)LOWORD(lParam);
|
||||||
mousePos.y = (float)HIWORD(lParam);
|
mousePos.y = (float)HIWORD(lParam);
|
||||||
break;
|
break;
|
||||||
|
|
@ -951,6 +952,16 @@ void VulkanExampleBase::handleMessages(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR
|
||||||
mousePos = glm::vec2((float)posx, (float)posy);
|
mousePos = glm::vec2((float)posx, (float)posy);
|
||||||
viewChanged();
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1108,22 +1119,36 @@ void VulkanExampleBase::handleEvent(const xcb_generic_event_t *event)
|
||||||
zoom += (mousePos.y - (float)motion->event_y) * .005f;
|
zoom += (mousePos.y - (float)motion->event_y) * .005f;
|
||||||
viewChanged();
|
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);
|
mousePos = glm::vec2((float)motion->event_x, (float)motion->event_y);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case XCB_BUTTON_PRESS:
|
case XCB_BUTTON_PRESS:
|
||||||
{
|
{
|
||||||
xcb_button_press_event_t *press = (xcb_button_press_event_t *)event;
|
xcb_button_press_event_t *press = (xcb_button_press_event_t *)event;
|
||||||
mouseButtons.left = (press->detail & XCB_BUTTON_INDEX_1);
|
if (press->detail == XCB_BUTTON_INDEX_1)
|
||||||
mouseButtons.right = (press->detail & XCB_BUTTON_INDEX_3);
|
mouseButtons.left = true;
|
||||||
|
if (press->detail == XCB_BUTTON_INDEX_1)
|
||||||
|
mouseButtons.middle = true;
|
||||||
|
if (press->detail == XCB_BUTTON_INDEX_3)
|
||||||
|
mouseButtons.right = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case XCB_BUTTON_RELEASE:
|
case XCB_BUTTON_RELEASE:
|
||||||
{
|
{
|
||||||
xcb_button_press_event_t *press = (xcb_button_press_event_t *)event;
|
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;
|
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;
|
mouseButtons.right = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -137,6 +137,7 @@ public:
|
||||||
float zoomSpeed = 1.0f;
|
float zoomSpeed = 1.0f;
|
||||||
|
|
||||||
glm::vec3 rotation = glm::vec3();
|
glm::vec3 rotation = glm::vec3();
|
||||||
|
glm::vec3 cameraPos = glm::vec3();
|
||||||
glm::vec2 mousePos;
|
glm::vec2 mousePos;
|
||||||
|
|
||||||
std::string title = "Vulkan Example";
|
std::string title = "Vulkan Example";
|
||||||
|
|
@ -172,6 +173,7 @@ public:
|
||||||
struct {
|
struct {
|
||||||
bool left = false;
|
bool left = false;
|
||||||
bool right = false;
|
bool right = false;
|
||||||
|
bool middle = false;
|
||||||
} mouseButtons;
|
} mouseButtons;
|
||||||
bool quit;
|
bool quit;
|
||||||
xcb_connection_t *connection;
|
xcb_connection_t *connection;
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,7 @@ public:
|
||||||
zoom = -7.5f;
|
zoom = -7.5f;
|
||||||
zoomSpeed = 2.5f;
|
zoomSpeed = 2.5f;
|
||||||
rotation = { 0.0f, -90.0f, 0.0f };
|
rotation = { 0.0f, -90.0f, 0.0f };
|
||||||
|
cameraPos = glm::vec3(2.5f, 2.5f, 0.0f);
|
||||||
title = "Vulkan Example - Multisampling";
|
title = "Vulkan Example - Multisampling";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -667,7 +668,7 @@ public:
|
||||||
float offset = 0.5f;
|
float offset = 0.5f;
|
||||||
int uboIndex = 1;
|
int uboIndex = 1;
|
||||||
uboVS.model = glm::mat4();
|
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.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.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));
|
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