line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SecondLife::Rotation; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$SecondLife::Rotation::VERSION = '0.900'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: Second Life's rotations (quarterions with a non-standard representation) |
6
|
2
|
|
|
2
|
|
830
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
70
|
|
7
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
75
|
|
8
|
|
|
|
|
|
|
use overload |
9
|
2
|
|
|
2
|
|
2055
|
'""' => "stringify"; |
|
2
|
|
|
|
|
1102
|
|
|
2
|
|
|
|
|
13
|
|
10
|
2
|
|
|
2
|
|
1784
|
use Regexp::Common qw/ RE_num_real /; |
|
2
|
|
|
|
|
4908
|
|
|
2
|
|
|
|
|
8
|
|
11
|
2
|
|
|
2
|
|
167147
|
use Scalar::Util qw( blessed ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
268
|
|
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
1840
|
use parent qw/Math::Quaternion/; |
|
2
|
|
|
|
|
621
|
|
|
2
|
|
|
|
|
13
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
59884
|
use constant X_SLOT => 1; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
214
|
|
16
|
2
|
|
|
2
|
|
11
|
use constant Y_SLOT => 2; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
91
|
|
17
|
2
|
|
|
2
|
|
12
|
use constant Z_SLOT => 3; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
108
|
|
18
|
2
|
|
|
2
|
|
11
|
use constant S_SLOT => 0; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1405
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub x { |
21
|
11
|
|
|
11
|
0
|
12
|
my $self = shift; |
22
|
11
|
100
|
|
|
|
23
|
if ( @_ ) { |
23
|
3
|
|
|
|
|
4
|
$self->[X_SLOT] = $_[0]; |
24
|
3
|
|
|
|
|
5
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
else { |
27
|
8
|
|
|
|
|
26
|
return $self->[X_SLOT]; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub y { |
32
|
11
|
|
|
11
|
0
|
14
|
my $self = shift; |
33
|
11
|
100
|
|
|
|
20
|
if ( @_ ) { |
34
|
3
|
|
|
|
|
5
|
$self->[Y_SLOT] = $_[0]; |
35
|
3
|
|
|
|
|
3
|
return $self; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
8
|
|
|
|
|
21
|
return $self->[Y_SLOT]; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub z { |
43
|
11
|
|
|
11
|
0
|
15
|
my $self = shift; |
44
|
11
|
100
|
|
|
|
23
|
if ( @_ ) { |
45
|
3
|
|
|
|
|
4
|
$self->[Z_SLOT] = $_[0]; |
46
|
3
|
|
|
|
|
14
|
return $self; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
8
|
|
|
|
|
23
|
return $self->[Z_SLOT]; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub s { |
54
|
11
|
|
|
11
|
0
|
12
|
my $self = shift; |
55
|
11
|
100
|
|
|
|
36
|
if ( @_ ) { |
56
|
3
|
|
|
|
|
4
|
$self->[S_SLOT] = $_[0]; |
57
|
3
|
|
|
|
|
5
|
return $self; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else { |
60
|
8
|
|
|
|
|
65
|
return $self->[S_SLOT]; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new { |
65
|
8
|
|
|
8
|
1
|
956
|
my $class = shift; |
66
|
8
|
100
|
|
|
|
24
|
if ( @_ == 1 ) { |
67
|
5
|
|
|
|
|
7
|
my ($rot) = @_; |
68
|
5
|
100
|
|
|
|
26
|
if ( blessed $rot ) { |
|
|
100
|
|
|
|
|
|
69
|
2
|
50
|
|
|
|
17
|
unless ( $rot->isa("Math::Quaternion") ) { |
70
|
0
|
|
|
|
|
0
|
require Carp; |
71
|
0
|
|
|
|
|
0
|
Carp::croak("We only understand quaternion's as provided by Math::Quaternion"); |
72
|
|
|
|
|
|
|
} |
73
|
2
|
|
|
|
|
58
|
return $class->new( x=> $rot->[X_SLOT], y=>$rot->[Y_SLOT], z=>$rot->[Z_SLOT], s=>$rot->[S_SLOT] ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
elsif (ref $rot eq 'HASH') { |
76
|
1
|
|
|
|
|
4
|
return $class->new( Math::Quaternion->new($rot) ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
else { |
79
|
2
|
|
|
|
|
12
|
my $num = RE_num_real(); |
80
|
2
|
50
|
|
|
|
627
|
if ( $rot =~ /^ [(<] \s* ($num), \s* ($num), \s* ($num), \s* ($num) \s* [)>] $/xo ) { |
81
|
2
|
|
|
|
|
25
|
return $class->SUPER::new( $4, $1, $2, $3 ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
else { |
84
|
0
|
|
|
|
|
0
|
require Carp; |
85
|
0
|
|
|
|
|
0
|
Carp::croak( "Could not parse a rotation from $rot" ); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
else { |
90
|
3
|
|
|
|
|
12
|
my %args = @_; |
91
|
3
|
|
|
|
|
11
|
my $self = $class->SUPER::new(); |
92
|
3
|
|
|
|
|
26
|
foreach (keys %args) { |
93
|
12
|
|
|
|
|
25
|
$self->$_( $args{$_} ); |
94
|
|
|
|
|
|
|
} |
95
|
3
|
|
|
|
|
14
|
return bless $self, $class; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub stringify { |
100
|
7
|
|
|
7
|
1
|
258
|
my $self = shift; |
101
|
7
|
|
|
|
|
16
|
return "<".join(", ",$self->x,$self->y,$self->z,$self->s).">"; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub rotate_vector { |
105
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
106
|
0
|
|
|
|
|
|
my( $vector ) = @_; |
107
|
0
|
|
|
|
|
|
my( $x, $y, $z) = $self->SUPER::rotate_vector( $vector->x, $vector->y, $vector->z ); |
108
|
0
|
|
|
|
|
|
return SecondLife::Vector->new( x=>$x, y=>$y, z=>$z ); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
0
|
1
|
|
sub rotation { bless Math::Quaternion::rotation(@_); } |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
## Wrap methods: |
115
|
|
|
|
|
|
|
foreach (qw( unit conjugate inverse normalize multiply dot plus minus power negate scale slerp )) { |
116
|
|
|
|
|
|
|
my $super = "SUPER::conjugate"; |
117
|
2
|
|
|
2
|
|
14
|
no strict 'refs'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
233
|
|
118
|
|
|
|
|
|
|
*$_ = sub { |
119
|
0
|
|
|
0
|
|
|
my $self = shift; |
120
|
0
|
0
|
|
|
|
|
my $class = ref($self) ? ref($self) : $self; |
121
|
0
|
|
|
|
|
|
return bless $self->$super(@_), $class; |
122
|
|
|
|
|
|
|
}; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
__END__ |