2023-05-02 13:02:56 +05:00
|
|
|
#include <QtWidgets/QOpenGLWidget>
|
2023-05-03 15:57:59 +05:00
|
|
|
#include "obj.h"
|
2023-05-04 14:37:43 +05:00
|
|
|
#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) {}
|
2023-05-04 15:43:30 +05:00
|
|
|
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);
|
2023-05-02 15:44:33 +05:00
|
|
|
void reorient();
|
|
|
|
|
2023-08-03 14:43:11 +05:00
|
|
|
// camera controls
|
2023-05-04 14:37:43 +05:00
|
|
|
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-05-04 14:37:43 +05:00
|
|
|
|
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
|
|
|
};
|