2024-12-01 12:08:45 +00:00
|
|
|
#include <GL/glew.h>
|
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
#include <QMouseEvent>
|
2024-12-01 11:26:14 +00:00
|
|
|
|
|
|
|
#include "part.h"
|
2024-12-01 12:08:45 +00:00
|
|
|
#include "qevent.h"
|
|
|
|
#include "qnamespace.h"
|
2024-12-01 11:26:14 +00:00
|
|
|
#include "rendering/renderer.h"
|
|
|
|
#include "physics/simulation.h"
|
|
|
|
#include "camera.h"
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
#include "mainglwidget.h"
|
|
|
|
|
|
|
|
MainGLWidget::MainGLWidget(QWidget* parent): QOpenGLWidget(parent) {}
|
|
|
|
|
|
|
|
void MainGLWidget::initializeGL() {
|
|
|
|
// Set up the rendering context, load shaders and other resources, etc.:
|
|
|
|
// QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
|
|
|
// f->glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
|
|
|
|
|
|
|
glewInit();
|
|
|
|
simulationInit();
|
|
|
|
renderInit(NULL);
|
|
|
|
|
|
|
|
// Baseplate
|
|
|
|
parts.push_back(Part {
|
|
|
|
.position = glm::vec3(0, -5, 0),
|
|
|
|
.rotation = glm::vec3(0),
|
|
|
|
.scale = glm::vec3(512, 1.2, 512),
|
|
|
|
.material = Material {
|
|
|
|
.diffuse = glm::vec3(0.388235, 0.372549, 0.384314),
|
|
|
|
.specular = glm::vec3(0.5f, 0.5f, 0.5f),
|
|
|
|
.shininess = 32.0f,
|
|
|
|
},
|
|
|
|
.anchored = true,
|
|
|
|
});
|
|
|
|
syncPartPhysics(parts.back());
|
|
|
|
|
|
|
|
parts.push_back(Part {
|
|
|
|
.position = glm::vec3(0),
|
|
|
|
.rotation = glm::vec3(0),
|
|
|
|
.scale = glm::vec3(4, 1.2, 2),
|
|
|
|
.material = Material {
|
|
|
|
.diffuse = glm::vec3(0.639216f, 0.635294f, 0.647059f),
|
|
|
|
.specular = glm::vec3(0.5f, 0.5f, 0.5f),
|
|
|
|
.shininess = 32.0f,
|
|
|
|
}
|
|
|
|
});
|
|
|
|
syncPartPhysics(parts.back());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainGLWidget::resizeGL(int w, int h) {
|
|
|
|
// Update projection matrix and other size related settings:
|
|
|
|
// m_projection.setToIdentity();
|
|
|
|
// m_projection.perspective(45.0f, w / float(h), 0.01f, 100.0f);
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainGLWidget::paintGL() {
|
|
|
|
::render(NULL);
|
|
|
|
}
|
2024-12-01 12:08:45 +00:00
|
|
|
|
|
|
|
bool isMouseDragging = false;
|
|
|
|
QPoint lastMousePos;
|
|
|
|
void MainGLWidget::mouseMoveEvent(QMouseEvent* evt) {
|
|
|
|
// if (!(evt->buttons() & Qt::RightButton)) return;
|
|
|
|
if (!isMouseDragging) return;
|
|
|
|
|
|
|
|
camera.processRotation(evt->pos().x() - lastMousePos.x(), evt->pos().y() - lastMousePos.y());
|
|
|
|
lastMousePos = evt->pos();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainGLWidget::mousePressEvent(QMouseEvent* evt) {
|
|
|
|
if (evt->button() != Qt::RightButton) return;
|
|
|
|
|
|
|
|
lastMousePos = evt->pos();
|
|
|
|
isMouseDragging = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainGLWidget::mouseReleaseEvent(QMouseEvent* evt) {
|
|
|
|
isMouseDragging = false;
|
|
|
|
}
|