Removed unused methods from 3DScene

This commit is contained in:
Enrico Turri 2018-05-31 08:44:39 +02:00
parent 30a3b2179b
commit cf8e7475ca
3 changed files with 74 additions and 110 deletions

View File

@ -188,6 +188,7 @@ sub new {
$self->volumes(Slic3r::GUI::_3DScene::GLVolume::Collection->new); $self->volumes(Slic3r::GUI::_3DScene::GLVolume::Collection->new);
#============================================================================================================================== #==============================================================================================================================
Slic3r::GUI::_3DScene::set_volumes($self, $self->volumes); Slic3r::GUI::_3DScene::set_volumes($self, $self->volumes);
Slic3r::GUI::_3DScene::reset_volumes($self);
#============================================================================================================================== #==============================================================================================================================
# 3D point in model space # 3D point in model space
@ -202,10 +203,7 @@ sub new {
# $self->{layer_height_edit_last_object_id} = -1; # $self->{layer_height_edit_last_object_id} = -1;
# $self->{layer_height_edit_last_z} = 0.; # $self->{layer_height_edit_last_z} = 0.;
# $self->{layer_height_edit_last_action} = 0; # $self->{layer_height_edit_last_action} = 0;
#============================================================================================================================== #
#==============================================================================================================================
Slic3r::GUI::_3DScene::reset_volumes($self);
# $self->reset_objects; # $self->reset_objects;
#============================================================================================================================== #==============================================================================================================================
@ -215,8 +213,6 @@ sub new {
}); });
#======================================================================================================================= #=======================================================================================================================
# EVT_SIZE($self, sub { $self->_dirty(1) }); # EVT_SIZE($self, sub { $self->_dirty(1) });
#=======================================================================================================================
#==============================================================================================================================
# EVT_IDLE($self, sub { # EVT_IDLE($self, sub {
# return unless $self->_dirty; # return unless $self->_dirty;
# return if !$self->IsShownOnScreen; # return if !$self->IsShownOnScreen;
@ -362,45 +358,33 @@ sub Destroy {
# } # }
# return -1; # return -1;
#} #}
#============================================================================================================================== #
## Returns an array with (left, top, right, bottom) of the variable layer thickness bar on the screen.
# Returns an array with (left, top, right, bottom) of the variable layer thickness bar on the screen. #sub _variable_layer_thickness_bar_rect_screen {
sub _variable_layer_thickness_bar_rect_screen { # my ($self) = @_;
my ($self) = @_; # my ($cw, $ch) = $self->GetSizeWH;
my ($cw, $ch) = $self->GetSizeWH; # return ($cw - VARIABLE_LAYER_THICKNESS_BAR_WIDTH, 0, $cw, $ch - VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT);
return ($cw - VARIABLE_LAYER_THICKNESS_BAR_WIDTH, 0, $cw, $ch - VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT); #}
} #
#sub _variable_layer_thickness_bar_rect_viewport {
sub _variable_layer_thickness_bar_rect_viewport { # my ($self) = @_;
my ($self) = @_; # my ($cw, $ch) = $self->GetSizeWH;
my ($cw, $ch) = $self->GetSizeWH;
#==============================================================================================================================
my $zoom = Slic3r::GUI::_3DScene::get_camera_zoom($self);
return ((0.5*$cw-VARIABLE_LAYER_THICKNESS_BAR_WIDTH)/$zoom, (-0.5*$ch+VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT)/$zoom, $cw/(2*$zoom), $ch/(2*$zoom));
# return ((0.5*$cw-VARIABLE_LAYER_THICKNESS_BAR_WIDTH)/$self->_zoom, (-0.5*$ch+VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT)/$self->_zoom, $cw/(2*$self->_zoom), $ch/(2*$self->_zoom)); # return ((0.5*$cw-VARIABLE_LAYER_THICKNESS_BAR_WIDTH)/$self->_zoom, (-0.5*$ch+VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT)/$self->_zoom, $cw/(2*$self->_zoom), $ch/(2*$self->_zoom));
#============================================================================================================================== #}
} #
#==============================================================================================================================
## Returns an array with (left, top, right, bottom) of the variable layer thickness bar on the screen. ## Returns an array with (left, top, right, bottom) of the variable layer thickness bar on the screen.
#sub _variable_layer_thickness_reset_rect_screen { #sub _variable_layer_thickness_reset_rect_screen {
# my ($self) = @_; # my ($self) = @_;
# my ($cw, $ch) = $self->GetSizeWH; # my ($cw, $ch) = $self->GetSizeWH;
# return ($cw - VARIABLE_LAYER_THICKNESS_BAR_WIDTH, $ch - VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT, $cw, $ch); # return ($cw - VARIABLE_LAYER_THICKNESS_BAR_WIDTH, $ch - VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT, $cw, $ch);
#} #}
#============================================================================================================================== #
#sub _variable_layer_thickness_reset_rect_viewport {
sub _variable_layer_thickness_reset_rect_viewport { # my ($self) = @_;
my ($self) = @_; # my ($cw, $ch) = $self->GetSizeWH;
my ($cw, $ch) = $self->GetSizeWH;
#==============================================================================================================================
my $zoom = Slic3r::GUI::_3DScene::get_camera_zoom($self);
return ((0.5*$cw-VARIABLE_LAYER_THICKNESS_BAR_WIDTH)/$zoom, -$ch/(2*$zoom), $cw/(2*$zoom), (-0.5*$ch+VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT)/$zoom);
# return ((0.5*$cw-VARIABLE_LAYER_THICKNESS_BAR_WIDTH)/$self->_zoom, -$ch/(2*$self->_zoom), $cw/(2*$self->_zoom), (-0.5*$ch+VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT)/$self->_zoom); # return ((0.5*$cw-VARIABLE_LAYER_THICKNESS_BAR_WIDTH)/$self->_zoom, -$ch/(2*$self->_zoom), $cw/(2*$self->_zoom), (-0.5*$ch+VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT)/$self->_zoom);
#============================================================================================================================== #}
} #
#==============================================================================================================================
#sub _variable_layer_thickness_bar_rect_mouse_inside { #sub _variable_layer_thickness_bar_rect_mouse_inside {
# my ($self, $mouse_evt) = @_; # my ($self, $mouse_evt) = @_;
# my ($bar_left, $bar_top, $bar_right, $bar_bottom) = $self->_variable_layer_thickness_bar_rect_screen; # my ($bar_left, $bar_top, $bar_right, $bar_bottom) = $self->_variable_layer_thickness_bar_rect_screen;
@ -1401,41 +1385,32 @@ sub Render {
$self->SetCurrent($context); $self->SetCurrent($context);
$self->InitGL; $self->InitGL;
glClearColor(1, 1, 1, 1);
glClearDepth(1);
glDepthFunc(GL_LESS);
#==============================================================================================================================
# glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#==============================================================================================================================
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if (!TURNTABLE_MODE) {
# Shift the perspective camera.
#==============================================================================================================================
my $camera_pos = Slic3r::Pointf3->new(0,0,-Slic3r::GUI::_3DScene::get_camera_distance($self));
# my $camera_pos = Slic3r::Pointf3->new(0,0,-$self->_camera_distance);
#==============================================================================================================================
glTranslatef(@$camera_pos);
}
if (TURNTABLE_MODE) {
# Turntable mode is enabled by default.
#==============================================================================================================================
glRotatef(-Slic3r::GUI::_3DScene::get_camera_theta($self), 1, 0, 0); # pitch
glRotatef(Slic3r::GUI::_3DScene::get_camera_phi($self), 0, 0, 1); # yaw
# glRotatef(-$self->_stheta, 1, 0, 0); # pitch
# glRotatef($self->_sphi, 0, 0, 1); # yaw
#==============================================================================================================================
} else {
my @rotmat = quat_to_rotmatrix($self->quat);
glMultMatrixd_p(@rotmat[0..15]);
}
#============================================================================================================================== #==============================================================================================================================
Slic3r::GUI::_3DScene::render($self); Slic3r::GUI::_3DScene::render($self);
# glClearColor(1, 1, 1, 1);
# glClearDepth(1);
# glDepthFunc(GL_LESS);
# glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#
# glMatrixMode(GL_MODELVIEW);
# glLoadIdentity();
#
# if (!TURNTABLE_MODE) {
# # Shift the perspective camera.
# my $camera_pos = Slic3r::Pointf3->new(0,0,-$self->_camera_distance);
# glTranslatef(@$camera_pos);
# }
#
# if (TURNTABLE_MODE) {
# # Turntable mode is enabled by default.
# glRotatef(-$self->_stheta, 1, 0, 0); # pitch
# glRotatef($self->_sphi, 0, 0, 1); # yaw
# } else {
# my @rotmat = quat_to_rotmatrix($self->quat);
# glMultMatrixd_p(@rotmat[0..15]);
# }
#
# glTranslatef(@{ $self->_camera_target->negative }); # glTranslatef(@{ $self->_camera_target->negative });
# #
# # light from above # # light from above

View File

@ -15,7 +15,6 @@
#include <iostream> #include <iostream>
#include <float.h> #include <float.h>
static const bool TURNTABLE_MODE = true;
static const float GIMBALL_LOCK_THETA_MAX = 180.0f; static const float GIMBALL_LOCK_THETA_MAX = 180.0f;
static const float GROUND_Z = -0.02f; static const float GROUND_Z = -0.02f;
@ -1082,10 +1081,12 @@ GLCanvas3D::~GLCanvas3D()
bool GLCanvas3D::init(bool useVBOs, bool use_legacy_opengl) bool GLCanvas3D::init(bool useVBOs, bool use_legacy_opengl)
{ {
::glClearColor(0.0f, 0.0f, 0.0f, 1.0f); ::glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
::glEnable(GL_DEPTH_TEST);
::glClearDepth(1.0f); ::glClearDepth(1.0f);
::glDepthFunc(GL_LEQUAL); ::glDepthFunc(GL_LESS);
::glEnable(GL_DEPTH_TEST);
::glEnable(GL_CULL_FACE); ::glEnable(GL_CULL_FACE);
::glEnable(GL_BLEND); ::glEnable(GL_BLEND);
::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -1109,6 +1110,14 @@ bool GLCanvas3D::init(bool useVBOs, bool use_legacy_opengl)
GLfloat diffuse[4] = { 0.2f, 0.2f, 0.2f, 1.0f }; GLfloat diffuse[4] = { 0.2f, 0.2f, 0.2f, 1.0f };
::glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse); ::glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
// light from above
GLfloat position1[4] = { -0.5f, -0.5f, 1.0f, 0.0f };
::glLightfv(GL_LIGHT0, GL_POSITION, position1);
GLfloat specular1[4] = { 0.2f, 0.2f, 0.2f, 1.0f };
::glLightfv(GL_LIGHT0, GL_SPECULAR, specular1);
GLfloat diffuse1[4] = { 0.5f, 0.5f, 0.5f, 1.0f };
::glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse1);
// Enables Smooth Color Shading; try GL_FLAT for (lack of) fun. // Enables Smooth Color Shading; try GL_FLAT for (lack of) fun.
::glShadeModel(GL_SMOOTH); ::glShadeModel(GL_SMOOTH);
@ -1574,21 +1583,7 @@ void GLCanvas3D::render(bool useVBOs) const
if (m_canvas == nullptr) if (m_canvas == nullptr)
return; return;
Pointf3 neg_target = get_camera_target().negative(); _camera_tranform();
::glTranslatef((GLfloat)neg_target.x, (GLfloat)neg_target.y, (GLfloat)neg_target.z);
// light from above
GLfloat position0[4] = { -0.5f, -0.5f, 1.0f, 0.0f };
::glLightfv(GL_LIGHT0, GL_POSITION, position0);
GLfloat specular[4] = { 0.2f, 0.2f, 0.2f, 1.0f };
::glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
GLfloat diffuse[4] = { 0.5f, 0.5f, 0.5f, 1.0f };
::glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
// Head light
GLfloat position1[4] = { 1.0f, 0.0f, 1.0f, 0.0f };
::glLightfv(GL_LIGHT1, GL_POSITION, position1);
_picking_pass(); _picking_pass();
_render_background(); _render_background();
_render_bed(); _render_bed();
@ -1941,27 +1936,8 @@ float GLCanvas3D::_get_zoom_to_bounding_box_factor(const BoundingBoxf3& bbox) co
// project the bbox vertices on a plane perpendicular to the camera forward axis // project the bbox vertices on a plane perpendicular to the camera forward axis
// then calculates the vertices coordinate on this plane along the camera xy axes // then calculates the vertices coordinate on this plane along the camera xy axes
// we need the view matrix, we let opengl calculate it(same as done in render sub) // we need the view matrix, we let opengl calculate it (same as done in render())
::glMatrixMode(GL_MODELVIEW); _camera_tranform();
::glLoadIdentity();
if (TURNTABLE_MODE)
{
// Turntable mode is enabled by default.
::glRotatef(-get_camera_theta(), 1.0f, 0.0f, 0.0f); // pitch
::glRotatef(get_camera_phi(), 0.0f, 0.0f, 1.0f); // yaw
}
else
{
// Shift the perspective camera.
Pointf3 camera_pos(0.0, 0.0, -(coordf_t)get_camera_distance());
::glTranslatef((float)camera_pos.x, (float)camera_pos.y, (float)camera_pos.z);
// my @rotmat = quat_to_rotmatrix($self->quat); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< TEMPORARY COMMENTED OUT
// glMultMatrixd_p(@rotmat[0..15]); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< TEMPORARY COMMENTED OUT
}
const Pointf3& target = get_camera_target();
::glTranslatef(-(float)target.x, -(float)target.y, -(float)target.z);
// get the view matrix back from opengl // get the view matrix back from opengl
GLfloat matrix[16]; GLfloat matrix[16];
@ -2055,6 +2031,18 @@ void GLCanvas3D::_refresh_if_shown_on_screen()
} }
} }
void GLCanvas3D::_camera_tranform() const
{
::glMatrixMode(GL_MODELVIEW);
::glLoadIdentity();
::glRotatef(-get_camera_theta(), 1.0f, 0.0f, 0.0f); // pitch
::glRotatef(get_camera_phi(), 0.0f, 0.0f, 1.0f); // yaw
Pointf3 neg_target = get_camera_target().negative();
::glTranslatef((GLfloat)neg_target.x, (GLfloat)neg_target.y, (GLfloat)neg_target.z);
}
void GLCanvas3D::_picking_pass() const void GLCanvas3D::_picking_pass() const
{ {
if (is_picking_enabled() && !is_mouse_dragging() && (m_volumes != nullptr)) if (is_picking_enabled() && !is_mouse_dragging() && (m_volumes != nullptr))

View File

@ -482,6 +482,7 @@ private:
void _mark_volumes_for_layer_height() const; void _mark_volumes_for_layer_height() const;
void _refresh_if_shown_on_screen(); void _refresh_if_shown_on_screen();
void _camera_tranform() const;
void _picking_pass() const; void _picking_pass() const;
void _render_background() const; void _render_background() const;
void _render_bed() const; void _render_bed() const;