lightpreview: report camera position to main window
This commit is contained in:
parent
fa890456f6
commit
3e51f2aeaa
|
|
@ -738,6 +738,8 @@ void GLView::applyFlyMovement(float duration_seconds)
|
||||||
|
|
||||||
const float distance = m_moveSpeed * duration_seconds;
|
const float distance = m_moveSpeed * duration_seconds;
|
||||||
|
|
||||||
|
const auto prevOrigin = m_cameraOrigin;
|
||||||
|
|
||||||
if (m_keysPressed & static_cast<uint32_t>(keys_t::up))
|
if (m_keysPressed & static_cast<uint32_t>(keys_t::up))
|
||||||
m_cameraOrigin += m_cameraFwd * distance;
|
m_cameraOrigin += m_cameraFwd * distance;
|
||||||
if (m_keysPressed & static_cast<uint32_t>(keys_t::down))
|
if (m_keysPressed & static_cast<uint32_t>(keys_t::down))
|
||||||
|
|
@ -750,4 +752,13 @@ void GLView::applyFlyMovement(float duration_seconds)
|
||||||
m_cameraOrigin -= QVector3D(0, 0, 1) * distance;
|
m_cameraOrigin -= QVector3D(0, 0, 1) * distance;
|
||||||
if (m_keysPressed & static_cast<uint32_t>(keys_t::fly_up))
|
if (m_keysPressed & static_cast<uint32_t>(keys_t::fly_up))
|
||||||
m_cameraOrigin += QVector3D(0, 0, 1) * distance;
|
m_cameraOrigin += QVector3D(0, 0, 1) * distance;
|
||||||
|
|
||||||
|
if (prevOrigin != m_cameraOrigin) {
|
||||||
|
emit cameraMoved();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qvec3f GLView::cameraPosition() const
|
||||||
|
{
|
||||||
|
return qvec3f{m_cameraOrigin[0], m_cameraOrigin[1], m_cameraOrigin[2]};
|
||||||
|
}
|
||||||
|
|
@ -53,6 +53,8 @@ struct mbsp_t;
|
||||||
|
|
||||||
class GLView : public QOpenGLWidget, protected QOpenGLFunctions_3_3_Core
|
class GLView : public QOpenGLWidget, protected QOpenGLFunctions_3_3_Core
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t m_keysPressed;
|
uint32_t m_keysPressed;
|
||||||
std::optional<time_point> m_lastFrame;
|
std::optional<time_point> m_lastFrame;
|
||||||
|
|
@ -148,4 +150,10 @@ protected:
|
||||||
private:
|
private:
|
||||||
void applyMouseMotion();
|
void applyMouseMotion();
|
||||||
void applyFlyMovement(float duration);
|
void applyFlyMovement(float duration);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void cameraMoved();
|
||||||
|
|
||||||
|
public:
|
||||||
|
qvec3f cameraPosition() const;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
connect(showtris, &QAbstractButton::toggled, this, [=](bool checked) { glView->setShowTris(checked); });
|
connect(showtris, &QAbstractButton::toggled, this, [=](bool checked) { glView->setShowTris(checked); });
|
||||||
connect(drawflat, &QAbstractButton::toggled, this, [=](bool checked) { glView->setDrawFlat(checked); });
|
connect(drawflat, &QAbstractButton::toggled, this, [=](bool checked) { glView->setDrawFlat(checked); });
|
||||||
connect(keepposition, &QAbstractButton::toggled, this, [=](bool checked) { glView->setKeepOrigin(checked); });
|
connect(keepposition, &QAbstractButton::toggled, this, [=](bool checked) { glView->setKeepOrigin(checked); });
|
||||||
|
connect(glView, &GLView::cameraMoved, this, &MainWindow::displayCameraPositionInfo);
|
||||||
setupMenu();
|
setupMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -334,10 +334,10 @@ class QLightStyleSlider : public QFrame
|
||||||
public:
|
public:
|
||||||
int32_t style_id;
|
int32_t style_id;
|
||||||
|
|
||||||
QLightStyleSlider(int32_t style_id, GLView *glView) :
|
QLightStyleSlider(int32_t style_id, GLView *glView)
|
||||||
QFrame(),
|
: QFrame(),
|
||||||
style_id(style_id),
|
style_id(style_id),
|
||||||
glView(glView)
|
glView(glView)
|
||||||
{
|
{
|
||||||
auto *style_layout = new QHBoxLayout();
|
auto *style_layout = new QHBoxLayout();
|
||||||
|
|
||||||
|
|
@ -345,11 +345,10 @@ public:
|
||||||
style->setRange(0, 200);
|
style->setRange(0, 200);
|
||||||
style->setValue(100);
|
style->setValue(100);
|
||||||
style->setSingleStep(10);
|
style->setSingleStep(10);
|
||||||
//style->setTickPosition(QSlider::TicksBothSides);
|
// style->setTickPosition(QSlider::TicksBothSides);
|
||||||
//style->setTickInterval(50);
|
// style->setTickInterval(50);
|
||||||
|
|
||||||
connect(style, QOverload<int>::of(&QSpinBox::valueChanged),
|
connect(style, QOverload<int>::of(&QSpinBox::valueChanged), this, &QLightStyleSlider::setValue);
|
||||||
this, &QLightStyleSlider::setValue);
|
|
||||||
|
|
||||||
auto *style_label = new QLabel();
|
auto *style_label = new QLabel();
|
||||||
style_label->setText(QString::asprintf("%i", style_id));
|
style_label->setText(QString::asprintf("%i", style_id));
|
||||||
|
|
@ -363,10 +362,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setValue(int value)
|
void setValue(int value) { glView->setLightStyleIntensity(style_id, value); }
|
||||||
{
|
|
||||||
glView->setLightStyleIntensity(style_id, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
GLView *glView;
|
GLView *glView;
|
||||||
};
|
};
|
||||||
|
|
@ -388,13 +384,13 @@ void MainWindow::loadFileInternal(const QString &file, bool is_reload)
|
||||||
|
|
||||||
fs::path fs_path = MakeFSPath(file);
|
fs::path fs_path = MakeFSPath(file);
|
||||||
|
|
||||||
bspdata_t d;
|
m_bspdata = {};
|
||||||
|
|
||||||
settings::common_settings render_settings;
|
settings::common_settings render_settings;
|
||||||
|
|
||||||
if (fs_path.extension().compare(".bsp") == 0) {
|
if (fs_path.extension().compare(".bsp") == 0) {
|
||||||
|
|
||||||
LoadBSPFile(fs_path, &d);
|
LoadBSPFile(fs_path, &m_bspdata);
|
||||||
|
|
||||||
auto opts = ParseArgs(light_options);
|
auto opts = ParseArgs(light_options);
|
||||||
|
|
||||||
|
|
@ -410,13 +406,13 @@ void MainWindow::loadFileInternal(const QString &file, bool is_reload)
|
||||||
render_settings.initialize(argPtrs.size() - 1, argPtrs.data() + 1);
|
render_settings.initialize(argPtrs.size() - 1, argPtrs.data() + 1);
|
||||||
render_settings.postinitialize(argPtrs.size(), argPtrs.data());
|
render_settings.postinitialize(argPtrs.size(), argPtrs.data());
|
||||||
|
|
||||||
d.version->game->init_filesystem(fs_path, render_settings);
|
m_bspdata.version->game->init_filesystem(fs_path, render_settings);
|
||||||
|
|
||||||
ConvertBSPFormat(&d, &bspver_generic);
|
ConvertBSPFormat(&m_bspdata, &bspver_generic);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
d = QbspVisLight_Common(fs_path, ParseArgs(qbsp_options), ParseArgs(vis_options), ParseArgs(light_options),
|
m_bspdata = QbspVisLight_Common(fs_path, ParseArgs(qbsp_options), ParseArgs(vis_options),
|
||||||
vis_checkbox->isChecked());
|
ParseArgs(light_options), vis_checkbox->isChecked());
|
||||||
|
|
||||||
// FIXME: move to a lightpreview_settings
|
// FIXME: move to a lightpreview_settings
|
||||||
settings::common_settings settings;
|
settings::common_settings settings;
|
||||||
|
|
@ -424,17 +420,17 @@ void MainWindow::loadFileInternal(const QString &file, bool is_reload)
|
||||||
// FIXME: copy the -path args from light
|
// FIXME: copy the -path args from light
|
||||||
settings.paths.copy_from(::light_options.paths);
|
settings.paths.copy_from(::light_options.paths);
|
||||||
|
|
||||||
d.loadversion->game->init_filesystem(file.toStdString(), settings);
|
m_bspdata.loadversion->game->init_filesystem(file.toStdString(), settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto &bsp = std::get<mbsp_t>(d.bsp);
|
const auto &bsp = std::get<mbsp_t>(m_bspdata.bsp);
|
||||||
|
|
||||||
auto ents = EntData_Parse(bsp);
|
auto ents = EntData_Parse(bsp);
|
||||||
|
|
||||||
// build lightmap atlas
|
// build lightmap atlas
|
||||||
auto atlas = build_lightmap_atlas(bsp, d.bspx.entries, false, true);
|
auto atlas = build_lightmap_atlas(bsp, m_bspdata.bspx.entries, false, true);
|
||||||
|
|
||||||
glView->renderBSP(file, bsp, d.bspx.entries, ents, atlas, render_settings);
|
glView->renderBSP(file, bsp, m_bspdata.bspx.entries, ents, atlas, render_settings);
|
||||||
|
|
||||||
if (!is_reload && !glView->getKeepOrigin()) {
|
if (!is_reload && !glView->getKeepOrigin()) {
|
||||||
for (auto &ent : ents) {
|
for (auto &ent : ents) {
|
||||||
|
|
@ -459,7 +455,7 @@ void MainWindow::loadFileInternal(const QString &file, bool is_reload)
|
||||||
}
|
}
|
||||||
|
|
||||||
// set lightstyle data
|
// set lightstyle data
|
||||||
while ( QWidget* w = lightstyles->parentWidget()->findChild<QWidget*>(QString(), Qt::FindDirectChildrenOnly) ) {
|
while (QWidget *w = lightstyles->parentWidget()->findChild<QWidget *>(QString(), Qt::FindDirectChildrenOnly)) {
|
||||||
delete w;
|
delete w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -468,4 +464,16 @@ void MainWindow::loadFileInternal(const QString &file, bool is_reload)
|
||||||
auto *style = new QLightStyleSlider(style_entry.first, glView);
|
auto *style = new QLightStyleSlider(style_entry.first, glView);
|
||||||
lightstyles->addWidget(style);
|
lightstyles->addWidget(style);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::displayCameraPositionInfo()
|
||||||
|
{
|
||||||
|
const auto *bsp = std::get_if<mbsp_t>(&m_bspdata.bsp);
|
||||||
|
if (!bsp)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const qvec3f point = glView->cameraPosition();
|
||||||
|
const mleaf_t *leaf = BSP_FindLeafAtPoint(bsp, &bsp->dmodels[0], point);
|
||||||
|
|
||||||
|
// TODO: display leaf info
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@ See file, 'COPYING', for details.
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
|
#include <common/bspfile.hh>
|
||||||
|
|
||||||
class GLView;
|
class GLView;
|
||||||
class QFileSystemWatcher;
|
class QFileSystemWatcher;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
|
|
@ -34,6 +36,7 @@ class MainWindow : public QMainWindow
|
||||||
private:
|
private:
|
||||||
QFileSystemWatcher *m_watcher = nullptr;
|
QFileSystemWatcher *m_watcher = nullptr;
|
||||||
QString m_mapFile;
|
QString m_mapFile;
|
||||||
|
bspdata_t m_bspdata;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = nullptr);
|
explicit MainWindow(QWidget *parent = nullptr);
|
||||||
|
|
@ -53,6 +56,7 @@ private:
|
||||||
void reload();
|
void reload();
|
||||||
void loadFile(const QString &file);
|
void loadFile(const QString &file);
|
||||||
void loadFileInternal(const QString &file, bool is_reload);
|
void loadFileInternal(const QString &file, bool is_reload);
|
||||||
|
void displayCameraPositionInfo();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLView *glView;
|
GLView *glView;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue