From cf6a8e98ebb793c0eb886292d4ab4d390a9e7f0f Mon Sep 17 00:00:00 2001 From: lisyarus Date: Mon, 31 Aug 2020 09:47:30 +0300 Subject: [PATCH] Change spherical camera: now X is right, Y is forward, Z is up --- libs/geom/include/psemek/geom/camera.hpp | 6 ++++-- libs/geom/source/camera.cpp | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libs/geom/include/psemek/geom/camera.hpp b/libs/geom/include/psemek/geom/camera.hpp index 7969bcff..976e9443 100644 --- a/libs/geom/include/psemek/geom/camera.hpp +++ b/libs/geom/include/psemek/geom/camera.hpp @@ -65,8 +65,10 @@ namespace psemek::geom struct spherical_camera : perspective_camera { - // assumes up is +Y - // + // assumes up is +Z + // azimuthal angle is in XY plane + // both angles zero gives X right, Y forward, and Z up + float azimuthal_angle; float elevation_angle; float distance; diff --git a/libs/geom/source/camera.cpp b/libs/geom/source/camera.cpp index 1bb8ef7b..9b54a9f3 100644 --- a/libs/geom/source/camera.cpp +++ b/libs/geom/source/camera.cpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include #include @@ -98,8 +100,10 @@ namespace psemek::geom { return translation({0.f, 0.f, -distance}).homogeneous_matrix() - * homogeneous(plane_rotation(1, 2, elevation_angle).matrix()) - * homogeneous(plane_rotation(2, 0, azimuthal_angle).matrix()) + * homogeneous(swap(1, 2).matrix()) + * homogeneous(scale({1.f, -1.f, 1.f}).matrix()) + * homogeneous(plane_rotation(2, 1, elevation_angle).matrix()) + * homogeneous(plane_rotation(1, 0, azimuthal_angle).matrix()) * translation({ -target[0], -target[1], -target[2] }).homogeneous_matrix() ; }