From 6f1fd51c2e526336b8621f3deb37ab50dbe8ec06 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 25 Aug 2013 02:07:51 +0200 Subject: [PATCH] Keep objects vertical in 3D preview --- lib/Slic3r/GUI/PreviewCanvas.pm | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/Slic3r/GUI/PreviewCanvas.pm b/lib/Slic3r/GUI/PreviewCanvas.pm index c5c82e94..0b37d50a 100644 --- a/lib/Slic3r/GUI/PreviewCanvas.pm +++ b/lib/Slic3r/GUI/PreviewCanvas.pm @@ -13,15 +13,19 @@ use Wx::GLCanvas qw(:all); __PACKAGE__->mk_accessors( qw(quat dirty init mview_init mesh_center mesh_size - verts norms initpos) ); + verts norms initpos + sphi stheta) ); use constant TRACKBALLSIZE => 0.8; +use constant TURNTABLE_MODE => 1; sub new { my ($class, $parent, $mesh) = @_; my $self = $class->SUPER::new($parent); $self->quat((0, 0, 0, 1)); + $self->sphi(45); + $self->stheta(-45); # prepare mesh { @@ -189,12 +193,17 @@ sub handle_rotation { my $orig = $self->initpos; my $new = $e->GetPosition(); my $size = $self->GetClientSize(); - my @quat = trackball($orig->x / ($size->width / 2) - 1, - 1 - $orig->y / ($size->height / 2), #/ - $new->x / ($size->width / 2) - 1, - 1 - $new->y / ($size->height / 2), #/ - ); - $self->quat(mulquats($self->quat, \@quat)); + if (TURNTABLE_MODE) { + $self->sphi($self->sphi + ($new->x - $orig->x)*TRACKBALLSIZE); + $self->stheta($self->stheta + ($new->y - $orig->y)*TRACKBALLSIZE); #- + } else { + my @quat = trackball($orig->x / ($size->width / 2) - 1, + 1 - $orig->y / ($size->height / 2), #/ + $new->x / ($size->width / 2) - 1, + 1 - $new->y / ($size->height / 2), #/ + ); + $self->quat(mulquats($self->quat, \@quat)); + } $self->initpos($new); $self->Refresh; } @@ -344,6 +353,8 @@ sub Render { glTranslatef(0, 0, -max(@$mesh_size[0..1])); my @rotmat = quat_to_rotmatrix($self->quat); glMultMatrixd_p(@rotmat[0..15]); + glRotatef($self->stheta, 1, 0, 0); + glRotatef($self->sphi, 0, 0, 1); glTranslatef(map -$_, @{ $self->mesh_center }); $self->draw_mesh;