Add WZM editor written in Qt. Be warned that it is still buggy and incomplete.
git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@6228 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
5ae79df9e3
commit
797701f42b
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,157 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2008 by Warzone Resurrection Team
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lessser General Public
|
||||||
|
License along with this program. If not, see
|
||||||
|
<http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "qwzm.h"
|
||||||
|
|
||||||
|
QWzmViewer::QWzmViewer(QWidget *parent)
|
||||||
|
: QMainWindow(parent), Ui::QWZM()
|
||||||
|
{
|
||||||
|
QTimer *timer = new QTimer(this);
|
||||||
|
|
||||||
|
setupUi(this);
|
||||||
|
connect(timer, SIGNAL(timeout()), this, SLOT(tick()));
|
||||||
|
connect(actionQuit, SIGNAL(triggered()), qApp, SLOT(quit()));
|
||||||
|
connect(actionSave_as, SIGNAL(triggered()), this, SLOT(saveAs()));
|
||||||
|
connect(actionImport_3DS, SIGNAL(triggered()), this, SLOT(open3DS()));
|
||||||
|
connect(actionOpenWZM, SIGNAL(triggered()), this, SLOT(openWZM()));
|
||||||
|
connect(actionWireframe, SIGNAL(triggered()), this, SLOT(toggleWireframe()));
|
||||||
|
connect(actionCulling, SIGNAL(triggered()), this, SLOT(toggleCulling()));
|
||||||
|
connect(actionAnimation, SIGNAL(triggered()), this, SLOT(toggleAnimation()));
|
||||||
|
connect(comboBoxTeam, SIGNAL(currentIndexChanged(int)), this, SLOT(toggleTeam(int)));
|
||||||
|
|
||||||
|
// Set defaults
|
||||||
|
toggleCulling();
|
||||||
|
toggleAnimation();
|
||||||
|
toggleWireframe();
|
||||||
|
|
||||||
|
timer->start(10); // 10 fps, which is more than enough!
|
||||||
|
}
|
||||||
|
|
||||||
|
QWzmViewer::~QWzmViewer()
|
||||||
|
{
|
||||||
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QWzmViewer::toggleTeam(int index)
|
||||||
|
{
|
||||||
|
glView->setTeam(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QWzmViewer::tick()
|
||||||
|
{
|
||||||
|
glView->updateGL();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QWzmViewer::toggleCulling()
|
||||||
|
{
|
||||||
|
if (actionCulling->isChecked())
|
||||||
|
{
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glDisable(GL_CULL_FACE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QWzmViewer::toggleAnimation()
|
||||||
|
{
|
||||||
|
glView->setAnimation(actionAnimation->isChecked());
|
||||||
|
}
|
||||||
|
|
||||||
|
void QWzmViewer::toggleWireframe()
|
||||||
|
{
|
||||||
|
if (actionWireframe->isChecked())
|
||||||
|
{
|
||||||
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QWzmViewer::saveAs()
|
||||||
|
{
|
||||||
|
filename = QFileDialog::getOpenFileName(this, tr("Choose output file"), QString::null, QString::null);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QWzmViewer::save()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void QWzmViewer::open3DS()
|
||||||
|
{
|
||||||
|
QString model = QFileDialog::getOpenFileName(this, tr("Choose 3DS file"), QString::null, tr("3DS models (*.3ds)"));
|
||||||
|
QString texture = QFileDialog::getOpenFileName(this, tr("Find texture"), QString::null, tr("PNG texture (*.png)"));
|
||||||
|
if (model != "" && texture != "")
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QWzmViewer::openWZM()
|
||||||
|
{
|
||||||
|
filename = QFileDialog::getOpenFileName(this, tr("Choose 3DS file"), QString::null, tr("WZM models (*.wzm)"));
|
||||||
|
if (filename != "")
|
||||||
|
{
|
||||||
|
MODEL *psModel = readModel(filename.toAscii().constData(), 0);
|
||||||
|
if (psModel)
|
||||||
|
{
|
||||||
|
QFileInfo texPath(psModel->texPath);
|
||||||
|
|
||||||
|
// Try to find texture automatically
|
||||||
|
if (!texPath.exists())
|
||||||
|
{
|
||||||
|
texPath.setFile(QString("../../data/base/texpages/"), psModel->texPath);
|
||||||
|
if (!texPath.exists())
|
||||||
|
{
|
||||||
|
texPath.setFile(QFileDialog::getExistingDirectory(this, tr("Specify texture directory"), QString::null), psModel->texPath);
|
||||||
|
if (!texPath.exists())
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this, tr("Oops..."), "Could not find texture", QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
qWarning("Creating model from %s and texture from %s", filename.toAscii().constData(), texPath.absoluteFilePath().toAscii().constData());
|
||||||
|
psModel->pixmap = readPixmap(texPath.absoluteFilePath().toAscii().constData());
|
||||||
|
if (!psModel->pixmap)
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this, tr("Oops..."), "Could not read texture", QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
|
||||||
|
}
|
||||||
|
comboBoxTeam->setCurrentIndex(0);
|
||||||
|
glView->setModel(psModel);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qWarning("Failed to create model!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QApplication app(argc, argv);
|
||||||
|
QWzmViewer *wzm = new QWzmViewer();
|
||||||
|
|
||||||
|
wzm->show();
|
||||||
|
return app.exec();
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2008 by Warzone Resurrection Team
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this program. If not, see
|
||||||
|
<http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#ifndef QWZM_H
|
||||||
|
#define QWZM_H
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QtOpenGL>
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "wzmutils.h"
|
||||||
|
}
|
||||||
|
#include "ui_qwzm.h"
|
||||||
|
|
||||||
|
/** WZM Viewer */
|
||||||
|
class QWzmViewer : public QMainWindow, private Ui::QWZM
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
QWzmViewer(QWidget *parent = 0);
|
||||||
|
~QWzmViewer();
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void saveAs();
|
||||||
|
void save();
|
||||||
|
void open3DS();
|
||||||
|
void openWZM();
|
||||||
|
void toggleWireframe();
|
||||||
|
void toggleCulling();
|
||||||
|
void toggleTeam(int index);
|
||||||
|
void tick();
|
||||||
|
void toggleAnimation();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString filename;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,11 @@
|
||||||
|
FORMS += qwzm.ui
|
||||||
|
SOURCES += qwzm.cpp ../display/wzmutils.c wzmglwidget.cpp
|
||||||
|
HEADERS += qwzm.h ../display/wzmutils.h wzmglwidget.h
|
||||||
|
TEMPLATE = app
|
||||||
|
CONFIG += warn_on \
|
||||||
|
qt \
|
||||||
|
precompile_header
|
||||||
|
TARGET = qwzm
|
||||||
|
INCLUDEPATH += ../display
|
||||||
|
LIBS += -l3ds -lm
|
||||||
|
QT += opengl
|
|
@ -0,0 +1,237 @@
|
||||||
|
<ui version="4.0" >
|
||||||
|
<class>QWZM</class>
|
||||||
|
<widget class="QMainWindow" name="QWZM" >
|
||||||
|
<property name="geometry" >
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>800</width>
|
||||||
|
<height>600</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle" >
|
||||||
|
<string>MainWindow</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget" >
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout" >
|
||||||
|
<item>
|
||||||
|
<widget class="WZMOpenGLWidget" native="1" name="glView" >
|
||||||
|
<property name="sizePolicy" >
|
||||||
|
<sizepolicy vsizetype="MinimumExpanding" hsizetype="Preferred" >
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="groupBox" >
|
||||||
|
<property name="title" >
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout" >
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer" >
|
||||||
|
<property name="orientation" >
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0" >
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2" >
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Player</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="comboBoxTeam" >
|
||||||
|
<item>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Green</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Yellow</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Grey</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Black</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Red</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Blue</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Pink</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Cyan</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menubar" >
|
||||||
|
<property name="geometry" >
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>800</width>
|
||||||
|
<height>25</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<widget class="QMenu" name="menuImport_3DS" >
|
||||||
|
<property name="title" >
|
||||||
|
<string>File</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="separator" />
|
||||||
|
<addaction name="actionOpenWZM" />
|
||||||
|
<addaction name="actionImport_3DS" />
|
||||||
|
<addaction name="actionImport_OBJ" />
|
||||||
|
<addaction name="actionImport_PIE" />
|
||||||
|
<addaction name="actionSave" />
|
||||||
|
<addaction name="actionSave_as" />
|
||||||
|
<addaction name="separator" />
|
||||||
|
<addaction name="actionQuit" />
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenu" name="menuDisplay" >
|
||||||
|
<property name="title" >
|
||||||
|
<string>Display</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionAnimation" />
|
||||||
|
<addaction name="actionCulling" />
|
||||||
|
<addaction name="actionWireframe" />
|
||||||
|
</widget>
|
||||||
|
<addaction name="menuImport_3DS" />
|
||||||
|
<addaction name="menuDisplay" />
|
||||||
|
</widget>
|
||||||
|
<action name="actionImport_3DS" >
|
||||||
|
<property name="enabled" >
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Import 3DS...</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionImport_OBJ" >
|
||||||
|
<property name="enabled" >
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Import OBJ...</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionImport_PIE" >
|
||||||
|
<property name="enabled" >
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Import PIE...</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionSave" >
|
||||||
|
<property name="enabled" >
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Save</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut" >
|
||||||
|
<string>Ctrl+S</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionSave_as" >
|
||||||
|
<property name="enabled" >
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Save as...</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionQuit" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Quit</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionAnimation" >
|
||||||
|
<property name="checkable" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Animate</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionCulling" >
|
||||||
|
<property name="checkable" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="checked" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Culling</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionWireframe" >
|
||||||
|
<property name="checkable" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Wireframe</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut" >
|
||||||
|
<string>Ctrl+W</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionOpenWZM" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Open</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut" >
|
||||||
|
<string>Ctrl+O</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>WZMOpenGLWidget</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>wzmglwidget.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
|
@ -0,0 +1,156 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2008 by Warzone Resurrection Team
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lessser General Public
|
||||||
|
License along with this program. If not, see
|
||||||
|
<http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "wzmglwidget.h"
|
||||||
|
|
||||||
|
WZMOpenGLWidget::WZMOpenGLWidget(QWidget *parent)
|
||||||
|
: QGLWidget(parent)
|
||||||
|
{
|
||||||
|
psModel = NULL;
|
||||||
|
if (!QGLFormat::hasOpenGL())
|
||||||
|
{
|
||||||
|
qWarning("This system has no OpenGL support!");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
timer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
WZMOpenGLWidget::~WZMOpenGLWidget()
|
||||||
|
{
|
||||||
|
freeModel(psModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WZMOpenGLWidget::initializeGL()
|
||||||
|
{
|
||||||
|
qWarning("OpenGL version: %s", glGetString(GL_VERSION));
|
||||||
|
qWarning("OpenGL renderer: %s", glGetString(GL_RENDERER));
|
||||||
|
qWarning("OpenGL vendor: %s", glGetString(GL_VENDOR));
|
||||||
|
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
glDisable(GL_FOG);
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glDepthFunc(GL_LEQUAL);
|
||||||
|
glClearDepth(1.0f);
|
||||||
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WZMOpenGLWidget::resizeGL(int w, int h)
|
||||||
|
{
|
||||||
|
if ( h == 0 ) h = 1;
|
||||||
|
const float aspect = (float)w / (float)h;
|
||||||
|
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glLoadIdentity();
|
||||||
|
glViewport(0, 0, w, h);
|
||||||
|
|
||||||
|
gluPerspective(45.0f, aspect, 0.1f, 500.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WZMOpenGLWidget::paintGL()
|
||||||
|
{
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glLoadIdentity();
|
||||||
|
glTranslatef(0.0f, -30.0f, -50.0f + -(dimension * 2.0f));;
|
||||||
|
if (psModel)
|
||||||
|
{
|
||||||
|
int now = timer.elapsed();
|
||||||
|
|
||||||
|
// Animation support
|
||||||
|
for (int i = 0; i < psModel->meshes && animation; i++)
|
||||||
|
{
|
||||||
|
MESH *psMesh = &psModel->mesh[i];
|
||||||
|
FRAME *psFrame;
|
||||||
|
|
||||||
|
if (!psMesh->frameArray)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
psFrame = &psMesh->frameArray[psMesh->currentFrame];
|
||||||
|
|
||||||
|
assert(psMesh->currentFrame < psMesh->frames && psMesh->currentFrame >= 0);
|
||||||
|
if (psFrame->timeSlice != 0 && psFrame->timeSlice * 1000.0 + psMesh->lastChange < now)
|
||||||
|
{
|
||||||
|
psMesh->lastChange = now;
|
||||||
|
psMesh->currentFrame++;
|
||||||
|
if (psMesh->currentFrame >= psMesh->frames)
|
||||||
|
{
|
||||||
|
psMesh->currentFrame = 0; // loop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
drawModel(psModel, QTime::currentTime().elapsed());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WZMOpenGLWidget::setTeam(int index)
|
||||||
|
{
|
||||||
|
if (!psModel)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (index > 7 || index < 0)
|
||||||
|
{
|
||||||
|
qWarning("setTeam: Bad index %d", index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < psModel->meshes; i++)
|
||||||
|
{
|
||||||
|
MESH *psMesh = &psModel->mesh[i];
|
||||||
|
|
||||||
|
if (!psMesh->teamColours)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
psMesh->currentTextureArray = index;
|
||||||
|
}
|
||||||
|
teamIndex = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WZMOpenGLWidget::setAnimation(bool value)
|
||||||
|
{
|
||||||
|
animation = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WZMOpenGLWidget::setModel(MODEL *model)
|
||||||
|
{
|
||||||
|
psModel = model;
|
||||||
|
if (!model)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
prepareModel(model);
|
||||||
|
|
||||||
|
// Calculate best z offset
|
||||||
|
for (int i = 0; i < psModel->meshes; i++)
|
||||||
|
{
|
||||||
|
MESH *psMesh = &psModel->mesh[i];
|
||||||
|
|
||||||
|
for (int j = 0; j < psMesh->vertices * 3; j++)
|
||||||
|
{
|
||||||
|
dimension = MAX(fabs(psMesh->vertexArray[j]), dimension);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
timer.start();
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2008 by Warzone Resurrection Team
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this program. If not, see
|
||||||
|
<http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#ifndef QWZMGL_H
|
||||||
|
#define QWZMGL_H
|
||||||
|
|
||||||
|
#include <QtOpenGL>
|
||||||
|
extern "C" {
|
||||||
|
#include "wzmutils.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
class WZMOpenGLWidget : public QGLWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
WZMOpenGLWidget(QWidget *parent);
|
||||||
|
~WZMOpenGLWidget();
|
||||||
|
void setModel(MODEL *model);
|
||||||
|
void setTeam(int index);
|
||||||
|
void setAnimation(bool value);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void initializeGL();
|
||||||
|
void resizeGL(int w, int h);
|
||||||
|
void paintGL();
|
||||||
|
|
||||||
|
private:
|
||||||
|
MODEL *psModel;
|
||||||
|
float dimension;
|
||||||
|
int teamIndex;
|
||||||
|
bool animation;
|
||||||
|
QTime timer;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue