Merge pull request #3556 from uclaros/gl_messing

3D Navigation improvement features
This commit is contained in:
Alessandro Ranellucci 2016-11-21 18:50:17 +01:00 committed by GitHub
commit 0eb20004b3

View File

@ -46,6 +46,7 @@ use constant GROUND_Z => -0.02;
use constant DEFAULT_COLOR => [1,1,0]; use constant DEFAULT_COLOR => [1,1,0];
use constant SELECTED_COLOR => [0,1,0,1]; use constant SELECTED_COLOR => [0,1,0,1];
use constant HOVER_COLOR => [0.4,0.9,0,1]; use constant HOVER_COLOR => [0.4,0.9,0,1];
use constant PI => 3.1415927;
# make OpenGL::Array thread-safe # make OpenGL::Array thread-safe
{ {
@ -147,7 +148,15 @@ sub mouse_event {
} elsif ($e->LeftDClick) { } elsif ($e->LeftDClick) {
$self->on_double_click->() $self->on_double_click->()
if $self->on_double_click; if $self->on_double_click;
} elsif ($e->LeftDown || $e->RightDown) { } elsif ($e->MiddleDClick) {
if (@{$self->volumes}) {
$self->zoom_to_volumes;
} else {
$self->zoom_to_bed;
}
$self->_dirty(1);
$self->Refresh;
} elsif (($e->LeftDown || $e->RightDown) && not $e->ShiftDown) {
# If user pressed left or right button we first check whether this happened # If user pressed left or right button we first check whether this happened
# on a volume or not. # on a volume or not.
my $volume_idx = $self->_hover_volume_idx // -1; my $volume_idx = $self->_hover_volume_idx // -1;
@ -209,7 +218,16 @@ sub mouse_event {
$self->_dragged(1); $self->_dragged(1);
$self->Refresh; $self->Refresh;
} elsif ($e->Dragging) { } elsif ($e->Dragging) {
if ($e->LeftIsDown) { if ($e->AltDown) {
# Move the camera center on the Z axis based on mouse Y axis movement
if (defined $self->_drag_start_pos) {
my $orig = $self->_drag_start_pos;
$self->_camera_target->translate(0, 0, $pos->y - $orig->y);
$self->on_viewport_changed->() if $self->on_viewport_changed;
$self->Refresh;
}
$self->_drag_start_pos($pos);
} elsif ($e->LeftIsDown) {
# if dragging over blank area with left button, rotate # if dragging over blank area with left button, rotate
if (defined $self->_drag_start_pos) { if (defined $self->_drag_start_pos) {
my $orig = $self->_drag_start_pos; my $orig = $self->_drag_start_pos;
@ -833,11 +851,46 @@ sub Render {
glDisable(GL_BLEND); glDisable(GL_BLEND);
} }
if (defined $self->_drag_start_pos || defined $self->_drag_start_xy) {
$self->draw_center_of_rotation($self->_camera_target->x, $self->_camera_target->y, $self->_camera_target->z);
}
glFlush(); glFlush();
$self->SwapBuffers(); $self->SwapBuffers();
} }
sub draw_axes {
my ($self, $x, $y, $z, $length, $width, $allways_visible) = @_;
if ($allways_visible) {
glDisable(GL_DEPTH_TEST);
} else {
glEnable(GL_DEPTH_TEST);
}
glLineWidth($width);
glBegin(GL_LINES);
# draw line for x axis
glColor3f(1, 0, 0);
glVertex3f($x, $y, $z);
glVertex3f($x + $length, $y, $z);
# draw line for y axis
glColor3f(0, 1, 0);
glVertex3f($x, $y, $z);
glVertex3f($x, $y + $length, $z);
# draw line for Z axis
glColor3f(0, 0, 1);
glVertex3f($x, $y, $z);
glVertex3f($x, $y, $z + $length);
glEnd();
}
sub draw_center_of_rotation {
my ($self, $x, $y, $z) = @_;
$self->draw_axes($x, $y, $z, 10, 1, 1);
$self->draw_axes($x, $y, $z, 10, 4, 0);
}
sub draw_volumes { sub draw_volumes {
my ($self, $fakecolor) = @_; my ($self, $fakecolor) = @_;