3dobj-renderer/include/opglwidget.h
2023-08-03 14:43:11 +05:00

37 lines
1.2 KiB
C++

#include <QtWidgets/QOpenGLWidget>
#include "obj.h"
#include <QKeyEvent>
#include <QMouseEvent>
class OPGLWidget : public QOpenGLWidget
{
Q_OBJECT
public:
OPGLWidget(QWidget *parent) : QOpenGLWidget(parent) {}
ObjectLoader obj;
public slots:
void paintGL(); // for repaint loop
void update_camera(); // for mouse movement
protected:
void initializeGL();
void resizeGL(int w, int h);
void reorient();
// camera controls
void keyPressEvent(QKeyEvent *event);
void keyReleaseEvent(QKeyEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
// init values
int mtl_idx = -1; // index to store current material to use
float loc[3] = {0, 0, 10}; // initial camera position
float f[3] = {0, 0, -1}; // initial camera direction
float up[3] = {0, 1, 0}; // initial camera up vector
float right[3] = {1, 0, 0}; // initial camera right vector
float vel[3] = {0, 0, 0}; // initial camera velocity
float speed = 0; // placeholder init for abs speed (for limit and slowing mostly)
bool key_states[6] = {false, false, false, false, false, false}; // camera control states
float mouse_loc_old[2]; // for calculating camera direction changes with mouse movement
};