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 auto prevOrigin = m_cameraOrigin;
|
||||
|
||||
if (m_keysPressed & static_cast<uint32_t>(keys_t::up))
|
||||
m_cameraOrigin += m_cameraFwd * distance;
|
||||
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;
|
||||
if (m_keysPressed & static_cast<uint32_t>(keys_t::fly_up))
|
||||
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
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
uint32_t m_keysPressed;
|
||||
std::optional<time_point> m_lastFrame;
|
||||
|
|
@ -148,4 +150,10 @@ protected:
|
|||
private:
|
||||
void applyMouseMotion();
|
||||
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(drawflat, &QAbstractButton::toggled, this, [=](bool checked) { glView->setDrawFlat(checked); });
|
||||
connect(keepposition, &QAbstractButton::toggled, this, [=](bool checked) { glView->setKeepOrigin(checked); });
|
||||
|
||||
connect(glView, &GLView::cameraMoved, this, &MainWindow::displayCameraPositionInfo);
|
||||
setupMenu();
|
||||
}
|
||||
|
||||
|
|
@ -334,10 +334,10 @@ class QLightStyleSlider : public QFrame
|
|||
public:
|
||||
int32_t style_id;
|
||||
|
||||
QLightStyleSlider(int32_t style_id, GLView *glView) :
|
||||
QFrame(),
|
||||
style_id(style_id),
|
||||
glView(glView)
|
||||
QLightStyleSlider(int32_t style_id, GLView *glView)
|
||||
: QFrame(),
|
||||
style_id(style_id),
|
||||
glView(glView)
|
||||
{
|
||||
auto *style_layout = new QHBoxLayout();
|
||||
|
||||
|
|
@ -345,11 +345,10 @@ public:
|
|||
style->setRange(0, 200);
|
||||
style->setValue(100);
|
||||
style->setSingleStep(10);
|
||||
//style->setTickPosition(QSlider::TicksBothSides);
|
||||
//style->setTickInterval(50);
|
||||
// style->setTickPosition(QSlider::TicksBothSides);
|
||||
// style->setTickInterval(50);
|
||||
|
||||
connect(style, QOverload<int>::of(&QSpinBox::valueChanged),
|
||||
this, &QLightStyleSlider::setValue);
|
||||
connect(style, QOverload<int>::of(&QSpinBox::valueChanged), this, &QLightStyleSlider::setValue);
|
||||
|
||||
auto *style_label = new QLabel();
|
||||
style_label->setText(QString::asprintf("%i", style_id));
|
||||
|
|
@ -363,10 +362,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
void setValue(int value)
|
||||
{
|
||||
glView->setLightStyleIntensity(style_id, value);
|
||||
}
|
||||
void setValue(int value) { glView->setLightStyleIntensity(style_id, value); }
|
||||
|
||||
GLView *glView;
|
||||
};
|
||||
|
|
@ -388,13 +384,13 @@ void MainWindow::loadFileInternal(const QString &file, bool is_reload)
|
|||
|
||||
fs::path fs_path = MakeFSPath(file);
|
||||
|
||||
bspdata_t d;
|
||||
m_bspdata = {};
|
||||
|
||||
settings::common_settings render_settings;
|
||||
|
||||
if (fs_path.extension().compare(".bsp") == 0) {
|
||||
|
||||
LoadBSPFile(fs_path, &d);
|
||||
LoadBSPFile(fs_path, &m_bspdata);
|
||||
|
||||
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.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 {
|
||||
d = QbspVisLight_Common(fs_path, ParseArgs(qbsp_options), ParseArgs(vis_options), ParseArgs(light_options),
|
||||
vis_checkbox->isChecked());
|
||||
m_bspdata = QbspVisLight_Common(fs_path, ParseArgs(qbsp_options), ParseArgs(vis_options),
|
||||
ParseArgs(light_options), vis_checkbox->isChecked());
|
||||
|
||||
// FIXME: move to a lightpreview_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
|
||||
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);
|
||||
|
||||
// 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()) {
|
||||
for (auto &ent : ents) {
|
||||
|
|
@ -459,7 +455,7 @@ void MainWindow::loadFileInternal(const QString &file, bool is_reload)
|
|||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
@ -468,4 +464,16 @@ void MainWindow::loadFileInternal(const QString &file, bool is_reload)
|
|||
auto *style = new QLightStyleSlider(style_entry.first, glView);
|
||||
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 <QVBoxLayout>
|
||||
|
||||
#include <common/bspfile.hh>
|
||||
|
||||
class GLView;
|
||||
class QFileSystemWatcher;
|
||||
class QLineEdit;
|
||||
|
|
@ -34,6 +36,7 @@ class MainWindow : public QMainWindow
|
|||
private:
|
||||
QFileSystemWatcher *m_watcher = nullptr;
|
||||
QString m_mapFile;
|
||||
bspdata_t m_bspdata;
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
|
|
@ -53,6 +56,7 @@ private:
|
|||
void reload();
|
||||
void loadFile(const QString &file);
|
||||
void loadFileInternal(const QString &file, bool is_reload);
|
||||
void displayCameraPositionInfo();
|
||||
|
||||
private:
|
||||
GLView *glView;
|
||||
|
|
|
|||
Loading…
Reference in New Issue