60 lines
1.5 KiB
C++
60 lines
1.5 KiB
C++
#include "VulkanWindow.h"
|
|
#include "VulkanRenderer.h"
|
|
#include <qevent.h>
|
|
|
|
static const int KEY_ESCAPE = 16777216;
|
|
static const int KEY_W = 87;
|
|
static const int KEY_A = 65;
|
|
static const int KEY_S = 83;
|
|
static const int KEY_D = 68;
|
|
|
|
void VulkanWindow::keyPressEvent(QKeyEvent *event) {
|
|
QWindow::keyPressEvent(event);
|
|
qDebug() << "text" << event->text() << "key" << event->key() << "modifiers"
|
|
<< event->modifiers();
|
|
if (event->key() == KEY_W) {
|
|
m_worldView.moveCamera(1.f);
|
|
} else if (event->key() == KEY_S) {
|
|
m_worldView.moveCamera(-1.f);
|
|
} else if (event->key() == KEY_A) {
|
|
m_worldView.strafeCamera(-1.f);
|
|
} else if (event->key() == KEY_D) {
|
|
m_worldView.strafeCamera(1.f);
|
|
} else if (event->matches(QKeySequence::Quit) || event->key() == KEY_ESCAPE) {
|
|
close();
|
|
}
|
|
}
|
|
|
|
void VulkanWindow::mousePressEvent(QMouseEvent *e)
|
|
{
|
|
m_mousePressed = true;
|
|
m_lastMousePos = e->localPos().toPoint();
|
|
}
|
|
|
|
void VulkanWindow::mouseReleaseEvent(QMouseEvent *)
|
|
{ m_mousePressed = false;
|
|
}
|
|
|
|
void VulkanWindow::mouseMoveEvent(QMouseEvent *e)
|
|
{
|
|
if (!m_mousePressed)
|
|
return;
|
|
|
|
int dx = e->localPos().toPoint().x() - m_lastMousePos.x();
|
|
int dy = e->localPos().toPoint().y() - m_lastMousePos.y();
|
|
|
|
if (dy) {
|
|
m_worldView.pitchCamera(static_cast<float>(dy) / 10.0f);
|
|
}
|
|
|
|
if (dx) {
|
|
m_worldView.yawCamera(static_cast<float>(dx) / 10.0f);
|
|
}
|
|
|
|
m_lastMousePos = e->localPos().toPoint();
|
|
}
|
|
|
|
QVulkanWindowRenderer *VulkanWindow::createRenderer() {
|
|
return new VulkanRenderer(this, &m_worldView);
|
|
}
|