Skip to content

Commit

Permalink
Surround mode: Make horizontal field of view adjustable
Browse files Browse the repository at this point in the history
Based on ideas by Github user ArsenicBismuth in Github pull request #36.

Adjust HFOV with Shift plus the mouse wheel. This actually adjusts the aspect
ratio, so it's independent of the view port.
  • Loading branch information
marlam committed Dec 26, 2024
1 parent 1e59d93 commit 30e7eb4
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 8 deletions.
8 changes: 8 additions & 0 deletions doc/bino-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ Bino is a video player with a focus on 3D and Virtual Reality:

Set surround vertical field of view (default 50, range 5-115).

- `--surround-ar` *ratio*

Set surround aspect ratio (default 2, range 1.0-4.0).

- `-S`, `--swap-eyes`

Swap left/right eye.
Expand Down Expand Up @@ -315,6 +319,10 @@ The following commands are supported:

Set surround vertical field of view (default 50, range 5-115).

- `set-surround-ar` *ratio*

Set surround aspect ratio (default 2, range 1.0-4.0).

- `set-swap-eyes` `on`|`off`

Set left/right eye swap.
Expand Down
10 changes: 10 additions & 0 deletions src/commandinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,16 @@ void CommandInterpreter::processNextCommand()
if (gui)
gui->setSurroundVerticalFieldOfView(surroundVerticalFOV);
}
} else if (cmd.startsWith("set-surround-ar ")) {
bool ok;
float surroundAspectRatio = cmd.mid(16).toFloat(&ok);
if (!ok || surroundAspectRatio < 1.0f || surroundAspectRatio > 4.0f) {
LOG_FATAL("%s", qPrintable(tr("Invalid argument in %1 line %2").arg(_file.fileName()).arg(_lineIndex)));
} else {
Gui* gui = Gui::instance();
if (gui)
gui->setSurroundAspectRatio(surroundAspectRatio);
}
} else if (cmd == "play") {
Bino::instance()->play();
} else if (cmd == "stop") {
Expand Down
10 changes: 8 additions & 2 deletions src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ void Gui::addBinoAction(QAction* action, QMenu* menu)

static Gui* GuiSingleton = nullptr;

Gui::Gui(OutputMode outputMode, float surroundVerticalFOV, bool fullscreen) :
Gui::Gui(OutputMode outputMode, float surroundVerticalFOV, float surroundAspectRatio, bool fullscreen) :
QMainWindow(),
_widget(new Widget(outputMode, surroundVerticalFOV, this)),
_widget(new Widget(outputMode, surroundVerticalFOV, surroundAspectRatio, this)),
_contextMenu(new QMenu(this))
{
setWindowTitle("Bino");
Expand Down Expand Up @@ -998,6 +998,12 @@ void Gui::setSurroundVerticalFieldOfView(float vfov)
_widget->update();
}

void Gui::setSurroundAspectRatio(float ar)
{
_widget->setSurroundAspectRatio(ar);
_widget->update();
}

void Gui::setFullscreen(bool f)
{
if (f && !(windowState() & Qt::WindowFullScreen)) {
Expand Down
3 changes: 2 additions & 1 deletion src/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ public slots:
virtual void moveEvent(QMoveEvent*) override;

public:
Gui(OutputMode outputMode, float surroundVerticalFOV, bool fullscreen);
Gui(OutputMode outputMode, float surroundVerticalFOV, float surroundAspectRatio, bool fullscreen);

static Gui* instance();

void setOutputMode(OutputMode mode);
void setSurroundVerticalFieldOfView(float vfov);
void setSurroundAspectRatio(float ar);
void setFullscreen(bool f);
};
14 changes: 13 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ int main(int argc, char* argv[])
parser.addOption({ "surround-vfov",
QCommandLineParser::tr("Set surround vertical field of view (default 50, range 5-115)."),
"degrees" });
parser.addOption({ "surround-ar",
QCommandLineParser::tr("Set surround aspect ratio (default 2, range 1.0-4.0)."),
"ratio" });
parser.addOption({ { "S", "swap-eyes" },
QCommandLineParser::tr("Swap left/right eye.") });
parser.addOption({ { "f", "fullscreen" },
Expand Down Expand Up @@ -273,6 +276,15 @@ int main(int argc, char* argv[])
return 1;
}
}
float surroundAspectRatio = 2.0f;
if (parser.isSet("surround-ar")) {
bool ok;
surroundAspectRatio = parser.value("surround-ar").toFloat(&ok);
if (!ok || surroundAspectRatio < 1.0f || surroundAspectRatio > 4.0f) {
LOG_FATAL("%s", qPrintable(QCommandLineParser::tr("Invalid argument for option %1").arg("--surround-ar")));
return 1;
}
}
InputMode inputMode = Input_Unknown;
if (parser.isSet("input")) {
bool ok;
Expand Down Expand Up @@ -757,7 +769,7 @@ int main(int argc, char* argv[])
return 1;
#endif
} else {
Gui gui(outputMode, surroundVerticalFOV, parser.isSet("fullscreen"));
Gui gui(outputMode, surroundVerticalFOV, surroundAspectRatio, parser.isSet("fullscreen"));
gui.show();
// wait for several seconds to process all events before starting
// the playlist, because otherwise playing might be finished before
Expand Down
18 changes: 15 additions & 3 deletions src/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

static const QSize SizeBase(16, 9);

Widget::Widget(OutputMode outputMode, float surroundVerticalFOV, QWidget* parent) :
Widget::Widget(OutputMode outputMode, float surroundVerticalFOV, float surroundAspectRatio, QWidget* parent) :
QOpenGLWidget(parent),
_sizeHint(0.5f * SizeBase),
_outputMode(outputMode),
Expand All @@ -54,6 +54,8 @@ Widget::Widget(OutputMode outputMode, float surroundVerticalFOV, QWidget* parent
{
setSurroundVerticalFieldOfView(surroundVerticalFOV);
_surroundVerticalFOVDefault = _surroundVerticalFOV; // to make sure clamping was applied
setSurroundAspectRatio(surroundAspectRatio);
_surroundAspectRatioDefault = _surroundAspectRatio; // to make sure clamping was applied
setUpdateBehavior(QOpenGLWidget::PartialUpdate);
setMouseTracking(true);
setMinimumSize(8, 8);
Expand Down Expand Up @@ -86,9 +88,15 @@ void Widget::setSurroundVerticalFieldOfView(float vfov)
_surroundVerticalFOV = qBound(5.0f, vfov, 115.0f);
}

void Widget::setSurroundAspectRatio(float ar)
{
_surroundAspectRatio = qBound(1.0f, ar, 4.0f);
}

void Widget::resetSurroundView()
{
_surroundVerticalFOV = _surroundVerticalFOVDefault;
_surroundAspectRatio = _surroundAspectRatioDefault;
_surroundHorizontalAngleBase = 0.0f;
_surroundVerticalAngleBase = 0.0f;
_surroundHorizontalAngleCurrent = 0.0f;
Expand Down Expand Up @@ -304,7 +312,7 @@ void Widget::paintGL()
QMatrix4x4 viewMatrix;
if (Bino::instance()->assumeSurroundMode() != Surround_Off) {
float verticalFieldOfView = qDegreesToRadians(_surroundVerticalFOV);
float aspectRatio = 2.0f; // always 2:1 for surround video!
float aspectRatio = _surroundAspectRatio;
float top = qTan(verticalFieldOfView * 0.5f);
float bottom = -top;
float right = top * aspectRatio;
Expand Down Expand Up @@ -438,7 +446,11 @@ void Widget::mouseMoveEvent(QMouseEvent* e)

void Widget::wheelEvent(QWheelEvent* e)
{
setSurroundVerticalFieldOfView(_surroundVerticalFOV - e->angleDelta().y() / 120.0f);
if (e->modifiers() & Qt::ShiftModifier) {
setSurroundAspectRatio(_surroundAspectRatio - (e->angleDelta().y() / 120.0f) * 0.05f * _surroundAspectRatio);
} else {
setSurroundVerticalFieldOfView(_surroundVerticalFOV - e->angleDelta().y() / 120.0f);
}
update();
}

Expand Down
5 changes: 4 additions & 1 deletion src/widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Q_OBJECT

float _surroundVerticalFOVDefault;
float _surroundVerticalFOV;
float _surroundAspectRatioDefault;
float _surroundAspectRatio;
bool _inSurroundMovement;
QPointF _surroundMovementStart;
float _surroundHorizontalAngleBase;
Expand All @@ -57,12 +59,13 @@ Q_OBJECT
void rebuildDisplayPrgIfNecessary(OutputMode outputMode);

public:
Widget(OutputMode outputMode, float surroundVerticalFOV, QWidget* parent = nullptr);
Widget(OutputMode outputMode, float surroundVerticalFOV, float surroundAspectRatio, QWidget* parent = nullptr);

bool isOpenGLStereo() const;
OutputMode outputMode() const;
void setOutputMode(OutputMode mode);
void setSurroundVerticalFieldOfView(float vfov);
void setSurroundAspectRatio(float ar);
void resetSurroundView();

virtual QSize sizeHint() const override;
Expand Down

0 comments on commit 30e7eb4

Please sign in to comment.