We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 941911c commit e9cffe8Copy full SHA for e9cffe8
Changes
@@ -1,5 +1,6 @@
1
- non-trivial tests added
2
- add overloads of ::Quaternion
3
+- change mouse control from ArcBall-like to orbiting-camera-like
4
5
2.100 2025-01-16
6
- adjust MathGraph and Labels so Debian packaging is happy
lib/PDL/Graphics/TriD/ArcBall.pm
@@ -106,4 +106,26 @@ sub get_z {
106
cos($dist*PI/2);
107
}
108
109
+package PDL::Graphics::TriD::Orbiter;
110
+
111
+use base qw/PDL::Graphics::TriD::QuaterController/;
112
+BEGIN { *PI = \&PDL::Graphics::TriD::QuaterController::PI; }
113
114
+# we rotate about our space's "Z" because that's what we made vertical
115
+# this is different from the OpenGL Z axis which is towards the viewer
116
+sub mouse_moved {
117
+ my($this,$x0,$y0,$x1,$y1) = @_;
118
+ $this->SUPER::mouse_moved($x0,$y0,$x1,$y1);
119
+ my ($dx, $dy) = ($x1-$x0, $y1-$y0);
120
+ $dx /= $this->{W}/2; $dy /= $this->{H}/2; # scale to whole window not SC
121
+ my ($x_rad, $y_rad) = map PI*$_, $dx, $dy;
122
+ my $q_horiz = PDL::Graphics::TriD::Quaternion->new(cos $x_rad/2, 0, 0, sin $x_rad/2);
123
+ my $q_vert = PDL::Graphics::TriD::Quaternion->new(cos $y_rad/2, sin $y_rad/2, 0, 0);
124
+ if ($this->{Inv}) {
125
+ $_->invert_rotation_this for $q_horiz, $q_vert;
126
+ }
127
+ $this->{Quat} .= $q_vert * $this->{Quat} * $q_horiz;
128
+ 1; # signals a refresh
129
+}
130
131
1;
lib/PDL/Graphics/TriD/Window.pm
@@ -67,7 +67,7 @@ sub new_viewport {
67
my $cont = $options->{Transformer} // PDL::Graphics::TriD::SimpleController->new;
68
$vp->transformer($cont);
69
if (ref($ev)){
70
- $ev->set_button(0,PDL::Graphics::TriD::ArcCone->new( $vp, 0, $cont->{WRotation}));
+ $ev->set_button(0,PDL::Graphics::TriD::Orbiter->new( $vp, 0, $cont->{WRotation}));
71
$ev->set_button(2,PDL::Graphics::TriD::SimpleScaler->new( $vp, \$cont->{CDistance}));
72
$ev->set_button(3,PDL::Graphics::TriD::ScrollButtonScaler->new( $vp, \$cont->{CDistance}, 0.9));
73
$ev->set_button(4,PDL::Graphics::TriD::ScrollButtonScaler->new( $vp, \$cont->{CDistance}, 1.1));
t/arcball.t
@@ -62,4 +62,12 @@ is_qua $arcbowl->xy2qua(75,75), [0,0.598834,-0.598834,0.531784];
62
mousemove $arcbowl, 50, 50, 50, 50, [1,0,0,0];
63
mousemove $arcbowl, 50, 50, 25, 25, [0.531784,-0.598834,-0.598834,0];
64
65
+my $orbiter = PDL::Graphics::TriD::Orbiter->new($win);
66
+isa_ok $orbiter, 'PDL::Graphics::TriD::Orbiter';
+$orbiter->set_wh(100,100);
+mousemove $orbiter, 50, 50, 50, 50, [1,0,0,0];
+mousemove $orbiter, 25, 25, 25, 25, [1,0,0,0];
+mousemove $orbiter, 50, 50, 25, 25, [0.5,-0.5,-0.5,-0.5];
+mousemove $orbiter, 25, 25, 0, 0, [0.5,-0.5,-0.5,-0.5];
done_testing;
0 commit comments