Changed mouse button handling, added mouse moved event
This commit is contained in:
parent
cd8274c294
commit
83d1dd63aa
2 changed files with 44 additions and 31 deletions
|
|
@ -1125,11 +1125,26 @@ void VulkanExampleBase::handleMessages(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WM_RBUTTONDOWN:
|
|
||||||
case WM_LBUTTONDOWN:
|
case WM_LBUTTONDOWN:
|
||||||
|
mousePos = glm::vec2((float)LOWORD(lParam), (float)HIWORD(lParam));
|
||||||
|
mouseButtons.left = true;
|
||||||
|
break;
|
||||||
|
case WM_RBUTTONDOWN:
|
||||||
|
mousePos = glm::vec2((float)LOWORD(lParam), (float)HIWORD(lParam));
|
||||||
|
mouseButtons.right = true;
|
||||||
|
break;
|
||||||
case WM_MBUTTONDOWN:
|
case WM_MBUTTONDOWN:
|
||||||
mousePos.x = (float)LOWORD(lParam);
|
mousePos = glm::vec2((float)LOWORD(lParam), (float)HIWORD(lParam));
|
||||||
mousePos.y = (float)HIWORD(lParam);
|
mouseButtons.middle = true;
|
||||||
|
break;
|
||||||
|
case WM_LBUTTONUP:
|
||||||
|
mouseButtons.left = false;
|
||||||
|
break;
|
||||||
|
case WM_RBUTTONUP:
|
||||||
|
mouseButtons.right = false;
|
||||||
|
break;
|
||||||
|
case WM_MBUTTONUP:
|
||||||
|
mouseButtons.middle = false;
|
||||||
break;
|
break;
|
||||||
case WM_MOUSEWHEEL:
|
case WM_MOUSEWHEEL:
|
||||||
{
|
{
|
||||||
|
|
@ -1140,37 +1155,37 @@ void VulkanExampleBase::handleMessages(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_MOUSEMOVE:
|
case WM_MOUSEMOVE:
|
||||||
if (wParam & MK_RBUTTON)
|
|
||||||
{
|
{
|
||||||
|
bool handled = false;
|
||||||
int32_t posx = LOWORD(lParam);
|
int32_t posx = LOWORD(lParam);
|
||||||
int32_t posy = HIWORD(lParam);
|
int32_t posy = HIWORD(lParam);
|
||||||
|
mouseMoved((float)posx, (float)posy, handled);
|
||||||
|
if (handled) {
|
||||||
|
mousePos = glm::vec2((float)posx, (float)posy);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (mouseButtons.right) {
|
||||||
zoom += (mousePos.y - (float)posy) * .005f * zoomSpeed;
|
zoom += (mousePos.y - (float)posy) * .005f * zoomSpeed;
|
||||||
camera.translate(glm::vec3(-0.0f, 0.0f, (mousePos.y - (float)posy) * .005f * zoomSpeed));
|
camera.translate(glm::vec3(-0.0f, 0.0f, (mousePos.y - (float)posy) * .005f * zoomSpeed));
|
||||||
mousePos = glm::vec2((float)posx, (float)posy);
|
mousePos = glm::vec2((float)posx, (float)posy);
|
||||||
viewUpdated = true;
|
viewUpdated = true;
|
||||||
}
|
}
|
||||||
if (wParam & MK_LBUTTON)
|
if (mouseButtons.left) {
|
||||||
{
|
|
||||||
int32_t posx = LOWORD(lParam);
|
|
||||||
int32_t posy = HIWORD(lParam);
|
|
||||||
rotation.x += (mousePos.y - (float)posy) * 1.25f * rotationSpeed;
|
rotation.x += (mousePos.y - (float)posy) * 1.25f * rotationSpeed;
|
||||||
rotation.y -= (mousePos.x - (float)posx) * 1.25f * rotationSpeed;
|
rotation.y -= (mousePos.x - (float)posx) * 1.25f * rotationSpeed;
|
||||||
camera.rotate(glm::vec3((mousePos.y - (float)posy) * camera.rotationSpeed, -(mousePos.x - (float)posx) * camera.rotationSpeed, 0.0f));
|
camera.rotate(glm::vec3((mousePos.y - (float)posy) * camera.rotationSpeed, -(mousePos.x - (float)posx) * camera.rotationSpeed, 0.0f));
|
||||||
mousePos = glm::vec2((float)posx, (float)posy);
|
mousePos = glm::vec2((float)posx, (float)posy);
|
||||||
viewUpdated = true;
|
viewUpdated = true;
|
||||||
}
|
}
|
||||||
if (wParam & MK_MBUTTON)
|
if (mouseButtons.middle) {
|
||||||
{
|
|
||||||
int32_t posx = LOWORD(lParam);
|
|
||||||
int32_t posy = HIWORD(lParam);
|
|
||||||
cameraPos.x -= (mousePos.x - (float)posx) * 0.01f;
|
cameraPos.x -= (mousePos.x - (float)posx) * 0.01f;
|
||||||
cameraPos.y -= (mousePos.y - (float)posy) * 0.01f;
|
cameraPos.y -= (mousePos.y - (float)posy) * 0.01f;
|
||||||
camera.translate(glm::vec3(-(mousePos.x - (float)posx) * 0.01f, -(mousePos.y - (float)posy) * 0.01f, 0.0f));
|
camera.translate(glm::vec3(-(mousePos.x - (float)posx) * 0.01f, -(mousePos.y - (float)posy) * 0.01f, 0.0f));
|
||||||
|
mousePos = glm::vec2((float)posx, (float)posy);
|
||||||
viewUpdated = true;
|
viewUpdated = true;
|
||||||
mousePos.x = (float)posx;
|
|
||||||
mousePos.y = (float)posy;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case WM_SIZE:
|
case WM_SIZE:
|
||||||
if ((prepared) && (wParam != SIZE_MINIMIZED))
|
if ((prepared) && (wParam != SIZE_MINIMIZED))
|
||||||
{
|
{
|
||||||
|
|
@ -1899,6 +1914,8 @@ void VulkanExampleBase::viewChanged() {}
|
||||||
|
|
||||||
void VulkanExampleBase::keyPressed(uint32_t) {}
|
void VulkanExampleBase::keyPressed(uint32_t) {}
|
||||||
|
|
||||||
|
void VulkanExampleBase::mouseMoved(double x, double y, bool & handled) {}
|
||||||
|
|
||||||
void VulkanExampleBase::buildCommandBuffers() {}
|
void VulkanExampleBase::buildCommandBuffers() {}
|
||||||
|
|
||||||
void VulkanExampleBase::createCommandPool()
|
void VulkanExampleBase::createCommandPool()
|
||||||
|
|
|
||||||
|
|
@ -189,13 +189,17 @@ public:
|
||||||
VkImageView view;
|
VkImageView view;
|
||||||
} depthStencil;
|
} depthStencil;
|
||||||
|
|
||||||
// Gamepad state (only one pad supported)
|
struct {
|
||||||
struct
|
|
||||||
{
|
|
||||||
glm::vec2 axisLeft = glm::vec2(0.0f);
|
glm::vec2 axisLeft = glm::vec2(0.0f);
|
||||||
glm::vec2 axisRight = glm::vec2(0.0f);
|
glm::vec2 axisRight = glm::vec2(0.0f);
|
||||||
} gamePadState;
|
} gamePadState;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
bool left = false;
|
||||||
|
bool right = false;
|
||||||
|
bool middle = false;
|
||||||
|
} mouseButtons;
|
||||||
|
|
||||||
// OS specific
|
// OS specific
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
HWND window;
|
HWND window;
|
||||||
|
|
@ -225,19 +229,10 @@ public:
|
||||||
wl_surface *surface = nullptr;
|
wl_surface *surface = nullptr;
|
||||||
wl_shell_surface *shell_surface = nullptr;
|
wl_shell_surface *shell_surface = nullptr;
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
struct {
|
|
||||||
bool left = false;
|
|
||||||
bool right = false;
|
|
||||||
bool middle = false;
|
|
||||||
} mouseButtons;
|
|
||||||
#elif defined(_DIRECT2DISPLAY)
|
#elif defined(_DIRECT2DISPLAY)
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
#elif defined(VK_USE_PLATFORM_XCB_KHR)
|
#elif defined(VK_USE_PLATFORM_XCB_KHR)
|
||||||
struct {
|
|
||||||
bool left = false;
|
|
||||||
bool right = false;
|
|
||||||
bool middle = false;
|
|
||||||
} mouseButtons;
|
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
xcb_connection_t *connection;
|
xcb_connection_t *connection;
|
||||||
xcb_screen_t *screen;
|
xcb_screen_t *screen;
|
||||||
|
|
@ -325,9 +320,10 @@ public:
|
||||||
// Can be overriden in derived class to e.g. update uniform buffers
|
// Can be overriden in derived class to e.g. update uniform buffers
|
||||||
// Containing view dependant matrices
|
// Containing view dependant matrices
|
||||||
virtual void viewChanged();
|
virtual void viewChanged();
|
||||||
// Called if a key is pressed
|
|
||||||
/** @brief (Virtual) Called after a key was pressed, can be used to do custom key handling */
|
/** @brief (Virtual) Called after a key was pressed, can be used to do custom key handling */
|
||||||
virtual void keyPressed(uint32_t);
|
virtual void keyPressed(uint32_t);
|
||||||
|
/** @brief (Virtual) Called after th mouse cursor moved and before internal events (like camera rotation) is handled */
|
||||||
|
virtual void mouseMoved(double x, double y, bool &handled);
|
||||||
// Called when the window has been resized
|
// Called when the window has been resized
|
||||||
// Can be overriden in derived class to recreate or rebuild resources attached to the frame buffer / swapchain
|
// Can be overriden in derived class to recreate or rebuild resources attached to the frame buffer / swapchain
|
||||||
virtual void windowResized();
|
virtual void windowResized();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue