Added method void Camera::rotate_local_around_pivot(const Vec3d& rotation_rad, const Vec3d& pivot) to rotate the camera around a generic point

This commit is contained in:
Enrico Turri 2020-01-16 12:00:54 +01:00
parent 89166accbe
commit a9529fbcdc
2 changed files with 13 additions and 3 deletions

View File

@ -442,12 +442,19 @@ void Camera::rotate_on_sphere(double delta_azimut_rad, double delta_zenit_rad)
void Camera::rotate_local_around_target(const Vec3d& rotation_rad)
{
Vec3d target = m_target;
translate_world(-target);
rotate_local_around_pivot(rotation_rad, m_target);
}
void Camera::rotate_local_around_pivot(const Vec3d& rotation_rad, const Vec3d& pivot)
{
// we use a copy of the pivot because a reference to the current m_target may be passed in (see i.e. rotate_local_around_target())
// and m_target is modified by the translate_world() calls
Vec3d center = pivot;
translate_world(-center);
m_view_matrix.rotate(Eigen::AngleAxisd(rotation_rad(0), get_dir_right()));
m_view_matrix.rotate(Eigen::AngleAxisd(rotation_rad(1), get_dir_up()));
m_view_matrix.rotate(Eigen::AngleAxisd(rotation_rad(2), get_dir_forward()));
translate_world(target);
translate_world(center);
}
bool Camera::is_looking_downward() const

View File

@ -136,6 +136,9 @@ public:
// rotate the camera around three axes parallel to the camera local axes and passing through m_target
void rotate_local_around_target(const Vec3d& rotation_rad);
// rotate the camera around three axes parallel to the camera local axes and passing through the given pivot point
void rotate_local_around_pivot(const Vec3d& rotation_rad, const Vec3d& pivot);
// returns true if the camera z axis (forward) is pointing in the negative direction of the world z axis
bool is_looking_downward() const;
#endif // ENABLE_6DOF_CAMERA