SPE-1251 - Fixed crash in Gizmo Rotate when rotating an object when the camera is using orthographic projection

This commit is contained in:
enricoturri1966 2022-07-20 13:45:21 +02:00
parent 90c49f4c1a
commit 42dbaf92bf

View File

@ -852,7 +852,21 @@ Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray, cons
#endif // ENABLE_WORLD_COORDINATE
m.translate(-m_center);
return transform(mouse_ray, m).intersect_plane(0.0);
const Linef3 local_mouse_ray = transform(mouse_ray, m);
if (std::abs(local_mouse_ray.vector().dot(Vec3d::UnitZ())) < EPSILON) {
// if the ray is parallel to the plane containing the circle
if (std::abs(local_mouse_ray.vector().dot(Vec3d::UnitY())) > 1.0 - EPSILON)
// if the ray is parallel to grabber direction
return Vec3d::UnitX();
else {
const Vec3d world_pos = (local_mouse_ray.a.x() >= 0.0) ? mouse_ray.a - m_center : mouse_ray.b - m_center;
m.translate(m_center);
return m * world_pos;
}
}
else
return local_mouse_ray.intersect_plane(0.0);
}
GLGizmoRotate3D::GLGizmoRotate3D(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id)