mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-24 03:21:19 +00:00
160 lines
3.9 KiB
C++
160 lines
3.9 KiB
C++
/****************************************************************************
|
|
|
|
Copyright (C) 2002-2008 Gilles Debunne. All rights reserved.
|
|
|
|
This file is part of the QGLViewer library version 2.3.6.
|
|
|
|
http://www.libqglviewer.com - contact@libqglviewer.com
|
|
|
|
This file may be used under the terms of the GNU General Public License
|
|
versions 2.0 or 3.0 as published by the Free Software Foundation and
|
|
appearing in the LICENSE file included in the packaging of this file.
|
|
In addition, as a special exception, Gilles Debunne gives you certain
|
|
additional rights, described in the file GPL_EXCEPTION in this package.
|
|
|
|
libQGLViewer uses dual licensing. Commercial/proprietary software must
|
|
purchase a libQGLViewer Commercial License.
|
|
|
|
This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|
WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*****************************************************************************/
|
|
|
|
#ifndef SIMPLEVIEWER_H
|
|
#define SIMPLEVIEWER_H
|
|
|
|
#include <QOpenGLFunctions_4_0_Core>
|
|
#include <QOpenGLVertexArrayObject>
|
|
#include <QOpenGLBuffer>
|
|
#include <QOpenGLTexture>
|
|
#include <QMatrix4x4>
|
|
#include <QGLViewer/qglviewer.h>
|
|
#include "../interfaces/visitor.h"
|
|
#include "../glnodes/glnode.h"
|
|
#include "../glnodes/scenegroup.h"
|
|
#include "../glnodes/shapes.h"
|
|
#include <stack>
|
|
|
|
QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram)
|
|
|
|
class Viewer : public QGLViewer,
|
|
protected QOpenGLFunctions_4_0_Core,
|
|
public Visitor
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
Viewer();
|
|
~Viewer();
|
|
|
|
virtual void visit(SceneGroup &s);
|
|
virtual void visit(Cube &s);
|
|
virtual void visit(Sphere &s);
|
|
|
|
public slots:
|
|
void cleanup();
|
|
void changeColor(QColor);
|
|
void setPhong(bool);
|
|
|
|
signals:
|
|
int shapeSelected(int);
|
|
|
|
protected :
|
|
virtual void draw();
|
|
virtual void drawSkybox();
|
|
virtual void init();
|
|
|
|
virtual void mouseMoveEvent(QMouseEvent* e);
|
|
virtual void mouseReleaseEvent(QMouseEvent* e);
|
|
virtual void mousePressEvent(QMouseEvent *e);
|
|
|
|
SceneGroup root;
|
|
std::stack<QMatrix4x4> modelStack;
|
|
|
|
private:
|
|
void initShaders();
|
|
void initGeometries();
|
|
void deselect();
|
|
Shape* pickGeom(int, int);
|
|
|
|
// shader switching variables and constants;
|
|
QOpenGLShaderProgram *colorPickerShaderProgram;
|
|
QOpenGLShaderProgram *textureRenderShaderprogram;
|
|
QOpenGLShaderProgram *skyboxRenderShaderProgram;
|
|
QOpenGLShaderProgram *m_program;
|
|
int m_vPositionLocation;
|
|
int m_colorLocation;
|
|
int m_projMatrixLocation;
|
|
int m_mvMatrixLocation;
|
|
|
|
int s_texCoordsLocation;
|
|
int s_vPositionLocation;
|
|
int s_mvMatrixLocation;
|
|
int s_colorLocation;
|
|
int s_projMatrixLocation;
|
|
int s_skyboxCubemapLocation;
|
|
int s_vUvLocation;
|
|
int m_vNormalLocation;
|
|
|
|
int m_isPhongLoc;
|
|
int m_isSkyLoc;
|
|
int m_lDirLoc;
|
|
int m_skyMultLoc;
|
|
int m_drawTextLoc;
|
|
int m_isLightLoc;
|
|
|
|
int m_point1Loc;
|
|
int m_point2Loc;
|
|
int m_point3Loc;
|
|
|
|
int m_c1Loc;
|
|
int m_c2Loc;
|
|
int m_c3Loc;
|
|
|
|
int m_isPickingModeLoc;
|
|
bool isPickingActivated = false;
|
|
|
|
float angle_mult;
|
|
|
|
QOpenGLTexture *s_texture;
|
|
|
|
SceneGroup* activeCell;
|
|
QColor* activeColor;
|
|
int activeShape;
|
|
|
|
enum VAO_IDs { VAO_Cube, VAO_Sphere, NumVAOs };
|
|
enum Buffer_IDs { VBO_Cube, VBO_Sphere, EBO_Sphere, NumBuffers };
|
|
|
|
GLuint m_VAOs[NumVAOs];
|
|
GLuint m_Buffers[NumBuffers];
|
|
|
|
Shape* generateShapeFromIndex(int);
|
|
|
|
enum Textures{
|
|
TEX_DRYGOUND,
|
|
TEX_GRANITEFLOOR,
|
|
TEX_GRASS,
|
|
TEX_LIMESTONEWALLS,
|
|
TEX_PIERREBOUCHARDEE,
|
|
TEX_WOODFLOOR,
|
|
|
|
TEX_LENGTH
|
|
};
|
|
|
|
QString TexturePaths[TEX_LENGTH] = {
|
|
"src/data/dry_gound.jpg",
|
|
"src/data/granite_floor.jpg",
|
|
"src/data/grass.jpg",
|
|
"src/data/limestone_walls.jpg",
|
|
"src/data/pierre_bouchardee.jpg",
|
|
"src/data/wood_floor.jpg"
|
|
};
|
|
|
|
QOpenGLTexture *TexturePrograms[TEX_LENGTH];
|
|
|
|
|
|
QQuaternion rot;
|
|
unsigned int frame;
|
|
};
|
|
|
|
#endif // SIMPLEVIEWER_H
|