Commits

Michele Bini  committed 33db3ec

Removed dependency to a local library

  • Participants
  • Parent commits 77c38dc

Comments (0)

Files changed (1)

 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 use strict;
-BEGIN {
-  push @INC, "$ENV{HOME}/dev/perl/";
-}
 package PhotoCrop;
 
 # Functional interface
 # * a one-pixel offset was detected in a picture between the photocrop window and the povray-rendered image
 # * grid for correct perspective adjustment
 
-use Math::Quat qw(i j k);
-
 # apt-get install libsdl-perl libimage-info-perl
 # photocrop dscf0008.jpg --debug --delay 10 --size 800x600 --angle "0.3 rad" --nometa
 # photocrop im002382.jpg --debug --delay 10 --size 320x200 --angle 60deg --nometa --rotation -56.88deg --tilt -14.45deg --turn -9.89deg --viewangley 33deg
   setperspective();
 }
 
-sub Math::Quat::unit { Math::Quat::mkquat(1,0,0,0) }
+sub Math::Quat::new { my $p = shift; bless \@_, $p }
+sub Math::Quat::unit() { Math::Quat->new(1,0,0,0) }
+sub Math::Quat::mul {
+    my ($x, $y) = @_;
+    Math::Quat->new(
+	$$x[0] * $$y[0] - $$x[1] * $$y[1] - $$x[2] * $$y[2] - $$x[3] * $$y[3],
+	$$x[0] * $$y[1] + $$x[1] * $$y[0] + $$x[2] * $$y[3] - $$x[3] * $$y[2],
+	$$x[0] * $$y[2] - $$x[1] * $$y[3] + $$x[2] * $$y[0] + $$x[3] * $$y[1],
+	$$x[0] * $$y[3] + $$x[1] * $$y[2] - $$x[2] * $$y[1] + $$x[3] * $$y[0]
+	);
+}
+sub Math::Quat::sqr { shift->mul(shift()) }
+sub Math::Quat::real_mul {
+    my ($q, $r) = @_;
+    Math::Quat->new($q->[0] * $r, $q->[1] * $r, $q->[2] * $r, $q->[3] * $r)
+}
 
 sub rotation_by_axis {
-  my ($a, $x, $y, $z) = @_; $a *= 0.5; my $s = sin($a);
-  my $m = sqrt($x**2 + $y**2 + $z**2);
-  #map { $$_ /= $m } (\$x, \$y, \$z);
-  $x /= $m; $y /= $m; $z /= $m;
-  Math::Quat->new(cos($a), $x*$s, $y*$s, $z*$s)
+    my ($a, $x, $y, $z) = @_; $a *= 0.5; my $s = sin($a);
+    my $m = sqrt($x**2 + $y**2 + $z**2);
+    $x /= $m; $y /= $m; $z /= $m;
+    Math::Quat->new(cos($a), $x*$s, $y*$s, $z*$s)
 }
 
-sub Math::Quat::rotate_by_axis { shift() * rotation_by_axis(@_) }
+sub Math::Quat::rotate_by_axis {
+    shift()->mul(rotation_by_axis(@_))
+}
 
 sub Math::Quat::matrix3x3 {
   my ($w, $x, $y, $z) = @{ shift() };