Commit 0735ef99 authored by Anakin's avatar Anakin

cosmetic to MainWindow,

drop does not work for widget,
fixed offset problem,
add esc key
parent dca6e61c
......@@ -25,10 +25,10 @@ private:
QVector<QOpenGLTexture*> m_textures;
QVector<DrawInformation> m_drawList;
void loadFile(const char* filePath);
void loadTexture(const char* filePath);
public:
void loadFile(const char* filePath);
void drawGeometry(QOpenGLShaderProgram *program);
};
......@@ -13,4 +13,10 @@ public:
private:
Ui::MainWindowClass* ui;
private slots:
void openFile();
void aboutFile();
void aboutTool();
};
......@@ -40,6 +40,7 @@ protected:
void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE;
void dropEvent(QDropEvent * event) Q_DECL_OVERRIDE;
void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
void initializeGL() Q_DECL_OVERRIDE;
......@@ -49,6 +50,9 @@ protected:
private:
void initShaders();
public:
void openFile(const char* filePath);
};
......@@ -15,7 +15,7 @@ GeometryEngine::GeometryEngine()
m_indexBuf.create();
// Initializes cube geometry and transfers it to VBOs
loadFile("..\\Release\\Msh\\triClothMan.msh");
loadFile("..\\Release\\Msh\\ic_helmet.msh");
}
GeometryEngine::~GeometryEngine()
......@@ -50,21 +50,22 @@ void GeometryEngine::loadFile(const char* filePath)
textureNames = file.getTextureNames();
// collect data
unsigned int offsetCount(0);
unsigned int indexOffset(0);
unsigned int vertexOffset(0);
for (auto& modelIterator : *models)
{
for (auto& segmentIterator : modelIterator->segmList)
{
// get draw information
DrawInformation new_info;
new_info.offset = offsetCount;
new_info.offset = indexOffset;
new_info.size = segmentIterator->indices.size();
new_info.textureIndex = segmentIterator->textureIndex;
new_info.modelMatrix = modelIterator->m4x4Translation;
// add offset to indices
for (auto& it : segmentIterator->indices)
it += new_info.offset;
it += vertexOffset;
// save data
vertexData += segmentIterator->vertices;
......@@ -72,7 +73,8 @@ void GeometryEngine::loadFile(const char* filePath)
m_drawList.push_back(new_info);
// update offset
offsetCount += new_info.size;
indexOffset += new_info.size;
vertexOffset += segmentIterator->vertices.size();
}
}
......
#include "..\Header\MainWindow.h"
#include "..\Header\OglViewerWidget.h"
#include <QSurfaceFormat>
#include <QMessageBox>
#include <QFileDialog>
#define WINDOW_NAME "Mesh Viewer"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
......@@ -8,19 +12,54 @@ MainWindow::MainWindow(QWidget *parent)
{
ui->setupUi(this);
setWindowTitle(WINDOW_NAME);
setWindowIcon(QIcon(":/images/icon.ico"));
ui->statusBar->showMessage("pre-alpha");
ui->mainToolBar->addAction("Open File", this, &MainWindow::openFile);
ui->mainToolBar->addAction("About File", this, &MainWindow::aboutFile);
ui->mainToolBar->addAction("Help", this, &MainWindow::aboutTool);
QSurfaceFormat format;
format.setDepthBufferSize(24);
QSurfaceFormat::setDefaultFormat(format);
setCentralWidget(new OglViewerWidget(this));
setWindowIcon(QIcon(":/images/icon.ico"));
setWindowTitle("Mesh Viewer");
ui->statusBar->showMessage("pre-alpha");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::openFile()
{
QString fileName = QFileDialog::getOpenFileName(this, "Open File", "../Release/Msh", "Mesh (*.msh)");
dynamic_cast<OglViewerWidget*>(centralWidget())->openFile(fileName.toStdString().c_str());
}
void MainWindow::aboutFile()
{
QMessageBox* dialog = new QMessageBox(QMessageBox::Information,
WINDOW_NAME,
"When i find some time, i'll add some information about\nthe file in the detailed text",
QMessageBox::StandardButton::Close,
this,
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
dialog->setDetailedText("This is the cool detailed text\n");
dialog->exec();
}
void MainWindow::aboutTool()
{
QMessageBox* dialog = new QMessageBox(QMessageBox::Question,
WINDOW_NAME,
"This is the Pre-Alpha version of my Mesh Viewer\nCheck the detailed information",
QMessageBox::StandardButton::Close,
this,
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
dialog->setDetailedText("left mouse - rotate\nright mouse - move\nscroll - zoom\nspace - reset view\nesc - close");
dialog->exec();
}
\ No newline at end of file
#include "..\Header\OglViewerWidget.h"
#include <QMouseEvent>
#include <QDropEvent>
#include <QMimeData>
#include <math.h>
#include <iostream>
......@@ -16,6 +18,7 @@ OglViewerWidget::OglViewerWidget(QWidget *parent) :
{
setFocus();
m_translation.setZ(DEFAULT_Z_DISTANCE);
setAcceptDrops(true);
}
OglViewerWidget::~OglViewerWidget()
......@@ -89,6 +92,11 @@ void OglViewerWidget::wheelEvent(QWheelEvent *e)
update();
}
void OglViewerWidget::dropEvent(QDropEvent * e)
{
std::cout << e->mimeData()->text().toStdString() << std::endl;
}
void OglViewerWidget::keyPressEvent(QKeyEvent *e)
{
if (e->key() == Qt::Key_Space)
......@@ -96,6 +104,10 @@ void OglViewerWidget::keyPressEvent(QKeyEvent *e)
m_rotation = QQuaternion();
m_translation = { 0.0, 0.0, DEFAULT_Z_DISTANCE };
}
else if (e->key() == Qt::Key_Escape)
{
parentWidget()->close();
}
update();
}
......@@ -103,7 +115,7 @@ void OglViewerWidget::initializeGL()
{
initializeOpenGLFunctions();
glClearColor(0, 0, 0, 1);
glClearColor(0.5000f, 0.8000f, 1.0000f, 0.0000f);
initShaders();
......@@ -174,4 +186,9 @@ void OglViewerWidget::initShaders()
/////////////////////////////////////////////////////////////////////////
// public functions
\ No newline at end of file
// public functions
void OglViewerWidget::openFile(const char * filePath)
{
m_dataEngine->loadFile(filePath);
}
\ No newline at end of file
......@@ -13,11 +13,14 @@ Feel free to use my code the way you like. But remember i used some public libra
licence, too.
### To Do
- rotation problem
- cloth not working correctly
- center and normalize
- open file while runtime does not work
- drag and drop does not work
- tga with alpha cannot be opened
- multi polygons not correctly triangulated
- 5+ polygons => corrupted file
- optional display bones, shadow, collision,...
- integrate into a software:
-> gui open file ( + drag and drop),
-> list all msh under a directory,
-> display shadows,
-> display colisions,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment