Added support for distance between camera position and camera target
This commit is contained in:
parent
26d48b7f52
commit
f0b228c4d2
2 changed files with 15 additions and 5 deletions
|
@ -22,11 +22,13 @@ static const float VIEW_REAR[2] = { 180.0f, 90.0f };
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
|
const float Camera::DefaultDistance = 1000.0f;
|
||||||
|
|
||||||
Camera::Camera()
|
Camera::Camera()
|
||||||
: type(Ortho)
|
: type(Ortho)
|
||||||
, zoom(1.0f)
|
, zoom(1.0f)
|
||||||
, phi(45.0f)
|
, phi(45.0f)
|
||||||
// , distance(0.0f)
|
, distance(DefaultDistance)
|
||||||
, requires_zoom_to_bed(false)
|
, requires_zoom_to_bed(false)
|
||||||
, inverted_phi(false)
|
, inverted_phi(false)
|
||||||
, m_theta(45.0f)
|
, m_theta(45.0f)
|
||||||
|
@ -107,12 +109,18 @@ void Camera::apply_viewport(int x, int y, unsigned int w, unsigned int h) const
|
||||||
|
|
||||||
void Camera::apply_view_matrix() const
|
void Camera::apply_view_matrix() const
|
||||||
{
|
{
|
||||||
|
double theta_rad = Geometry::deg2rad(-(double)m_theta);
|
||||||
|
double phi_rad = Geometry::deg2rad((double)phi);
|
||||||
|
double sin_theta = ::sin(theta_rad);
|
||||||
|
Vec3d camera_pos = m_target + (double)distance * Vec3d(sin_theta * ::sin(phi_rad), sin_theta * ::cos(phi_rad), ::cos(theta_rad));
|
||||||
|
|
||||||
glsafe(::glMatrixMode(GL_MODELVIEW));
|
glsafe(::glMatrixMode(GL_MODELVIEW));
|
||||||
glsafe(::glLoadIdentity());
|
glsafe(::glLoadIdentity());
|
||||||
|
|
||||||
glsafe(::glRotatef(-m_theta, 1.0f, 0.0f, 0.0f)); // pitch
|
glsafe(::glRotatef(-m_theta, 1.0f, 0.0f, 0.0f)); // pitch
|
||||||
glsafe(::glRotatef(phi, 0.0f, 0.0f, 1.0f)); // yaw
|
glsafe(::glRotatef(phi, 0.0f, 0.0f, 1.0f)); // yaw
|
||||||
glsafe(::glTranslated(-m_target(0), -m_target(1), -m_target(2))); // target to origin
|
|
||||||
|
glsafe(::glTranslated(-camera_pos(0), -camera_pos(1), -camera_pos(2)));
|
||||||
|
|
||||||
glsafe(::glGetDoublev(GL_MODELVIEW_MATRIX, m_view_matrix.data()));
|
glsafe(::glGetDoublev(GL_MODELVIEW_MATRIX, m_view_matrix.data()));
|
||||||
}
|
}
|
||||||
|
@ -136,8 +144,7 @@ void Camera::apply_projection(const BoundingBoxf3& box) const
|
||||||
// FIXME: calculate a tighter value for depth will improve z-fighting
|
// FIXME: calculate a tighter value for depth will improve z-fighting
|
||||||
// Set at least some minimum depth in case the bounding box is empty to avoid an OpenGL driver error.
|
// Set at least some minimum depth in case the bounding box is empty to avoid an OpenGL driver error.
|
||||||
double depth = std::max(1.0, 5.0 * box.max_size());
|
double depth = std::max(1.0, 5.0 * box.max_size());
|
||||||
apply_ortho_projection(-w2, w2, -h2, h2, -depth, depth);
|
apply_ortho_projection(-w2, w2, -h2, h2, (double)distance - depth, (double)distance + depth);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// case Perspective:
|
// case Perspective:
|
||||||
|
|
|
@ -9,6 +9,8 @@ namespace GUI {
|
||||||
|
|
||||||
struct Camera
|
struct Camera
|
||||||
{
|
{
|
||||||
|
static const float DefaultDistance;
|
||||||
|
|
||||||
enum EType : unsigned char
|
enum EType : unsigned char
|
||||||
{
|
{
|
||||||
Unknown,
|
Unknown,
|
||||||
|
@ -20,7 +22,8 @@ struct Camera
|
||||||
EType type;
|
EType type;
|
||||||
float zoom;
|
float zoom;
|
||||||
float phi;
|
float phi;
|
||||||
// float distance;
|
// Distance between camera position and camera target measured along the camera Z axis
|
||||||
|
float distance;
|
||||||
bool requires_zoom_to_bed;
|
bool requires_zoom_to_bed;
|
||||||
bool inverted_phi;
|
bool inverted_phi;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue