1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
#pragma once
#include <QVector>
#include <QGLWidget>
#include <QPoint>
#include <QList>
#include "SyntopiaCore/Math/Vector3.h"
#include "SyntopiaCore/Math/Matrix4.h"
#include "Object3D.h"
namespace SyntopiaCore {
namespace GLEngine {
/// Settings for the GLEngine
class Settings {
public:
// Default constructor
Settings() {
perspectiveAngle = 22.0;
nearClipping = 5.0;
farClipping = 60.0;
}
// Projection settings
double perspectiveAngle;
double nearClipping;
double farClipping;
};
/// Widget for the mini OpenGL engine.
class EngineWidget : public QGLWidget {
public:
/// Constructor
EngineWidget(QWidget* parent);
/// Destructor
~EngineWidget();
/// Use this whenever the an redraw is required.
/// Calling this function multiple times will still only result in one redraw
void requireRedraw();
void clearWorld();
void reset();
void addObject(Object3D* object);
int objectCount() const { return objects.size(); }
SyntopiaCore::Math::Vector3f getPivot() { return pivot; }
SyntopiaCore::Math::Matrix4f getRotation() { return rotation; }
SyntopiaCore::Math::Vector3f getTranslation() { return translation; }
SyntopiaCore::Math::Vector3f getCameraPosition();
SyntopiaCore::Math::Vector3f getCameraUp();
SyntopiaCore::Math::Vector3f getCameraTarget();
double getScale() { return scale; }
void setPivot(SyntopiaCore::Math::Vector3f pivot) { this->pivot = pivot; }
void setRotation(SyntopiaCore::Math::Matrix4f rotation) { this->rotation = rotation; }
void setTranslation(SyntopiaCore::Math::Vector3f translation) { this->translation = translation; }
void setScale(double scale) { this->scale = scale; }
/// RGB in [0;1]
void setBackgroundColor(double r, double g, double b) {
backgroundColor = QColor((int)(r*255.0), (int)(g*255.0), (int)(b*255.0));
};
SyntopiaCore::Math::Vector3f getBackgroundColor() {
return SyntopiaCore::Math::Vector3f(backgroundColor.red()/255,backgroundColor.green()/255,backgroundColor.blue()/255);
}
void setContextMenu(QMenu* contextMenu) { this->contextMenu = contextMenu; }
double getFOV();
QColor getVisibleForegroundColor();
void setDisabled(bool disabled) { this->disabled = disabled; }
void setFastRotate(bool enabled);
protected:
void contextMenuEvent (QContextMenuEvent* ev );
void mouseReleaseEvent ( QMouseEvent * event );
void initializeGL();
void timerEvent( QTimerEvent * );
/// Actual drawing is implemented here
void paintGL();
/// Triggers a perspective update and a redraw
void resizeGL(int w, int h);
void wheelEvent(QWheelEvent* e);
void mouseMoveEvent(QMouseEvent* e);
void rotateWorldXY(double x, double y);
void rotateWorldZ(double z);
void translateWorld(double x, double y, double z);
private:
// Creates the appropriate GL_PROJECTION matrix
void updatePerspective();
SyntopiaCore::Math::Vector3f screenTo3D(int sx, int sy, int sz);
int pendingRedraws; // the number of times we must redraw
// (when a redraw is requested we must draw two times, when double buffering)
int requiredRedraws;
Settings settings;
double scale;
double mouseSpeed;
double mouseTranslationSpeed;
double minimumScale;
QPoint oldPos;
QColor backgroundColor;
SyntopiaCore::Math::Vector3f translation;
SyntopiaCore::Math::Vector3f pivot;
SyntopiaCore::Math::Matrix4f rotation;
QList<Object3D*> objects;
QString infoText;
QMenu* contextMenu;
bool rmbDragging;
SyntopiaCore::Math::Vector3f cameraPosition;
SyntopiaCore::Math::Vector3f cameraUp;
SyntopiaCore::Math::Vector3f cameraTarget;
QTime textTimer;
bool disabled;
bool fastRotate;
bool doingRotate;
};
};
};
|