Camera angle clamping moved to c++

This commit is contained in:
Enrico Turri 2018-05-14 12:08:23 +02:00
parent 1fd59144c7
commit a73cb45792
3 changed files with 118 additions and 33 deletions

View file

@ -139,7 +139,9 @@ use constant MANIPULATION_IDLE => 0;
use constant MANIPULATION_DRAGGING => 1;
use constant MANIPULATION_LAYER_HEIGHT => 2;
use constant GIMBALL_LOCK_THETA_MAX => 180;
#==============================================================================================================================
#use constant GIMBALL_LOCK_THETA_MAX => 180;
#==============================================================================================================================
use constant VARIABLE_LAYER_THICKNESS_BAR_WIDTH => 70;
use constant VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT => 22;
@ -587,8 +589,6 @@ sub mouse_event {
#==============================================================================================================================
Slic3r::GUI::_3DScene::set_camera_phi($self, Slic3r::GUI::_3DScene::get_camera_phi($self) + ($pos->x - $orig->x) * TRACKBALLSIZE);
Slic3r::GUI::_3DScene::set_camera_theta($self, Slic3r::GUI::_3DScene::get_camera_theta($self) - ($pos->y - $orig->y) * TRACKBALLSIZE);
Slic3r::GUI::_3DScene::set_camera_theta($self, GIMBALL_LOCK_THETA_MAX) if Slic3r::GUI::_3DScene::get_camera_theta($self) > GIMBALL_LOCK_THETA_MAX;
Slic3r::GUI::_3DScene::set_camera_theta($self, 0) if Slic3r::GUI::_3DScene::get_camera_theta($self) < 0;
# $self->_sphi($self->_sphi + ($pos->x - $orig->x) * TRACKBALLSIZE);
# $self->_stheta($self->_stheta - ($pos->y - $orig->y) * TRACKBALLSIZE); #-
@ -791,9 +791,6 @@ sub select_view {
#==============================================================================================================================
Slic3r::GUI::_3DScene::set_camera_phi($self, $dirvec->[0]);
Slic3r::GUI::_3DScene::set_camera_theta($self, $dirvec->[1]);
# Avoid gimball lock.
Slic3r::GUI::_3DScene::set_camera_theta($self, GIMBALL_LOCK_THETA_MAX) if Slic3r::GUI::_3DScene::get_camera_theta($self) > GIMBALL_LOCK_THETA_MAX;
Slic3r::GUI::_3DScene::set_camera_theta($self, 0) if Slic3r::GUI::_3DScene::get_camera_theta($self) < 0;
# $self->_sphi($dirvec->[0]);
# $self->_stheta($dirvec->[1]);

View file

@ -4,23 +4,34 @@
#include <iostream>
static const float GIMBALL_LOCK_THETA_MAX = 180.0f;
namespace Slic3r {
namespace GUI {
GLCanvas3D::Camera::Camera()
: type(CT_Ortho)
, zoom(1.0f)
, phi(45.0f)
, theta(45.0f)
, distance(0.0f)
, target(0.0, 0.0, 0.0)
: m_type(CT_Ortho)
, m_zoom(1.0f)
, m_phi(45.0f)
, m_theta(45.0f)
, m_distance(0.0f)
, m_target(0.0, 0.0, 0.0)
{
}
GLCanvas3D::Camera::EType GLCanvas3D::Camera::get_type() const
{
return m_type;
}
void GLCanvas3D::Camera::set_type(GLCanvas3D::Camera::EType type)
{
m_type = type;
}
std::string GLCanvas3D::Camera::get_type_as_string() const
{
switch (type)
switch (m_type)
{
default:
case CT_Unknown:
@ -32,6 +43,63 @@ std::string GLCanvas3D::Camera::get_type_as_string() const
};
}
float GLCanvas3D::Camera::get_zoom() const
{
return m_zoom;
}
void GLCanvas3D::Camera::set_zoom(float zoom)
{
m_zoom = zoom;
}
float GLCanvas3D::Camera::get_phi() const
{
return m_phi;
}
void GLCanvas3D::Camera::set_phi(float phi)
{
m_phi = phi;
}
float GLCanvas3D::Camera::get_theta() const
{
return m_theta;
}
void GLCanvas3D::Camera::set_theta(float theta)
{
m_theta = theta;
// clamp angle
if (m_theta > GIMBALL_LOCK_THETA_MAX)
m_theta = GIMBALL_LOCK_THETA_MAX;
if (m_theta < 0.0f)
m_theta = 0.0f;
}
float GLCanvas3D::Camera::get_distance() const
{
return m_distance;
}
void GLCanvas3D::Camera::set_distance(float distance)
{
m_distance = distance;
}
const Pointf3& GLCanvas3D::Camera::get_target() const
{
return m_target;
}
void GLCanvas3D::Camera::set_target(const Pointf3& target)
{
m_target = target;
}
GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context)
: m_canvas(canvas)
, m_context(context)
@ -62,12 +130,12 @@ bool GLCanvas3D::is_shown_on_screen() const
GLCanvas3D::Camera::EType GLCanvas3D::get_camera_type() const
{
return m_camera.type;
return m_camera.get_type();
}
void GLCanvas3D::set_camera_type(GLCanvas3D::Camera::EType type)
{
m_camera.type = type;
m_camera.set_type(type);
}
std::string GLCanvas3D::get_camera_type_as_string() const
@ -77,52 +145,52 @@ std::string GLCanvas3D::get_camera_type_as_string() const
float GLCanvas3D::get_camera_zoom() const
{
return m_camera.zoom;
return m_camera.get_zoom();
}
void GLCanvas3D::set_camera_zoom(float zoom)
{
m_camera.zoom = zoom;
m_camera.set_zoom(zoom);
}
float GLCanvas3D::get_camera_phi() const
{
return m_camera.phi;
return m_camera.get_phi();
}
void GLCanvas3D::set_camera_phi(float phi)
{
m_camera.phi = phi;
m_camera.set_phi(phi);
}
float GLCanvas3D::get_camera_theta() const
{
return m_camera.theta;
return m_camera.get_theta();
}
void GLCanvas3D::set_camera_theta(float theta)
{
m_camera.theta = theta;
m_camera.set_theta(theta);
}
float GLCanvas3D::get_camera_distance() const
{
return m_camera.distance;
return m_camera.get_distance();
}
void GLCanvas3D::set_camera_distance(float distance)
{
m_camera.distance = distance;
m_camera.set_distance(distance);
}
const Pointf3& GLCanvas3D::get_camera_target() const
{
return m_camera.target;
return m_camera.get_target();
}
void GLCanvas3D::set_camera_target(const Pointf3& target)
{
m_camera.target = target;
m_camera.set_target(target);
}
void GLCanvas3D::on_size(wxSizeEvent& evt)

View file

@ -13,8 +13,9 @@ namespace GUI {
class GLCanvas3D
{
public:
struct Camera
class Camera
{
public:
enum EType : unsigned char
{
CT_Unknown,
@ -23,16 +24,35 @@ public:
CT_Count
};
EType type;
float zoom;
float phi;
float theta;
float distance;
Pointf3 target;
private:
EType m_type;
float m_zoom;
float m_phi;
float m_theta;
float m_distance;
Pointf3 m_target;
public:
Camera();
Camera::EType get_type() const;
void set_type(Camera::EType type);
std::string get_type_as_string() const;
float get_zoom() const;
void set_zoom(float zoom);
float get_phi() const;
void set_phi(float phi);
float get_theta() const;
void set_theta(float theta);
float get_distance() const;
void set_distance(float distance);
const Pointf3& get_target() const;
void set_target(const Pointf3& target);
};
private: