Compare commits
16 Commits
Version_1.
...
Version_1.
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f47e1cc76a | ||
![]() |
2d335474bf | ||
![]() |
a07d8acbec | ||
![]() |
800a6a50f8 | ||
![]() |
94a2fa59ec | ||
![]() |
648b805daf | ||
![]() |
92245be302 | ||
![]() |
333eca25eb | ||
![]() |
b17ab3f8e9 | ||
![]() |
ff08ee7cea | ||
![]() |
8346e5916d | ||
![]() |
5372838420 | ||
![]() |
a14229aa71 | ||
![]() |
1c5631a5e0 | ||
![]() |
bc5bfc62bc | ||
![]() |
4cb070c8c5 |
26
QtMeshViewer/Header/CameraInterface.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include <QMatrix4x4>
|
||||
|
||||
class CameraInterface
|
||||
{
|
||||
public:
|
||||
explicit CameraInterface() {};
|
||||
virtual ~CameraInterface() {};
|
||||
|
||||
// attributes
|
||||
protected:
|
||||
QMatrix4x4 m_matrix;
|
||||
double m_zSpeed = 1.0;
|
||||
|
||||
// functions
|
||||
public:
|
||||
virtual void setZoomSpeed(int percent) { m_zSpeed = (double) percent / 100; };
|
||||
|
||||
virtual void rotateAction(QVector2D diff) = 0;
|
||||
virtual void moveAction(QVector2D diff) = 0;
|
||||
virtual void wheelAction(double value) = 0;
|
||||
virtual void resetView() { m_matrix = QMatrix4x4(); };
|
||||
|
||||
virtual void recalculateMatrix() = 0;
|
||||
virtual QMatrix4x4 getMatrix() { recalculateMatrix(); return m_matrix; };
|
||||
};
|
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <QOpenGlTexture>
|
||||
#include <fstream>
|
||||
#include <QFile>
|
||||
#include <QVector>
|
||||
#include <QVector2D>
|
||||
#include <QMatrix4x4>
|
||||
@@ -21,17 +21,17 @@ struct VertexData
|
||||
};
|
||||
|
||||
struct Segment {
|
||||
std::uint32_t textureIndex = 0;
|
||||
quint32 textureIndex = 0;
|
||||
QVector<VertexData> vertices;
|
||||
QVector<GLuint> indices;
|
||||
};
|
||||
|
||||
struct Model {
|
||||
std::string name = "";
|
||||
std::string parent = "";
|
||||
QString name = "";
|
||||
QString parent = "";
|
||||
QMatrix4x4 m4x4Translation;
|
||||
QQuaternion quadRotation;
|
||||
std::vector<Segment*> segmList;
|
||||
QVector<Segment*> segmList;
|
||||
};
|
||||
|
||||
struct Material {
|
||||
@@ -48,8 +48,8 @@ struct Material {
|
||||
float shininess = 80;
|
||||
bool flags[8] = { false };
|
||||
bool transparent = false;
|
||||
std::uint8_t rendertype = 0;
|
||||
std::uint8_t dataValues[2] = { 0 };
|
||||
quint8 rendertype = 0;
|
||||
quint8 dataValues[2] = { 0 };
|
||||
};
|
||||
|
||||
class FileInterface
|
||||
@@ -61,9 +61,9 @@ public:
|
||||
, m_materials(new QVector<Material>)
|
||||
{
|
||||
//open file
|
||||
m_file.open(path.toStdString().c_str(), std::ios::in | std::ios::binary);
|
||||
m_file.setFileName(path);
|
||||
|
||||
if (!m_file.is_open())
|
||||
if (!m_file.open(QIODevice::ReadOnly))
|
||||
throw std::invalid_argument(std::string("ERROR: file not found: ") += path.toStdString());
|
||||
|
||||
m_filepath = path.left(path.lastIndexOf(QRegExp("/|\\\\")));
|
||||
@@ -94,7 +94,7 @@ public:
|
||||
|
||||
protected:
|
||||
QVector<Model*>* m_models;
|
||||
std::fstream m_file;
|
||||
QFile m_file;
|
||||
QVector<Material>* m_materials;
|
||||
BoundingBox m_sceneBbox;
|
||||
QString m_filepath;
|
||||
|
23
QtMeshViewer/Header/FreeCamera.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include "CameraInterface.h"
|
||||
|
||||
|
||||
class FreeCamera : public CameraInterface
|
||||
{
|
||||
public:
|
||||
explicit FreeCamera();
|
||||
virtual ~FreeCamera();
|
||||
|
||||
// attributes
|
||||
private:
|
||||
QVector3D m_translation;
|
||||
QQuaternion m_rotation;
|
||||
|
||||
// functions
|
||||
public:
|
||||
virtual void rotateAction(QVector2D diff) Q_DECL_OVERRIDE;
|
||||
virtual void moveAction(QVector2D diff) Q_DECL_OVERRIDE;
|
||||
virtual void wheelAction(double value) Q_DECL_OVERRIDE;
|
||||
virtual void recalculateMatrix() Q_DECL_OVERRIDE;
|
||||
virtual void resetView() Q_DECL_OVERRIDE;
|
||||
};
|
26
QtMeshViewer/Header/MoveCamera.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include "CameraInterface.h"
|
||||
|
||||
|
||||
class MoveCamera : public CameraInterface
|
||||
{
|
||||
public:
|
||||
explicit MoveCamera();
|
||||
virtual ~MoveCamera();
|
||||
|
||||
// attributes
|
||||
private:
|
||||
QVector3D m_position;
|
||||
double m_phi;
|
||||
double m_theta;
|
||||
int m_forwardSpeed;
|
||||
int m_sidewardSpeed;
|
||||
|
||||
// functions
|
||||
public:
|
||||
virtual void rotateAction(QVector2D diff) Q_DECL_OVERRIDE;
|
||||
virtual void moveAction(QVector2D diff) Q_DECL_OVERRIDE;
|
||||
virtual void wheelAction(double value) Q_DECL_OVERRIDE;
|
||||
virtual void recalculateMatrix() Q_DECL_OVERRIDE;
|
||||
virtual void resetView() Q_DECL_OVERRIDE;
|
||||
};
|
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
#include "..\Header\FileInterface.h"
|
||||
|
||||
#include <QList>
|
||||
|
||||
struct ChunkHeader {
|
||||
char name[5];
|
||||
std::uint32_t size;
|
||||
std::streampos position;
|
||||
QString name;
|
||||
quint32 size;
|
||||
qint64 position;
|
||||
};
|
||||
|
||||
enum ModelTyp {
|
||||
@@ -29,22 +29,22 @@ private:
|
||||
|
||||
virtual void import() Q_DECL_OVERRIDE Q_DECL_FINAL;
|
||||
|
||||
void loadChunks(std::list<ChunkHeader*> &destination, std::streampos start, const std::uint32_t length);
|
||||
void loadChunks(QList<ChunkHeader*> &destination, qint64 start, const quint32 length);
|
||||
|
||||
void analyseMsh2Chunks(std::list<ChunkHeader*> &chunkList);
|
||||
void analyseMsh2Chunks(QList<ChunkHeader*> &chunkList);
|
||||
|
||||
void analyseMatdChunks(std::list<ChunkHeader*> &chunkList);
|
||||
void analyseMatdChunks(QList<ChunkHeader*> &chunkList);
|
||||
|
||||
void analyseModlChunks(Model* dataDestination, std::list<ChunkHeader*> &chunkList);
|
||||
void analyseGeomChunks(Model* dataDestination, std::list<ChunkHeader*> &chunkList);
|
||||
void analyseSegmChunks(Model* dataDestination, std::list<ChunkHeader*> &chunkList);
|
||||
void analyseClthChunks(Model* dataDestination, std::list<ChunkHeader*> &chunkList);
|
||||
void analyseModlChunks(Model* dataDestination, QList<ChunkHeader*> &chunkList);
|
||||
void analyseGeomChunks(Model* dataDestination, QList<ChunkHeader*> &chunkList);
|
||||
void analyseSegmChunks(Model* dataDestination, QList<ChunkHeader*> &chunkList);
|
||||
void analyseClthChunks(Model* dataDestination, QList<ChunkHeader*> &chunkList);
|
||||
|
||||
void readVertex(Segment* dataDestination, std::streampos position);
|
||||
void readUV(Segment* dataDestination, std::streampos position);
|
||||
void readVertex(Segment* dataDestination, qint64 position);
|
||||
void readUV(Segment* dataDestination, qint64 position);
|
||||
|
||||
void loadTexture(QOpenGLTexture*& destination, QString filepath, QString& filename);
|
||||
|
||||
QMatrix4x4 getParentMatrix(std::string parent) const;
|
||||
QQuaternion getParentRotation(std::string parent) const;
|
||||
QMatrix4x4 getParentMatrix(QString parent) const;
|
||||
QQuaternion getParentRotation(QString parent) const;
|
||||
};
|
@@ -5,6 +5,7 @@
|
||||
#include <QMatrix4x4>
|
||||
#include "GeometryEngine.h"
|
||||
#include "SettingsWindow.h"
|
||||
#include "CameraInterface.h"
|
||||
|
||||
|
||||
class GeometryEngine;
|
||||
@@ -37,25 +38,16 @@ private:
|
||||
bool headlight = false;
|
||||
} m_light;
|
||||
|
||||
SettingsWindow* m_settings;
|
||||
|
||||
struct {
|
||||
bool left = false;
|
||||
bool right = false;
|
||||
QVector2D position;
|
||||
} m_mouse;
|
||||
|
||||
struct {
|
||||
bool x = true;
|
||||
bool y = true;
|
||||
bool z = true;
|
||||
} m_rotDirections;
|
||||
|
||||
QMatrix4x4 m_projection;
|
||||
QVector3D m_translation;
|
||||
QQuaternion m_rotation;
|
||||
CameraInterface* m_camera;
|
||||
|
||||
double m_zSpeed = 1.0;
|
||||
SettingsWindow* m_settings;
|
||||
|
||||
// functions
|
||||
private:
|
||||
@@ -74,6 +66,7 @@ protected:
|
||||
void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE;
|
||||
|
||||
void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
|
||||
void keyReleaseEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
|
||||
|
||||
void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE;
|
||||
void dropEvent(QDropEvent * event) Q_DECL_OVERRIDE;
|
||||
@@ -81,10 +74,13 @@ protected:
|
||||
// slots
|
||||
public slots:
|
||||
void loadFile(QString name);
|
||||
void toggleAxis(int axis);
|
||||
void useFreeCamera();
|
||||
void useOrbitCamera();
|
||||
void useMoveCamera();
|
||||
void toggleWireframe();
|
||||
void toggleLight();
|
||||
void showSettings();
|
||||
|
||||
void setBGColorOff(QVector3D value);
|
||||
void setBGColorOn(QVector3D value);
|
||||
void setLightColor(QVector3D value);
|
||||
@@ -92,7 +88,6 @@ public slots:
|
||||
void setAmbCoef(double value);
|
||||
void setHeadlight(bool value);
|
||||
void setBackfaceCulling(bool value);
|
||||
void setZoomSpeed(int percent);
|
||||
|
||||
};
|
||||
|
||||
|
24
QtMeshViewer/Header/OrbitCamera.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include "CameraInterface.h"
|
||||
|
||||
|
||||
class OrbitCamera : public CameraInterface
|
||||
{
|
||||
public:
|
||||
explicit OrbitCamera();
|
||||
virtual ~OrbitCamera();
|
||||
|
||||
// attributes
|
||||
private:
|
||||
double m_phi;
|
||||
double m_theta;
|
||||
double m_roh;
|
||||
|
||||
// functions
|
||||
public:
|
||||
virtual void rotateAction(QVector2D diff) Q_DECL_OVERRIDE;
|
||||
virtual void moveAction(QVector2D diff) Q_DECL_OVERRIDE;
|
||||
virtual void wheelAction(double value) Q_DECL_OVERRIDE;
|
||||
virtual void recalculateMatrix() Q_DECL_OVERRIDE;
|
||||
virtual void resetView() Q_DECL_OVERRIDE;
|
||||
};
|
@@ -1,36 +1,38 @@
|
||||
#pragma once
|
||||
#include <fstream>
|
||||
#include "OutputDevice.h"
|
||||
#include <QImage>
|
||||
#include <QColor>
|
||||
#include <QVector>
|
||||
#include <QFile>
|
||||
|
||||
|
||||
QImage loadTga(QString filePath, bool &success)
|
||||
{
|
||||
QImage img;
|
||||
success = true;
|
||||
|
||||
// open the file
|
||||
std::fstream fsPicture(filePath.toStdString().c_str(), std::ios::in | std::ios::binary);
|
||||
QFile file(filePath);
|
||||
|
||||
if (!fsPicture.is_open())
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
img = QImage(1, 1, QImage::Format_RGB32);
|
||||
img.fill(Qt::red);
|
||||
success = false;
|
||||
return img;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// read in the header
|
||||
std::uint8_t ui8x18Header[19] = { 0 };
|
||||
fsPicture.read(reinterpret_cast<char*>(&ui8x18Header), sizeof(ui8x18Header) - 1);
|
||||
quint8 ui8x18Header[19] = { 0 };
|
||||
file.read(reinterpret_cast<char*>(&ui8x18Header), sizeof(ui8x18Header) - 1);
|
||||
|
||||
//get variables
|
||||
std::uint32_t ui32BpP;
|
||||
std::uint32_t ui32Width;
|
||||
std::uint32_t ui32Height;
|
||||
std::uint32_t ui32IDLength;
|
||||
std::uint32_t ui32PicType;
|
||||
std::uint32_t ui32PaletteLength;
|
||||
std::uint32_t ui32Size;
|
||||
quint32 ui32BpP;
|
||||
quint32 ui32Width;
|
||||
quint32 ui32Height;
|
||||
quint32 ui32IDLength;
|
||||
quint32 ui32PicType;
|
||||
quint32 ui32PaletteLength;
|
||||
quint32 ui32Size;
|
||||
|
||||
// extract all information from header
|
||||
ui32IDLength = ui8x18Header[0];
|
||||
@@ -44,58 +46,47 @@ QImage loadTga(QString filePath, bool &success)
|
||||
ui32Size = ui32Width * ui32Height * ui32BpP / 8;
|
||||
|
||||
// jump to the data block
|
||||
fsPicture.seekg(ui32IDLength + ui32PaletteLength, std::ios_base::cur);
|
||||
|
||||
img = QImage(ui32Width, ui32Height, QImage::Format_RGBA8888);
|
||||
file.seek(ui32IDLength + ui32PaletteLength + 18);
|
||||
|
||||
// uncompressed
|
||||
if (ui32PicType == 2 && (ui32BpP == 24 || ui32BpP == 32))
|
||||
{
|
||||
std::vector<std::uint8_t> vui8Pixels;
|
||||
vui8Pixels.resize(ui32Size);
|
||||
fsPicture.read(reinterpret_cast<char*>(vui8Pixels.data()), ui32Size);
|
||||
img = QImage(ui32Width, ui32Height, ui32BpP == 32 ? QImage::Format_RGBA8888 : QImage::Format_RGB888);
|
||||
int lineWidth = ui32Width * ui32BpP / 8;
|
||||
|
||||
for (unsigned int y = 0; y < ui32Height; y++)
|
||||
{
|
||||
for (unsigned int x = 0; x < ui32Width; x++)
|
||||
{
|
||||
int valr = vui8Pixels.at(y * ui32Width * ui32BpP / 8 + x * ui32BpP / 8 + 2);
|
||||
int valg = vui8Pixels.at(y * ui32Width * ui32BpP / 8 + x * ui32BpP / 8 + 1);
|
||||
int valb = vui8Pixels.at(y * ui32Width * ui32BpP / 8 + x * ui32BpP / 8);
|
||||
int vala = 255;
|
||||
if (ui32BpP == 32)
|
||||
vala = vui8Pixels.at(y * ui32Width * ui32BpP / 8 + x * ui32BpP / 8 + 3);
|
||||
for (int i = ui32Height - 1; i >= 0; --i)
|
||||
file.read(reinterpret_cast<char*>(img.scanLine(i)), lineWidth);
|
||||
|
||||
QColor value(valr, valg, valb, vala);
|
||||
img.setPixel(x, ui32Width - 1 - y, value.rgba());
|
||||
}
|
||||
}
|
||||
}
|
||||
// else if compressed 24 or 32 bit
|
||||
else if (ui32PicType == 10 && (ui32BpP == 24 || ui32BpP == 32)) // compressed
|
||||
{
|
||||
std::uint8_t tempChunkHeader;
|
||||
std::uint8_t tempData[5];
|
||||
OutputDevice::getInstance()->print("compressed tga is not supported by SWBF", 1);
|
||||
|
||||
img = QImage(ui32Width, ui32Height, QImage::Format_RGBA8888);
|
||||
|
||||
quint8 tempChunkHeader;
|
||||
quint8 tempData[5];
|
||||
unsigned int tmp_pixelIndex = 0;
|
||||
|
||||
do {
|
||||
fsPicture.read(reinterpret_cast<char*>(&tempChunkHeader), sizeof(tempChunkHeader));
|
||||
file.read(reinterpret_cast<char*>(&tempChunkHeader), sizeof(tempChunkHeader));
|
||||
|
||||
if (tempChunkHeader >> 7) // repeat count
|
||||
{
|
||||
// just use the first 7 bits
|
||||
tempChunkHeader = (uint8_t(tempChunkHeader << 1) >> 1);
|
||||
tempChunkHeader = (quint8(tempChunkHeader << 1) >> 1);
|
||||
|
||||
fsPicture.read(reinterpret_cast<char*>(&tempData), ui32BpP / 8);
|
||||
file.read(reinterpret_cast<char*>(&tempData), ui32BpP / 8);
|
||||
|
||||
for (int i = 0; i <= tempChunkHeader; i++)
|
||||
{
|
||||
QColor color;
|
||||
|
||||
if (ui32BpP == 32)
|
||||
color.setRgba(qRgba(tempData[2], tempData[1], tempData[0], tempData[3]));
|
||||
color.setRgba(qRgba(tempData[0], tempData[1], tempData[2], tempData[3]));
|
||||
else
|
||||
color.setRgba(qRgba(tempData[2], tempData[1], tempData[0], 255));
|
||||
color.setRgba(qRgba(tempData[0], tempData[1], tempData[2], 255));
|
||||
|
||||
img.setPixel(tmp_pixelIndex % ui32Width, ui32Height - 1 - (tmp_pixelIndex / ui32Width), color.rgba());
|
||||
tmp_pixelIndex++;
|
||||
@@ -108,14 +99,14 @@ QImage loadTga(QString filePath, bool &success)
|
||||
|
||||
for (int i = 0; i <= tempChunkHeader; i++)
|
||||
{
|
||||
fsPicture.read(reinterpret_cast<char*>(&tempData), ui32BpP / 8);
|
||||
file.read(reinterpret_cast<char*>(&tempData), ui32BpP / 8);
|
||||
|
||||
QColor color;
|
||||
|
||||
if (ui32BpP == 32)
|
||||
color.setRgba(qRgba(tempData[2], tempData[1], tempData[0], tempData[3]));
|
||||
color.setRgba(qRgba(tempData[0], tempData[1], tempData[2], tempData[3]));
|
||||
else
|
||||
color.setRgba(qRgba(tempData[2], tempData[1], tempData[0], 255));
|
||||
color.setRgba(qRgba(tempData[0], tempData[1], tempData[2], 255));
|
||||
|
||||
img.setPixel(tmp_pixelIndex % ui32Width, ui32Height - 1 - (tmp_pixelIndex / ui32Width), color.rgba());
|
||||
tmp_pixelIndex++;
|
||||
@@ -126,13 +117,12 @@ QImage loadTga(QString filePath, bool &success)
|
||||
// not useable format
|
||||
else
|
||||
{
|
||||
fsPicture.close();
|
||||
success = false;
|
||||
return img;
|
||||
}
|
||||
}
|
||||
|
||||
fsPicture.close();
|
||||
success = true;
|
||||
return img;
|
||||
if (file.isOpen())
|
||||
file.close();
|
||||
return qMove(img).rgbSwapped();
|
||||
|
||||
}
|
||||
|
@@ -15,17 +15,14 @@
|
||||
<file>info.png</file>
|
||||
<file>about.png</file>
|
||||
<file>open.png</file>
|
||||
<file>X.png</file>
|
||||
<file>Y.png</file>
|
||||
<file>Z.png</file>
|
||||
<file>screenshot.png</file>
|
||||
<file>wireframe.png</file>
|
||||
<file>light_off.png</file>
|
||||
<file>light_on.png</file>
|
||||
<file>solid.png</file>
|
||||
<file>X_disabled.png</file>
|
||||
<file>Y_disabled.png</file>
|
||||
<file>Z_disabled.png</file>
|
||||
<file>settings.png</file>
|
||||
<file>freeCamera.png</file>
|
||||
<file>orbitalCamera.png</file>
|
||||
<file>walkCamera.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@@ -37,28 +37,16 @@ QToolButton#screenshot {
|
||||
image: url(:/images/toolbar/screenshot.png);
|
||||
}
|
||||
|
||||
QToolButton#x {
|
||||
image: url(:/images/toolbar/X_disabled.png);
|
||||
QToolButton#freeCamera {
|
||||
image: url(:/images/toolbar/freeCamera.png);
|
||||
}
|
||||
|
||||
QToolButton#x:checked {
|
||||
image: url(:/images/toolbar/X.png);
|
||||
QToolButton#orbitalCamera {
|
||||
image: url(:/images/toolbar/orbitalCamera.png);
|
||||
}
|
||||
|
||||
QToolButton#y {
|
||||
image: url(:/images/toolbar/Y_disabled.png);
|
||||
}
|
||||
|
||||
QToolButton#y:checked {
|
||||
image: url(:/images/toolbar/Y.png);
|
||||
}
|
||||
|
||||
QToolButton#z {
|
||||
image: url(:/images/toolbar/Z_disabled.png);
|
||||
}
|
||||
|
||||
QToolButton#z:checked {
|
||||
image: url(:/images/toolbar/Z.png);
|
||||
QToolButton#walkCamera {
|
||||
image: url(:/images/toolbar/walkCamera.png);
|
||||
}
|
||||
|
||||
QToolButton#wireframe {
|
||||
|
@@ -4,9 +4,22 @@ source code: https://git.rwth-aachen.de/carstenf/OpenGL/tree/master/QtMeshViewer
|
||||
|
||||
===============================================================
|
||||
Controll:
|
||||
|
||||
Free Camera: static view position and you rotate and move the object
|
||||
left mouse - rotate
|
||||
right mouse - move
|
||||
scroll - zoom
|
||||
|
||||
Orbit Camera: static object and you move around it like a satalite
|
||||
left mouse - rotate
|
||||
scroll - zoom
|
||||
|
||||
Move Camera: static object and you can walk through the scene
|
||||
w/s - forward/backward
|
||||
a/d - left/right
|
||||
left mouse - look around
|
||||
|
||||
General:
|
||||
space - reset view
|
||||
L - set light to current position
|
||||
esc - close
|
||||
|
BIN
QtMeshViewer/Resources/freeCamera.png
Normal file
After Width: | Height: | Size: 964 B |
BIN
QtMeshViewer/Resources/orbitalCamera.png
Normal file
After Width: | Height: | Size: 993 B |
BIN
QtMeshViewer/Resources/walkCamera.png
Normal file
After Width: | Height: | Size: 924 B |
53
QtMeshViewer/Source/FreeCamera.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "..\Header\FreeCamera.h"
|
||||
#include <QVector2D>
|
||||
#include <QVector3D>
|
||||
#include <QQuaternion>
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// constructor/destructor
|
||||
|
||||
FreeCamera::FreeCamera()
|
||||
{
|
||||
resetView();
|
||||
}
|
||||
|
||||
FreeCamera::~FreeCamera()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// functions
|
||||
|
||||
void FreeCamera::rotateAction(QVector2D diff)
|
||||
{
|
||||
m_rotation = QQuaternion::fromAxisAndAngle(QVector3D(diff.y(), diff.x(), 0.0).normalized(), diff.length() * 0.5) * m_rotation;
|
||||
}
|
||||
|
||||
void FreeCamera::moveAction(QVector2D diff)
|
||||
{
|
||||
m_translation += {(float)(diff.x() * 0.01), (float)(diff.y() * -0.01), 0.0};
|
||||
}
|
||||
|
||||
void FreeCamera::wheelAction(double value)
|
||||
{
|
||||
m_translation += {0.0, 0.0, (float) (m_zSpeed * value / 240)};
|
||||
}
|
||||
|
||||
void FreeCamera::recalculateMatrix()
|
||||
{
|
||||
m_matrix = QMatrix4x4();
|
||||
|
||||
m_matrix.translate(m_translation);
|
||||
m_matrix.rotate(m_rotation);
|
||||
}
|
||||
|
||||
void FreeCamera::resetView()
|
||||
{
|
||||
m_translation = { 0, 0, -4 };
|
||||
m_rotation = QQuaternion();
|
||||
|
||||
CameraInterface::resetView();
|
||||
}
|
@@ -5,6 +5,7 @@
|
||||
#include "..\Header\OutputDevice.h"
|
||||
#include <QRegExp>
|
||||
|
||||
#include "..\Header\Profiler.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// constructor/destructor
|
||||
@@ -140,6 +141,7 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
|
||||
|
||||
void GeometryEngine::loadFile(QString filePath)
|
||||
{
|
||||
TIC("Start");
|
||||
// cleanup old stuff and recreate buffers
|
||||
clearData();
|
||||
m_arrayBuf.create();
|
||||
@@ -214,5 +216,7 @@ void GeometryEngine::loadFile(QString filePath)
|
||||
clearData();
|
||||
OutputDevice::getInstance()->print(QString(e.what()), 2);
|
||||
}
|
||||
|
||||
TOC("End");
|
||||
}
|
||||
|
||||
|
@@ -36,9 +36,6 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
// setup opengl things
|
||||
QSurfaceFormat format;
|
||||
format.setDepthBufferSize(24);
|
||||
format.setMajorVersion(2);
|
||||
format.setMinorVersion(0);
|
||||
format.setProfile(QSurfaceFormat::NoProfile);
|
||||
QSurfaceFormat::setDefaultFormat(format);
|
||||
|
||||
// set default text to file info
|
||||
@@ -90,41 +87,26 @@ void MainWindow::setupWidgets()
|
||||
//////////////////////////////////////////////////
|
||||
ui->mainToolBar->addSeparator();
|
||||
|
||||
QSignalMapper* signalMapper = new QSignalMapper(this);
|
||||
// Free Camera
|
||||
QToolButton *freeCamera = new QToolButton(this);
|
||||
freeCamera->setObjectName("freeCamera");
|
||||
freeCamera->setToolTip("free camera");
|
||||
connect(freeCamera, &QToolButton::pressed, viewer, &OglViewerWidget::useFreeCamera);
|
||||
ui->mainToolBar->addWidget(freeCamera);
|
||||
|
||||
// X
|
||||
QToolButton *x = new QToolButton(this);
|
||||
x->setObjectName("x");
|
||||
x->setToolTip("x-direction");
|
||||
x->setCheckable(true);
|
||||
x->setChecked(true);
|
||||
ui->mainToolBar->addWidget(x);
|
||||
// Orbital Camera
|
||||
QToolButton *orbitCamera = new QToolButton(this);
|
||||
orbitCamera->setObjectName("orbitalCamera");
|
||||
orbitCamera->setToolTip("orbital camera");
|
||||
connect(orbitCamera, &QToolButton::pressed, viewer, &OglViewerWidget::useOrbitCamera);
|
||||
ui->mainToolBar->addWidget(orbitCamera);
|
||||
|
||||
// Y
|
||||
QToolButton *y = new QToolButton(this);
|
||||
y->setObjectName("y");
|
||||
y->setToolTip("y-direction");
|
||||
y->setCheckable(true);
|
||||
y->setChecked(true);
|
||||
ui->mainToolBar->addWidget(y);
|
||||
|
||||
// Z
|
||||
QToolButton *z = new QToolButton(this);
|
||||
z->setObjectName("z");
|
||||
z->setToolTip("z-direction");
|
||||
z->setCheckable(true);
|
||||
z->setChecked(true);
|
||||
ui->mainToolBar->addWidget(z);
|
||||
|
||||
connect(x, SIGNAL(pressed()), signalMapper, SLOT(map()));
|
||||
connect(y, SIGNAL(pressed()), signalMapper, SLOT(map()));
|
||||
connect(z, SIGNAL(pressed()), signalMapper, SLOT(map()));
|
||||
|
||||
signalMapper->setMapping(x, 1);
|
||||
signalMapper->setMapping(y, 2);
|
||||
signalMapper->setMapping(z, 3);
|
||||
|
||||
connect(signalMapper, SIGNAL(mapped(int)), viewer, SLOT(toggleAxis(int)));
|
||||
// Move Camera
|
||||
QToolButton *walkCamera = new QToolButton(this);
|
||||
walkCamera->setObjectName("walkCamera");
|
||||
walkCamera->setToolTip("walk camera");
|
||||
connect(walkCamera, &QToolButton::pressed, viewer, &OglViewerWidget::useMoveCamera);
|
||||
ui->mainToolBar->addWidget(walkCamera);
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
ui->mainToolBar->addSeparator();
|
||||
|
82
QtMeshViewer/Source/MoveCamera.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
#include "..\Header\MoveCamera.h"
|
||||
#include <QVector2D>
|
||||
#include <qmath.h>
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// constructor/destructor
|
||||
|
||||
MoveCamera::MoveCamera()
|
||||
{
|
||||
resetView();
|
||||
}
|
||||
|
||||
MoveCamera::~MoveCamera()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// functions
|
||||
|
||||
void MoveCamera::rotateAction(QVector2D diff)
|
||||
{
|
||||
m_phi -= diff.x() * 0.01;
|
||||
m_theta += diff.y() * 0.01;
|
||||
|
||||
m_theta = qMax(qMin(M_PI - 0.0001, m_theta), 0.0001);
|
||||
}
|
||||
|
||||
void MoveCamera::moveAction(QVector2D diff)
|
||||
{
|
||||
if (diff.y() > 0)
|
||||
m_sidewardSpeed = 1;
|
||||
else if (diff.y() < 0)
|
||||
m_sidewardSpeed = -1;
|
||||
else
|
||||
m_sidewardSpeed = 0;
|
||||
}
|
||||
|
||||
void MoveCamera::wheelAction(double value)
|
||||
{
|
||||
if (value > 0)
|
||||
m_forwardSpeed = 1;
|
||||
else if (value < 0)
|
||||
m_forwardSpeed = -1;
|
||||
else
|
||||
m_forwardSpeed = 0;
|
||||
}
|
||||
|
||||
void MoveCamera::recalculateMatrix()
|
||||
{
|
||||
m_matrix = QMatrix4x4();
|
||||
|
||||
// different coordinate (spherical -> world) X->Z | Y->X | Z->Y
|
||||
QVector3D tmpdirection(
|
||||
qSin(m_theta) * qSin(m_phi),
|
||||
qCos(m_theta),
|
||||
qSin(m_theta) * qCos(m_phi)
|
||||
);
|
||||
|
||||
QVector3D tmpRight(
|
||||
qSin(m_phi - M_PI_2),
|
||||
0,
|
||||
qCos(m_phi - M_PI_2)
|
||||
);
|
||||
|
||||
m_position += m_forwardSpeed * m_zSpeed * 0.1 * tmpdirection;
|
||||
m_position += m_sidewardSpeed * m_zSpeed * 0.1 * tmpRight;
|
||||
|
||||
m_matrix.lookAt(m_position, m_position + tmpdirection, QVector3D::crossProduct(tmpRight, tmpdirection));
|
||||
}
|
||||
|
||||
void MoveCamera::resetView()
|
||||
{
|
||||
m_position = { 0,0,4 };
|
||||
m_phi = M_PI;
|
||||
m_theta = M_PI_2;
|
||||
m_forwardSpeed = 0;
|
||||
m_sidewardSpeed = 0;
|
||||
CameraInterface::resetView();
|
||||
}
|
@@ -1,7 +1,6 @@
|
||||
#include "..\Header\MshFile.h"
|
||||
#include "..\Header\tga.h"
|
||||
#include "..\Header\OutputDevice.h"
|
||||
#include <QColor>
|
||||
|
||||
|
||||
// helper function to save data from file to any variable type
|
||||
@@ -28,22 +27,22 @@ MshFile::~MshFile()
|
||||
void MshFile::import()
|
||||
{
|
||||
// go to file size information
|
||||
m_file.seekg(4);
|
||||
m_file.seek(4);
|
||||
|
||||
std::uint32_t tmp_fileSize;
|
||||
std::list<ChunkHeader*> tmp_mainChunks;
|
||||
quint32 tmp_fileSize;
|
||||
QList<ChunkHeader*> tmp_mainChunks;
|
||||
|
||||
// get all chunks under HEDR
|
||||
m_file.read(F2V(tmp_fileSize), sizeof(tmp_fileSize));
|
||||
loadChunks(tmp_mainChunks, m_file.tellg(), tmp_fileSize);
|
||||
loadChunks(tmp_mainChunks, m_file.pos(), tmp_fileSize);
|
||||
|
||||
// evaulate HEDR subchunks (= find MSH2)
|
||||
for (ChunkHeader* it : tmp_mainChunks)
|
||||
{
|
||||
if (!strcmp("MSH2", it->name))
|
||||
if ("MSH2" == it->name)
|
||||
{
|
||||
// get all subchunks
|
||||
std::list<ChunkHeader*> tmp_msh2Chunks;
|
||||
QList<ChunkHeader*> tmp_msh2Chunks;
|
||||
loadChunks(tmp_msh2Chunks, it->position, it->size);
|
||||
|
||||
// evaluate MSH2 subchunks
|
||||
@@ -68,54 +67,57 @@ void MshFile::import()
|
||||
}
|
||||
}
|
||||
|
||||
void MshFile::loadChunks(std::list<ChunkHeader*>& destination, std::streampos start, const std::uint32_t length)
|
||||
void MshFile::loadChunks(QList<ChunkHeader*>& destination, qint64 start, const quint32 length)
|
||||
{
|
||||
// jump to first chunk
|
||||
m_file.seekg(start);
|
||||
m_file.seek(start);
|
||||
|
||||
do
|
||||
{
|
||||
// out of file. Maybe a size information is corrupted
|
||||
if (m_file.atEnd() || m_file.error() != QFileDevice::NoError)
|
||||
{
|
||||
OutputDevice::getInstance()->print("WARNING: corrupted file. Trying to continue..", 1);
|
||||
m_file.unsetError();
|
||||
m_file.seek(0);
|
||||
break;
|
||||
}
|
||||
|
||||
ChunkHeader* tmp_header = new ChunkHeader();
|
||||
|
||||
// get information
|
||||
m_file.read(F2V(tmp_header->name[0]), sizeof(tmp_header->name) - 1);
|
||||
char tmpName[5] = { 0 };
|
||||
m_file.read(F2V(tmpName[0]), sizeof(tmpName) -1);
|
||||
tmp_header->name = QString(tmpName);
|
||||
m_file.read(F2V(tmp_header->size), sizeof(tmp_header->size));
|
||||
tmp_header->position = m_file.tellg();
|
||||
tmp_header->position = m_file.pos();
|
||||
|
||||
// store information
|
||||
destination.push_back(tmp_header);
|
||||
|
||||
// jump to next header
|
||||
m_file.seekg(tmp_header->size, std::ios_base::cur);
|
||||
m_file.seek(tmp_header->size + m_file.pos());
|
||||
|
||||
// out of file. Maybe a size information is corrupted
|
||||
if (!m_file.good())
|
||||
{
|
||||
OutputDevice::getInstance()->print("WARNING: corrupted file. Trying to continue..", 1);
|
||||
m_file.clear();
|
||||
break;
|
||||
}
|
||||
|
||||
} while (m_file.tellg() - start != length);
|
||||
} while (m_file.pos() - start != length);
|
||||
}
|
||||
|
||||
void MshFile::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
|
||||
void MshFile::analyseMsh2Chunks(QList<ChunkHeader*>& chunkList)
|
||||
{
|
||||
for (auto& it : chunkList)
|
||||
{
|
||||
// scene information
|
||||
if (!strcmp("SINF", it->name))
|
||||
if ("SINF" == it->name)
|
||||
{
|
||||
// get SINF subchunks
|
||||
std::list<ChunkHeader*> tmp_sinfChunks;
|
||||
QList<ChunkHeader*> tmp_sinfChunks;
|
||||
loadChunks(tmp_sinfChunks, it->position, it->size);
|
||||
|
||||
// evaluate SINF subchunks
|
||||
for (auto& it : tmp_sinfChunks)
|
||||
{
|
||||
if (!strcmp("BBOX", it->name))
|
||||
if ("BBOX" == it->name)
|
||||
{
|
||||
m_file.seekg(it->position);
|
||||
m_file.seek(it->position);
|
||||
|
||||
// read in the quaternion
|
||||
float tmp_quat[4];
|
||||
@@ -143,24 +145,25 @@ void MshFile::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
|
||||
}
|
||||
|
||||
// material list
|
||||
else if (!strcmp("MATL", it->name))
|
||||
else if ("MATL" == it->name)
|
||||
{
|
||||
OutputDevice::getInstance()->print("loading materials..", 0);
|
||||
// "useless" information how many MATD follow, jump over it
|
||||
m_file.seekg(it->position);
|
||||
m_file.seekg(sizeof(std::uint32_t), std::ios_base::cur);
|
||||
m_file.seek(it->position);
|
||||
m_file.seek(sizeof(quint32) + m_file.pos());
|
||||
|
||||
// get all MATL subchunk
|
||||
std::list<ChunkHeader*> tmp_matlChunks;
|
||||
loadChunks(tmp_matlChunks, m_file.tellg(), it->size - 4);
|
||||
QList<ChunkHeader*> tmp_matlChunks;
|
||||
loadChunks(tmp_matlChunks, m_file.pos(), it->size - 4);
|
||||
|
||||
// evaluate MATL subchunks
|
||||
for (auto& it : tmp_matlChunks)
|
||||
{
|
||||
// This shouldn't be anything else than MATD
|
||||
if (!strcmp("MATD", it->name))
|
||||
if ("MATD" == it->name)
|
||||
{
|
||||
// get all subchunks from MATD
|
||||
std::list<ChunkHeader*> tmp_matdChunks;
|
||||
QList<ChunkHeader*> tmp_matdChunks;
|
||||
loadChunks(tmp_matdChunks, it->position, it->size);
|
||||
|
||||
m_materials->push_back(Material());
|
||||
@@ -188,14 +191,15 @@ void MshFile::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
|
||||
}
|
||||
|
||||
// model
|
||||
else if (!strcmp("MODL", it->name))
|
||||
else if ("MODL" == it->name)
|
||||
{
|
||||
OutputDevice::getInstance()->print("loading model..", 0);
|
||||
Model* new_model = new Model;
|
||||
m_currentType = ModelTyp::null;
|
||||
m_currentRenderFlag = -1;
|
||||
|
||||
// get all MODL subchunks
|
||||
std::list<ChunkHeader*> tmp_chunks;
|
||||
QList<ChunkHeader*> tmp_chunks;
|
||||
loadChunks(tmp_chunks, it->position, it->size);
|
||||
|
||||
// evaluate MODL subchunks
|
||||
@@ -215,14 +219,14 @@ void MshFile::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
|
||||
}
|
||||
}
|
||||
|
||||
void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
|
||||
void MshFile::analyseMatdChunks(QList<ChunkHeader*>& chunkList)
|
||||
{
|
||||
for (auto& it : chunkList)
|
||||
{
|
||||
// name
|
||||
if (!strcmp("NAME", it->name))
|
||||
if ("NAME" == it->name)
|
||||
{
|
||||
m_file.seekg(it->position);
|
||||
m_file.seek(it->position);
|
||||
char* buffer = new char[it->size + 1];
|
||||
*buffer = { 0 };
|
||||
m_file.read(buffer, it->size);
|
||||
@@ -231,9 +235,9 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
|
||||
}
|
||||
|
||||
// data
|
||||
else if(!strcmp("DATA", it->name))
|
||||
else if("DATA" == it->name)
|
||||
{
|
||||
m_file.seekg(it->position);
|
||||
m_file.seek(it->position);
|
||||
|
||||
// diffuse
|
||||
for (unsigned int i = 0; i < 4; i++)
|
||||
@@ -252,18 +256,18 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
|
||||
}
|
||||
|
||||
// attributes
|
||||
else if (!strcmp("ATRB", it->name))
|
||||
else if ("ATRB" == it->name)
|
||||
{
|
||||
// get pointer to current material
|
||||
Material* curMat = &m_materials->back();
|
||||
|
||||
// read the attributes
|
||||
m_file.seekg(it->position);
|
||||
std::uint8_t flag;
|
||||
m_file.seek(it->position);
|
||||
quint8 flag;
|
||||
m_file.read(F2V(flag), sizeof(flag));
|
||||
m_file.read(F2V(curMat->rendertype), sizeof(std::uint8_t));
|
||||
m_file.read(F2V(curMat->dataValues[0]), sizeof(std::uint8_t));
|
||||
m_file.read(F2V(curMat->dataValues[1]), sizeof(std::uint8_t));
|
||||
m_file.read(F2V(curMat->rendertype), sizeof(quint8));
|
||||
m_file.read(F2V(curMat->dataValues[0]), sizeof(quint8));
|
||||
m_file.read(F2V(curMat->dataValues[1]), sizeof(quint8));
|
||||
|
||||
// flags
|
||||
// 0: emissive
|
||||
@@ -276,16 +280,16 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
|
||||
// 7: specular
|
||||
|
||||
for (unsigned int i = 0; i < 8; i++)
|
||||
curMat->flags[i] = (std::uint8_t)(flag << (7 - i)) >> 7;
|
||||
curMat->flags[i] = (quint8)(flag << (7 - i)) >> 7;
|
||||
|
||||
curMat->transparent = curMat->flags[2] || curMat->flags[3] || curMat->flags[4] || curMat->flags[6] || curMat->rendertype == 4;
|
||||
}
|
||||
|
||||
// texture 0
|
||||
else if (!strcmp("TX0D", it->name))
|
||||
else if ("TX0D" == it->name)
|
||||
{
|
||||
// get the texture name
|
||||
m_file.seekg(it->position);
|
||||
m_file.seek(it->position);
|
||||
char* buffer = new char[it->size + 1];
|
||||
*buffer = { 0 };
|
||||
m_file.read(buffer, it->size);
|
||||
@@ -298,10 +302,10 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
|
||||
}
|
||||
|
||||
// texture 1
|
||||
else if (!strcmp("TX1D", it->name))
|
||||
else if ("TX1D" == it->name)
|
||||
{
|
||||
// get the texture name
|
||||
m_file.seekg(it->position);
|
||||
m_file.seek(it->position);
|
||||
char* buffer = new char[it->size + 1];
|
||||
*buffer = { 0 };
|
||||
m_file.read(buffer, it->size);
|
||||
@@ -313,10 +317,10 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
|
||||
}
|
||||
|
||||
// texture 2
|
||||
else if (!strcmp("TX2D", it->name))
|
||||
else if ("TX2D" == it->name)
|
||||
{
|
||||
// get the texture name
|
||||
m_file.seekg(it->position);
|
||||
m_file.seek(it->position);
|
||||
char* buffer = new char[it->size + 1];
|
||||
*buffer = { 0 };
|
||||
m_file.read(buffer, it->size);
|
||||
@@ -325,10 +329,10 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
|
||||
}
|
||||
|
||||
// texture 3
|
||||
else if (!strcmp("TX3D", it->name))
|
||||
else if ("TX3D" == it->name)
|
||||
{
|
||||
// get the texture name
|
||||
m_file.seekg(it->position);
|
||||
m_file.seek(it->position);
|
||||
char* buffer = new char[it->size + 1];
|
||||
*buffer = { 0 };
|
||||
m_file.read(buffer, it->size);
|
||||
@@ -338,23 +342,23 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
|
||||
}
|
||||
}
|
||||
|
||||
void MshFile::analyseModlChunks(Model * dataDestination, std::list<ChunkHeader*>& chunkList)
|
||||
void MshFile::analyseModlChunks(Model * dataDestination, QList<ChunkHeader*>& chunkList)
|
||||
{
|
||||
for (auto& it : chunkList)
|
||||
{
|
||||
// model type
|
||||
if (!strcmp("MTYP", it->name))
|
||||
if ("MTYP" == it->name)
|
||||
{
|
||||
m_file.seekg(it->position);
|
||||
std::uint32_t tmp_type;
|
||||
m_file.seek(it->position);
|
||||
quint32 tmp_type;
|
||||
m_file.read(F2V(tmp_type), sizeof(tmp_type));
|
||||
m_currentType = (ModelTyp)tmp_type;
|
||||
}
|
||||
|
||||
// parent name
|
||||
else if (!strcmp("PRNT", it->name))
|
||||
else if ("PRNT" == it->name)
|
||||
{
|
||||
m_file.seekg(it->position);
|
||||
m_file.seek(it->position);
|
||||
char* buffer = new char[it->size + 1];
|
||||
*buffer = { 0 };
|
||||
m_file.read(buffer, it->size);
|
||||
@@ -363,9 +367,9 @@ void MshFile::analyseModlChunks(Model * dataDestination, std::list<ChunkHeader*>
|
||||
}
|
||||
|
||||
// model name
|
||||
else if (!strcmp("NAME", it->name))
|
||||
else if ("NAME" == it->name)
|
||||
{
|
||||
m_file.seekg(it->position);
|
||||
m_file.seek(it->position);
|
||||
char* buffer = new char[it->size + 1];
|
||||
*buffer = { 0 };
|
||||
m_file.read(buffer, it->size);
|
||||
@@ -374,20 +378,20 @@ void MshFile::analyseModlChunks(Model * dataDestination, std::list<ChunkHeader*>
|
||||
}
|
||||
|
||||
// render flags
|
||||
else if (!strcmp("FLGS", it->name))
|
||||
else if ("FLGS" == it->name)
|
||||
{
|
||||
m_file.seekg(it->position);
|
||||
m_file.seek(it->position);
|
||||
m_file.read(F2V(m_currentRenderFlag), sizeof(m_currentRenderFlag));
|
||||
}
|
||||
|
||||
// translation
|
||||
else if (!strcmp("TRAN", it->name))
|
||||
else if ("TRAN" == it->name)
|
||||
{
|
||||
float tmp_scale[3];
|
||||
float tmp_rotation[4];
|
||||
float tmp_trans[3];
|
||||
|
||||
m_file.seekg(it->position);
|
||||
m_file.seek(it->position);
|
||||
|
||||
// read in the data
|
||||
for (int i = 0; i < 3; i++)
|
||||
@@ -410,14 +414,14 @@ void MshFile::analyseModlChunks(Model * dataDestination, std::list<ChunkHeader*>
|
||||
}
|
||||
|
||||
// geometry data
|
||||
else if (!strcmp("GEOM", it->name))
|
||||
else if ("GEOM" == it->name)
|
||||
{
|
||||
// don't get null, bone, shadowMesh and hidden mesh indices
|
||||
if (m_currentType == null || m_currentType == bone || m_currentType == shadowMesh || m_currentRenderFlag == 1)
|
||||
continue;
|
||||
|
||||
// get all GEOM subchunks
|
||||
std::list<ChunkHeader*> tmp_geomChunks;
|
||||
QList<ChunkHeader*> tmp_geomChunks;
|
||||
loadChunks(tmp_geomChunks, it->position, it->size);
|
||||
|
||||
// evaluate GEOM subchunks
|
||||
@@ -434,15 +438,15 @@ void MshFile::analyseModlChunks(Model * dataDestination, std::list<ChunkHeader*>
|
||||
}
|
||||
}
|
||||
|
||||
void MshFile::analyseGeomChunks(Model * dataDestination, std::list<ChunkHeader*>& chunkList)
|
||||
void MshFile::analyseGeomChunks(Model * dataDestination, QList<ChunkHeader*>& chunkList)
|
||||
{
|
||||
for (auto& it : chunkList)
|
||||
{
|
||||
// segment
|
||||
if (!strcmp("SEGM", it->name))
|
||||
if ("SEGM" == it->name)
|
||||
{
|
||||
// get all SEGM subchunks
|
||||
std::list<ChunkHeader*> tmp_segmChunks;
|
||||
QList<ChunkHeader*> tmp_segmChunks;
|
||||
loadChunks(tmp_segmChunks, it->position, it->size);
|
||||
|
||||
// evaluate SEGM subchunks
|
||||
@@ -458,10 +462,10 @@ void MshFile::analyseGeomChunks(Model * dataDestination, std::list<ChunkHeader*>
|
||||
}
|
||||
|
||||
// cloth
|
||||
else if (!strcmp("CLTH", it->name))
|
||||
else if ("CLTH" == it->name)
|
||||
{
|
||||
// get all CLTH subchunks
|
||||
std::list<ChunkHeader*> tmp_clthChunks;
|
||||
QList<ChunkHeader*> tmp_clthChunks;
|
||||
loadChunks(tmp_clthChunks, it->position, it->size);
|
||||
|
||||
// evaluate CLTH subchunks
|
||||
@@ -478,30 +482,30 @@ void MshFile::analyseGeomChunks(Model * dataDestination, std::list<ChunkHeader*>
|
||||
}
|
||||
}
|
||||
|
||||
void MshFile::analyseSegmChunks(Model * dataDestination, std::list<ChunkHeader*>& chunkList)
|
||||
void MshFile::analyseSegmChunks(Model * dataDestination, QList<ChunkHeader*>& chunkList)
|
||||
{
|
||||
Segment* new_segment = new Segment;
|
||||
|
||||
for (auto& it : chunkList)
|
||||
{
|
||||
// material index
|
||||
if (!strcmp("MATI", it->name))
|
||||
if ("MATI" == it->name)
|
||||
{
|
||||
m_file.seekg(it->position);
|
||||
m_file.seek(it->position);
|
||||
m_file.read(F2V(new_segment->textureIndex), sizeof(new_segment->textureIndex));
|
||||
}
|
||||
|
||||
// position list (vertex)
|
||||
else if (!strcmp("POSL", it->name))
|
||||
else if ("POSL" == it->name)
|
||||
{
|
||||
readVertex(new_segment, it->position);
|
||||
}
|
||||
|
||||
// normals
|
||||
else if (!strcmp("NRML", it->name))
|
||||
else if ("NRML" == it->name)
|
||||
{
|
||||
std::uint32_t tmp_size;
|
||||
m_file.seekg(it->position);
|
||||
quint32 tmp_size;
|
||||
m_file.seek(it->position);
|
||||
m_file.read(F2V(tmp_size), sizeof(tmp_size));
|
||||
|
||||
if (tmp_size < (unsigned) new_segment->vertices.size())
|
||||
@@ -525,18 +529,18 @@ void MshFile::analyseSegmChunks(Model * dataDestination, std::list<ChunkHeader*>
|
||||
}
|
||||
|
||||
// uv
|
||||
else if (!strcmp("UV0L", it->name))
|
||||
else if ("UV0L" == it->name)
|
||||
{
|
||||
readUV(new_segment, it->position);
|
||||
}
|
||||
|
||||
// polygons (indices into vertex/uv list)
|
||||
else if (!strcmp("STRP", it->name))
|
||||
else if ("STRP" == it->name)
|
||||
{
|
||||
|
||||
// jump to the data section and read the size;
|
||||
std::uint32_t tmp_size;
|
||||
m_file.seekg(it->position);
|
||||
quint32 tmp_size;
|
||||
m_file.seek(it->position);
|
||||
m_file.read(F2V(tmp_size), sizeof(tmp_size));
|
||||
|
||||
int highBitCount(0);
|
||||
@@ -545,7 +549,7 @@ void MshFile::analyseSegmChunks(Model * dataDestination, std::list<ChunkHeader*>
|
||||
for (unsigned int i = 0; i < tmp_size; i++)
|
||||
{
|
||||
// ReadData
|
||||
std::uint16_t tmp_value;
|
||||
quint16 tmp_value;
|
||||
m_file.read(F2V(tmp_value), sizeof(tmp_value));
|
||||
|
||||
// Check if highbit is set
|
||||
@@ -553,7 +557,7 @@ void MshFile::analyseSegmChunks(Model * dataDestination, std::list<ChunkHeader*>
|
||||
{
|
||||
highBitCount++;
|
||||
// remove the high bit, to get the actually value
|
||||
tmp_value = (std::uint16_t(tmp_value << 1) >> 1);
|
||||
tmp_value = (quint16(tmp_value << 1) >> 1);
|
||||
}
|
||||
|
||||
// save data
|
||||
@@ -607,17 +611,17 @@ void MshFile::analyseSegmChunks(Model * dataDestination, std::list<ChunkHeader*>
|
||||
dataDestination->segmList.push_back(new_segment);
|
||||
}
|
||||
|
||||
void MshFile::analyseClthChunks(Model * dataDestination, std::list<ChunkHeader*>& chunkList)
|
||||
void MshFile::analyseClthChunks(Model * dataDestination, QList<ChunkHeader*>& chunkList)
|
||||
{
|
||||
Segment* new_segment = new Segment;
|
||||
|
||||
for (auto& it : chunkList)
|
||||
{
|
||||
// texture name
|
||||
if (!strcmp("CTEX", it->name))
|
||||
if ("CTEX" == it->name)
|
||||
{
|
||||
// read the texture name
|
||||
m_file.seekg(it->position);
|
||||
m_file.seek(it->position);
|
||||
char* buffer = new char[it->size + 1];
|
||||
*buffer = { 0 };
|
||||
m_file.read(buffer, it->size);
|
||||
@@ -638,30 +642,30 @@ void MshFile::analyseClthChunks(Model * dataDestination, std::list<ChunkHeader*>
|
||||
}
|
||||
|
||||
// position list (vertex)
|
||||
else if (!strcmp("CPOS", it->name))
|
||||
else if ("CPOS" == it->name)
|
||||
{
|
||||
readVertex(new_segment, it->position);
|
||||
}
|
||||
|
||||
// uv
|
||||
else if (!strcmp("CUV0", it->name))
|
||||
else if ("CUV0" == it->name)
|
||||
{
|
||||
readUV(new_segment, it->position);
|
||||
}
|
||||
|
||||
// triangles (indices into vertex/uv list)
|
||||
else if (!strcmp("CMSH", it->name))
|
||||
else if ("CMSH" == it->name)
|
||||
{
|
||||
// jump to the data section and read the size;
|
||||
std::uint32_t tmp_size;
|
||||
m_file.seekg(it->position);
|
||||
quint32 tmp_size;
|
||||
m_file.seek(it->position);
|
||||
m_file.read(F2V(tmp_size), sizeof(tmp_size));
|
||||
|
||||
// for every triangle..
|
||||
for (unsigned int i = 0; i < tmp_size * 3; i++)
|
||||
{
|
||||
std::uint32_t tmp_value;
|
||||
m_file.read(F2V(tmp_value), sizeof(std::uint32_t));
|
||||
quint32 tmp_value;
|
||||
m_file.read(F2V(tmp_value), sizeof(quint32));
|
||||
|
||||
new_segment->indices.push_back((GLuint)tmp_value);
|
||||
}
|
||||
@@ -671,10 +675,10 @@ void MshFile::analyseClthChunks(Model * dataDestination, std::list<ChunkHeader*>
|
||||
dataDestination->segmList.push_back(new_segment);
|
||||
}
|
||||
|
||||
void MshFile::readVertex(Segment * dataDestination, std::streampos position)
|
||||
void MshFile::readVertex(Segment * dataDestination, qint64 position)
|
||||
{
|
||||
std::uint32_t tmp_size;
|
||||
m_file.seekg(position);
|
||||
quint32 tmp_size;
|
||||
m_file.seek(position);
|
||||
m_file.read(F2V(tmp_size), sizeof(tmp_size));
|
||||
|
||||
for (unsigned int i = 0; i < tmp_size; i++)
|
||||
@@ -690,10 +694,10 @@ void MshFile::readVertex(Segment * dataDestination, std::streampos position)
|
||||
}
|
||||
}
|
||||
|
||||
void MshFile::readUV(Segment * dataDestination, std::streampos position)
|
||||
void MshFile::readUV(Segment * dataDestination, qint64 position)
|
||||
{
|
||||
std::uint32_t tmp_size;
|
||||
m_file.seekg(position);
|
||||
quint32 tmp_size;
|
||||
m_file.seek(position);
|
||||
m_file.read(F2V(tmp_size), sizeof(tmp_size));
|
||||
|
||||
if (tmp_size < (unsigned) dataDestination->vertices.size())
|
||||
@@ -746,13 +750,13 @@ void MshFile::loadTexture(QOpenGLTexture *& destination, QString filepath, QStri
|
||||
destination = new_texture;
|
||||
}
|
||||
|
||||
QMatrix4x4 MshFile::getParentMatrix(std::string parent) const
|
||||
QMatrix4x4 MshFile::getParentMatrix(QString parent) const
|
||||
{
|
||||
QMatrix4x4 matrix;
|
||||
|
||||
for (auto& it : *m_models)
|
||||
{
|
||||
if (!strcmp(parent.c_str(), it->name.c_str()))
|
||||
if (parent == it->name)
|
||||
{
|
||||
matrix = getParentMatrix(it->parent) * it->m4x4Translation;
|
||||
break;
|
||||
@@ -762,13 +766,13 @@ QMatrix4x4 MshFile::getParentMatrix(std::string parent) const
|
||||
return matrix;
|
||||
}
|
||||
|
||||
QQuaternion MshFile::getParentRotation(std::string parent) const
|
||||
QQuaternion MshFile::getParentRotation(QString parent) const
|
||||
{
|
||||
QQuaternion rotation;
|
||||
|
||||
for (auto& it : *m_models)
|
||||
{
|
||||
if (!strcmp(parent.c_str(), it->name.c_str()))
|
||||
if (parent == it->name)
|
||||
{
|
||||
rotation = getParentRotation(it->parent) * it->quadRotation;
|
||||
break;
|
||||
|
@@ -1,5 +1,8 @@
|
||||
#include "..\Header\OglViewerWidget.h"
|
||||
#include "..\Header\MainWindow.h"
|
||||
#include "..\Header\FreeCamera.h"
|
||||
#include "..\Header\OrbitCamera.h"
|
||||
#include "..\Header\MoveCamera.h"
|
||||
#include <QMouseEvent>
|
||||
#include <QDropEvent>
|
||||
#include <QMimeData>
|
||||
@@ -14,7 +17,8 @@
|
||||
|
||||
OglViewerWidget::OglViewerWidget(QWidget *parent)
|
||||
: QOpenGLWidget(parent)
|
||||
, m_dataEngine(0)
|
||||
, m_dataEngine(Q_NULLPTR)
|
||||
, m_camera(new FreeCamera)
|
||||
{
|
||||
setFocus();
|
||||
setAcceptDrops(true);
|
||||
@@ -29,7 +33,7 @@ OglViewerWidget::OglViewerWidget(QWidget *parent)
|
||||
connect(m_settings, &SettingsWindow::updateAmbCoef, this, &OglViewerWidget::setAmbCoef);
|
||||
connect(m_settings, &SettingsWindow::sendHeadlight, this, &OglViewerWidget::setHeadlight);
|
||||
connect(m_settings, &SettingsWindow::sendBackfaceCulling, this, &OglViewerWidget::setBackfaceCulling);
|
||||
connect(m_settings, &SettingsWindow::sendZommSpeed, this, &OglViewerWidget::setZoomSpeed);
|
||||
connect(m_settings, &SettingsWindow::sendZommSpeed, [this](int value) {m_camera->setZoomSpeed(value); });
|
||||
}
|
||||
|
||||
OglViewerWidget::~OglViewerWidget()
|
||||
@@ -40,6 +44,7 @@ OglViewerWidget::~OglViewerWidget()
|
||||
delete m_dataEngine;
|
||||
doneCurrent();
|
||||
|
||||
delete m_camera;
|
||||
delete m_settings;
|
||||
}
|
||||
|
||||
@@ -68,9 +73,7 @@ void OglViewerWidget::initShaders()
|
||||
|
||||
void OglViewerWidget::resetView()
|
||||
{
|
||||
m_rotation = QQuaternion();
|
||||
m_translation = { 0.0, 0.0, DEFAULT_Z_DISTANCE };
|
||||
m_zSpeed = 1;
|
||||
m_camera->resetView();
|
||||
|
||||
if (m_light.headlight)
|
||||
updateLightPosition();
|
||||
@@ -79,13 +82,13 @@ void OglViewerWidget::resetView()
|
||||
|
||||
void OglViewerWidget::updateLightPosition()
|
||||
{
|
||||
QMatrix4x4 rotateBack;
|
||||
rotateBack.rotate(m_rotation.inverted());
|
||||
QVector3D cameraPosition = rotateBack * (-m_translation);
|
||||
QVector4D lightPosition = { 0,0,0,1 };
|
||||
|
||||
m_light.position.setX(cameraPosition.x());
|
||||
m_light.position.setY(cameraPosition.y());
|
||||
m_light.position.setZ(cameraPosition.z());
|
||||
lightPosition = m_camera->getMatrix().inverted() * lightPosition;
|
||||
|
||||
m_light.position.setX(lightPosition.x());
|
||||
m_light.position.setY(lightPosition.y());
|
||||
m_light.position.setZ(lightPosition.z());
|
||||
}
|
||||
|
||||
// OpenGL ///////////////////////////////////////////////////////////////
|
||||
@@ -139,13 +142,8 @@ void OglViewerWidget::paintGL()
|
||||
// Clear color and depth buffer
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Calculate view transformation
|
||||
QMatrix4x4 view;
|
||||
view.translate(m_translation);
|
||||
view.rotate(m_rotation);
|
||||
|
||||
// Set view-projection matrix
|
||||
m_program.setUniformValue("vp_matrix", m_projection * view);
|
||||
m_program.setUniformValue("vp_matrix", m_projection * m_camera->getMatrix());
|
||||
|
||||
// Set Light values
|
||||
m_program.setUniformValue("b_light", m_lightOn);
|
||||
@@ -155,9 +153,7 @@ void OglViewerWidget::paintGL()
|
||||
m_program.setUniformValue("light.ambientCoefficient", m_light.ambientCoefficient);
|
||||
|
||||
// Set camera position
|
||||
QMatrix4x4 rotateBack;
|
||||
rotateBack.rotate(m_rotation.inverted());
|
||||
m_program.setUniformValue("cameraPosition", rotateBack * (-m_translation));
|
||||
m_program.setUniformValue("cameraPosition", (m_camera->getMatrix().inverted() * QVector4D(0,0,0,1)).toVector3D());
|
||||
|
||||
// Draw cube geometry
|
||||
if (m_backfaceCulling)
|
||||
@@ -199,76 +195,11 @@ void OglViewerWidget::mouseMoveEvent(QMouseEvent *e)
|
||||
if (m_mouse.left)
|
||||
{
|
||||
// get the difference between last press and now
|
||||
QVector2D diff = QVector2D(e->localPos()) - m_mouse.position;
|
||||
m_camera->rotateAction(QVector2D(e->localPos()) - m_mouse.position);
|
||||
|
||||
// update the new position
|
||||
m_mouse.position = QVector2D(e->localPos());
|
||||
|
||||
// calculate the rotations depending on the active axis
|
||||
// XYZ
|
||||
if (m_rotDirections.x && m_rotDirections.y && m_rotDirections.z)
|
||||
{
|
||||
m_rotation = QQuaternion::fromAxisAndAngle(QVector3D(diff.y(), diff.x(), 0.0).normalized(), diff.length() * 0.5) * m_rotation;
|
||||
}
|
||||
// XY
|
||||
else if (m_rotDirections.x && m_rotDirections.y && !m_rotDirections.z)
|
||||
{
|
||||
|
||||
float pitch, yaw, roll;
|
||||
m_rotation.getEulerAngles(&pitch, &yaw, &roll);
|
||||
|
||||
pitch += diff.y() * 0.5;
|
||||
yaw += diff.x() * 0.5;
|
||||
|
||||
if (pitch > 89)
|
||||
pitch = 89;
|
||||
else if (pitch < -89)
|
||||
pitch = -89;
|
||||
|
||||
m_rotation = QQuaternion::fromEulerAngles(pitch, yaw, roll);
|
||||
|
||||
}
|
||||
// X
|
||||
else if (m_rotDirections.x && !m_rotDirections.y && !m_rotDirections.z)
|
||||
{
|
||||
m_rotation = QQuaternion::fromAxisAndAngle(QVector3D(0.0, 1.0, 0.0).normalized(), diff.x() * 0.5) * m_rotation;
|
||||
}
|
||||
// Y
|
||||
else if (!m_rotDirections.x && m_rotDirections.y && !m_rotDirections.z)
|
||||
{
|
||||
m_rotation = QQuaternion::fromAxisAndAngle(QVector3D(1.0, 0.0, 0.0).normalized(), diff.y() * 0.5) * m_rotation;
|
||||
}
|
||||
// Z
|
||||
else if (!m_rotDirections.x && !m_rotDirections.y && m_rotDirections.z)
|
||||
{
|
||||
m_rotation = QQuaternion::fromAxisAndAngle(QVector3D(0.0, 0.0, 1.0).normalized(), diff.x() * 0.5) * m_rotation;
|
||||
}
|
||||
// XZ
|
||||
else if (m_rotDirections.x && !m_rotDirections.y && m_rotDirections.z)
|
||||
{
|
||||
float pitch, yaw, roll;
|
||||
m_rotation.getEulerAngles(&pitch, &yaw, &roll);
|
||||
roll -= diff.y() * 0.5;
|
||||
yaw += diff.x() * 0.5;
|
||||
|
||||
m_rotation = QQuaternion::fromEulerAngles(pitch, yaw, roll);
|
||||
}
|
||||
// YZ
|
||||
else if (!m_rotDirections.x && m_rotDirections.y && m_rotDirections.z)
|
||||
{
|
||||
float pitch, yaw, roll;
|
||||
m_rotation.getEulerAngles(&pitch, &yaw, &roll);
|
||||
pitch += diff.y() * 0.5;
|
||||
roll += diff.x() * 0.5;
|
||||
|
||||
if (pitch > 89)
|
||||
pitch = 89;
|
||||
else if (pitch < -89)
|
||||
pitch = -89;
|
||||
|
||||
m_rotation = QQuaternion::fromEulerAngles(pitch, yaw, roll);
|
||||
}
|
||||
|
||||
// request an update
|
||||
if (m_light.headlight)
|
||||
updateLightPosition();
|
||||
@@ -277,14 +208,11 @@ void OglViewerWidget::mouseMoveEvent(QMouseEvent *e)
|
||||
else if (m_mouse.right)
|
||||
{
|
||||
// get the difference between last press and now
|
||||
QVector2D diff = QVector2D(e->localPos()) - m_mouse.position;
|
||||
m_camera->moveAction(QVector2D(e->localPos()) - m_mouse.position);
|
||||
|
||||
// update the new position
|
||||
m_mouse.position = QVector2D(e->localPos());
|
||||
|
||||
// calculate the translation
|
||||
m_translation += {(float)(diff.x() * 0.01), (float)(diff.y() * -0.01), 0.0};
|
||||
|
||||
// request an update
|
||||
if (m_light.headlight)
|
||||
updateLightPosition();
|
||||
@@ -294,7 +222,7 @@ void OglViewerWidget::mouseMoveEvent(QMouseEvent *e)
|
||||
|
||||
void OglViewerWidget::wheelEvent(QWheelEvent *e)
|
||||
{
|
||||
m_translation += {0.0, 0.0, (float)m_zSpeed * e->angleDelta().y() / 240};
|
||||
m_camera->wheelAction(e->angleDelta().y());
|
||||
|
||||
if (m_light.headlight)
|
||||
updateLightPosition();
|
||||
@@ -307,6 +235,38 @@ void OglViewerWidget::keyPressEvent(QKeyEvent *e)
|
||||
{
|
||||
resetView();
|
||||
}
|
||||
else if (e->key() == Qt::Key_W)
|
||||
{
|
||||
emit m_camera->wheelAction(1);
|
||||
|
||||
if (m_light.headlight)
|
||||
updateLightPosition();
|
||||
update();
|
||||
}
|
||||
else if (e->key() == Qt::Key_S)
|
||||
{
|
||||
emit m_camera->wheelAction(-1);
|
||||
|
||||
if (m_light.headlight)
|
||||
updateLightPosition();
|
||||
update();
|
||||
}
|
||||
else if (e->key() == Qt::Key_A)
|
||||
{
|
||||
emit m_camera->moveAction(QVector2D(0, -1));
|
||||
|
||||
if (m_light.headlight)
|
||||
updateLightPosition();
|
||||
update();
|
||||
}
|
||||
else if (e->key() == Qt::Key_D)
|
||||
{
|
||||
emit m_camera->moveAction(QVector2D(0, 1));
|
||||
|
||||
if (m_light.headlight)
|
||||
updateLightPosition();
|
||||
update();
|
||||
}
|
||||
else if (e->key() == Qt::Key_Escape)
|
||||
{
|
||||
parentWidget()->close();
|
||||
@@ -318,6 +278,26 @@ void OglViewerWidget::keyPressEvent(QKeyEvent *e)
|
||||
}
|
||||
}
|
||||
|
||||
void OglViewerWidget::keyReleaseEvent(QKeyEvent *e)
|
||||
{
|
||||
if (e->key() == Qt::Key_W || e->key() == Qt::Key_S)
|
||||
{
|
||||
emit m_camera->wheelAction(0);
|
||||
|
||||
if (m_light.headlight)
|
||||
updateLightPosition();
|
||||
update();
|
||||
}
|
||||
else if (e->key() == Qt::Key_A || e->key() == Qt::Key_D)
|
||||
{
|
||||
emit m_camera->moveAction(QVector2D(0, 0));
|
||||
|
||||
if (m_light.headlight)
|
||||
updateLightPosition();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void OglViewerWidget::dragEnterEvent(QDragEnterEvent *e)
|
||||
{
|
||||
if (e->mimeData()->hasUrls())
|
||||
@@ -341,20 +321,34 @@ void OglViewerWidget::loadFile(QString name)
|
||||
m_dataEngine->loadFile(name);
|
||||
}
|
||||
|
||||
void OglViewerWidget::toggleAxis(int axis)
|
||||
void OglViewerWidget::useFreeCamera()
|
||||
{
|
||||
switch (axis)
|
||||
{
|
||||
case 1:
|
||||
m_rotDirections.x = !m_rotDirections.x;
|
||||
break;
|
||||
case 2:
|
||||
m_rotDirections.y = !m_rotDirections.y;
|
||||
break;
|
||||
case 3:
|
||||
m_rotDirections.z = !m_rotDirections.z;
|
||||
break;
|
||||
}
|
||||
delete m_camera;
|
||||
m_camera = new FreeCamera;
|
||||
|
||||
if (m_lightOn)
|
||||
updateLightPosition();
|
||||
update();
|
||||
}
|
||||
|
||||
void OglViewerWidget::useOrbitCamera()
|
||||
{
|
||||
delete m_camera;
|
||||
m_camera = new OrbitCamera;
|
||||
|
||||
if (m_lightOn)
|
||||
updateLightPosition();
|
||||
update();
|
||||
}
|
||||
|
||||
void OglViewerWidget::useMoveCamera()
|
||||
{
|
||||
delete m_camera;
|
||||
m_camera = new MoveCamera;
|
||||
|
||||
if (m_lightOn)
|
||||
updateLightPosition();
|
||||
update();
|
||||
}
|
||||
|
||||
void OglViewerWidget::toggleWireframe()
|
||||
@@ -441,8 +435,3 @@ void OglViewerWidget::setBackfaceCulling(bool value)
|
||||
m_backfaceCulling = value;
|
||||
update();
|
||||
}
|
||||
|
||||
void OglViewerWidget::setZoomSpeed(int percent)
|
||||
{
|
||||
m_zSpeed = (double) percent / 100;
|
||||
}
|
||||
|
69
QtMeshViewer/Source/OrbitCamera.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "..\Header\OrbitCamera.h"
|
||||
#include <QVector2D>
|
||||
#include <qmath.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// constructor/destructor
|
||||
|
||||
OrbitCamera::OrbitCamera()
|
||||
{
|
||||
resetView();
|
||||
}
|
||||
|
||||
OrbitCamera::~OrbitCamera()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// functions
|
||||
|
||||
void OrbitCamera::rotateAction(QVector2D diff)
|
||||
{
|
||||
m_phi -= diff.x() * 0.01;
|
||||
m_theta -= diff.y() * 0.01;
|
||||
|
||||
//m_theta = qMax(qMin(M_PI - 0.0001, m_theta), 0.0001);
|
||||
}
|
||||
|
||||
void OrbitCamera::moveAction(QVector2D diff)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void OrbitCamera::wheelAction(double value)
|
||||
{
|
||||
m_roh -= m_zSpeed * value / 240;
|
||||
m_roh = qMax(m_roh, 0.0);
|
||||
}
|
||||
|
||||
void OrbitCamera::recalculateMatrix()
|
||||
{
|
||||
m_matrix = QMatrix4x4();
|
||||
|
||||
// different coordinate (spherical -> world) X->Z | Y->X | Z->Y
|
||||
QVector3D tmpPosition(
|
||||
qSin(m_theta) * qSin(m_phi),
|
||||
qCos(m_theta),
|
||||
qSin(m_theta) * qCos(m_phi)
|
||||
);
|
||||
|
||||
QVector3D tmpRight(
|
||||
qSin(m_phi - M_PI_2),
|
||||
0,
|
||||
qCos(m_phi - M_PI_2)
|
||||
);
|
||||
|
||||
m_matrix.lookAt(m_roh * tmpPosition, QVector3D(0,0,0), QVector3D::crossProduct(tmpRight, tmpPosition));
|
||||
}
|
||||
|
||||
void OrbitCamera::resetView()
|
||||
{
|
||||
m_roh = 4;
|
||||
m_phi = 0;
|
||||
m_theta = M_PI_2;
|
||||
CameraInterface::resetView();
|
||||
}
|
Before Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 64 KiB |
Before Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 48 KiB |
@@ -1,14 +0,0 @@
|
||||
#version 450 core
|
||||
|
||||
// Input
|
||||
in vec2 UV;
|
||||
|
||||
// Ouput data
|
||||
out vec3 color;
|
||||
|
||||
uniform sampler2D textureSampler;
|
||||
|
||||
void main()
|
||||
{
|
||||
color = texture(textureSampler, UV).rgb;
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
#version 450 core
|
||||
|
||||
// Input vertex data, different for all executions of this shader.
|
||||
layout(location = 0) in vec3 vertexPosition_modelspace;
|
||||
layout(location = 1) in vec2 vertexUV;
|
||||
|
||||
// Output
|
||||
out vec2 UV;
|
||||
|
||||
// Values that stay constant for the whole mesh.
|
||||
uniform mat4 MVP;
|
||||
|
||||
void main(){
|
||||
|
||||
// Output position of the vertex, in clip space : MVP * position
|
||||
gl_Position = MVP * vec4(vertexPosition_modelspace, 1);
|
||||
|
||||
UV = vertexUV;
|
||||
|
||||
}
|