mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-07 03:12:36 +01:00
Viewport movement
This commit is contained in:
parent
8110358dbf
commit
8c25712ea6
@ -1,10 +1,11 @@
|
|||||||
#include "ViewerWidget.hpp"
|
#include "ViewerWidget.hpp"
|
||||||
#include <render/Model.hpp>
|
#include <render/Model.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
ViewerWidget::ViewerWidget(QWidget* parent, const QGLWidget* shareWidget, Qt::WindowFlags f)
|
ViewerWidget::ViewerWidget(QWidget* parent, const QGLWidget* shareWidget, Qt::WindowFlags f)
|
||||||
: QGLWidget(parent, shareWidget, f), gworld(nullptr), currentModel(nullptr),
|
: QGLWidget(parent, shareWidget, f), gworld(nullptr), currentModel(nullptr),
|
||||||
viewDistance(1.f), fm(ViewerWidget::UNK)
|
viewDistance(1.f), dragging(false), fm(ViewerWidget::UNK)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,6 +43,8 @@ void ViewerWidget::paintGL()
|
|||||||
r.camera.frustum.aspectRatio = width()/(height()*1.f);
|
r.camera.frustum.aspectRatio = width()/(height()*1.f);
|
||||||
|
|
||||||
if(currentModel) {
|
if(currentModel) {
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
glm::mat4 m;
|
glm::mat4 m;
|
||||||
|
|
||||||
glUseProgram(r.worldProgram);
|
glUseProgram(r.worldProgram);
|
||||||
@ -56,7 +59,8 @@ void ViewerWidget::paintGL()
|
|||||||
glUniform1f(r.uniMatAmbient, 0.1f);
|
glUniform1f(r.uniMatAmbient, 0.1f);
|
||||||
|
|
||||||
glm::mat4 proj = r.camera.frustum.projection();
|
glm::mat4 proj = r.camera.frustum.projection();
|
||||||
glm::mat4 view = glm::lookAt(glm::vec3(0.f, viewDistance, 0.f), glm::vec3(0.f, 0.f, 0.f), glm::vec3(0.f, 0.f, 1.f));
|
glm::vec3 eye(sin(viewAngles.x) * cos(viewAngles.y), cos(viewAngles.x) * cos(viewAngles.y), sin(viewAngles.y));
|
||||||
|
glm::mat4 view = glm::lookAt(eye * viewDistance, glm::vec3(0.f, 0.f, 0.f), glm::vec3(0.f, 0.f, 1.f));
|
||||||
glUniformMatrix4fv(r.uniView, 1, GL_FALSE, glm::value_ptr(view));
|
glUniformMatrix4fv(r.uniView, 1, GL_FALSE, glm::value_ptr(view));
|
||||||
glUniformMatrix4fv(r.uniProj, 1, GL_FALSE, glm::value_ptr(proj));
|
glUniformMatrix4fv(r.uniProj, 1, GL_FALSE, glm::value_ptr(proj));
|
||||||
|
|
||||||
@ -110,3 +114,29 @@ void ViewerWidget::showTXD(const QString& file)
|
|||||||
{
|
{
|
||||||
fm = ViewerWidget::TXD;
|
fm = ViewerWidget::TXD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ViewerWidget::mousePressEvent(QMouseEvent* e)
|
||||||
|
{
|
||||||
|
dragging = true;
|
||||||
|
dstart = e->localPos();
|
||||||
|
dastart = viewAngles;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ViewerWidget::mouseReleaseEvent(QMouseEvent*)
|
||||||
|
{
|
||||||
|
dragging = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ViewerWidget::mouseMoveEvent(QMouseEvent* e)
|
||||||
|
{
|
||||||
|
if(dragging) {
|
||||||
|
auto d = e->localPos() - dstart;
|
||||||
|
viewAngles = dastart + glm::vec2(d.x(), d.y()) * 0.01f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ViewerWidget::wheelEvent(QWheelEvent* e)
|
||||||
|
{
|
||||||
|
viewDistance = qMax(viewDistance - e->angleDelta().y() / 240.f, 1.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,11 @@ class ViewerWidget : public QGLWidget
|
|||||||
Model* currentModel;
|
Model* currentModel;
|
||||||
|
|
||||||
float viewDistance;
|
float viewDistance;
|
||||||
|
glm::vec2 viewAngles;
|
||||||
|
|
||||||
|
bool dragging;
|
||||||
|
QPointF dstart;
|
||||||
|
glm::vec2 dastart;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum FileMode {
|
enum FileMode {
|
||||||
@ -45,6 +50,13 @@ signals:
|
|||||||
|
|
||||||
void fileOpened(const QString& file);
|
void fileOpened(const QString& file);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual void mousePressEvent(QMouseEvent*);
|
||||||
|
virtual void mouseReleaseEvent(QMouseEvent*);
|
||||||
|
virtual void mouseMoveEvent(QMouseEvent*);
|
||||||
|
virtual void wheelEvent(QWheelEvent*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FileMode fm;
|
FileMode fm;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user