3dobj-renderer/include/opglwidget.h

38 lines
1.2 KiB
C
Raw Normal View History

2023-05-02 13:02:56 +05:00
#include <QtWidgets/QOpenGLWidget>
2023-05-03 15:57:59 +05:00
#include "obj.h"
#include <QKeyEvent>
2023-05-04 15:01:53 +05:00
#include <QMouseEvent>
2023-05-02 13:02:56 +05:00
class OPGLWidget : public QOpenGLWidget
{
2023-05-04 13:17:42 +05:00
Q_OBJECT
2023-05-02 13:02:56 +05:00
public:
OPGLWidget(QWidget *parent) : QOpenGLWidget(parent) {}
ObjectLoader obj;
2023-05-04 13:17:42 +05:00
public slots:
2023-08-03 14:43:11 +05:00
void paintGL(); // for repaint loop
void update_camera(); // for mouse movement
2023-05-04 13:17:42 +05:00
protected:
2023-05-02 14:16:05 +05:00
void initializeGL();
void resizeGL(int w, int h);
void reorient();
2023-08-03 14:43:11 +05:00
// camera controls
void keyPressEvent(QKeyEvent *event);
void keyReleaseEvent(QKeyEvent *event);
2023-05-04 15:01:53 +05:00
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
2023-08-03 14:43:11 +05:00
// 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
2023-05-02 13:02:56 +05:00
};