Add a free-flying camera

This commit is contained in:
Nikita Lisitsa 2020-10-02 19:18:55 +03:00
parent 23de4a520e
commit eb1f5d49ff
2 changed files with 26 additions and 0 deletions

View file

@ -92,4 +92,17 @@ namespace psemek::geom
matrix<float, 4, 4> view() const override;
};
struct free_camera
: perspective_camera
{
// 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;
point<float, 3> pos;
matrix<float, 4, 4> view() const override;
};
}

View file

@ -120,4 +120,17 @@ namespace psemek::geom
return tr.homogeneous_matrix();
}
matrix<float, 4, 4> free_camera::view() const
{
auto tr =
swap<float, 3>(1, 2).transform()
* scale<float, 3>({1.f, -1.f, 1.f}).transform()
* plane_rotation<float, 3>(1, 2, elevation_angle).transform()
* plane_rotation<float, 3>(1, 0, azimuthal_angle).transform()
* translation<float, 3>({ -pos[0], -pos[1], -pos[2] }).transform()
;
return tr.homogeneous_matrix();
}
}