File Coverage

blib/lib/Rinchi/CIGIPP/ViewControl.pm
Criterion Covered Total %
statement 97 139 69.7
branch 22 54 40.7
condition 7 21 33.3
subroutine 23 25 92.0
pod 21 21 100.0
total 170 260 65.3


line stmt bran cond sub pod time code
1             #
2             # Rinchi Common Image Generator Interface for Perl
3             # Class Identifier: f78add82-200e-11de-bdb0-001c25551abc
4             # Author: Brian M. Ames
5             #
6              
7             package Rinchi::CIGIPP::ViewControl;
8              
9 1     1   21 use 5.006;
  1         4  
  1         42  
10 1     1   7 use strict;
  1         2  
  1         34  
11 1     1   8 use warnings;
  1         2  
  1         31  
12 1     1   5 use Carp;
  1         2  
  1         5847  
13              
14             require Exporter;
15              
16             our @ISA = qw(Exporter);
17              
18             # Items to export into callers namespace by default. Note: do not export
19             # names by default without a very good reason. Use EXPORT_OK instead.
20             # Do not simply export all your public functions/methods/constants.
21              
22             # This allows declaration use Rinchi::CIGI::AtmosphereControl ':all';
23             # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
24             # will save memory.
25             our %EXPORT_TAGS = ( 'all' => [ qw(
26            
27             ) ] );
28              
29             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
30              
31             our @EXPORT = qw(
32            
33             );
34              
35             our $VERSION = '0.01';
36              
37             # Preloaded methods go here.
38              
39             =head1 NAME
40              
41             Rinchi::CIGIPP::ViewControl - Perl extension for the Common Image Generator
42             Interface - View Control data packet.
43             data packet.
44             =head1 SYNOPSIS
45              
46             use Rinchi::CIGIPP::ViewControl;
47             my $view_ctl = Rinchi::CIGIPP::ViewControl->new();
48              
49             $packet_type = $view_ctl->packet_type();
50             $packet_size = $view_ctl->packet_size();
51             $view_ident = $view_ctl->view_ident(11410);
52             $group_ident = $view_ctl->group_ident(132);
53             $yaw_enable = $view_ctl->yaw_enable(Rinchi::CIGIPP->Enable);
54             $pitch_enable = $view_ctl->pitch_enable(Rinchi::CIGIPP->Enable);
55             $roll_enable = $view_ctl->roll_enable(Rinchi::CIGIPP->Enable);
56             $z_offset_enable = $view_ctl->z_offset_enable(Rinchi::CIGIPP->Disable);
57             $y_offset_enable = $view_ctl->y_offset_enable(Rinchi::CIGIPP->Enable);
58             $x_offset_enable = $view_ctl->x_offset_enable(Rinchi::CIGIPP->Disable);
59             $entity_ident = $view_ctl->entity_ident(22744);
60             $x_offset = $view_ctl->x_offset(14.225);
61             $y_offset = $view_ctl->y_offset(68.843);
62             $z_offset = $view_ctl->z_offset(19.148);
63             $roll = $view_ctl->roll(53.063);
64             $pitch = $view_ctl->pitch(75.147);
65             $yaw = $view_ctl->yaw(45.894);
66              
67             =head1 DESCRIPTION
68              
69             The View Control packet is used to attach a view or view group to an entity and
70             to define the position and rotation of the view relative to the entity's
71             reference point. Views can be positioned to correspond to the pilot eye,
72             weapon/sensor viewpoints, and stealth view cameras.
73              
74             Multiple views may be combined to form one or more view groups. This allows
75             more than one view to be moved in unison with a single View Control packet. A
76             view group is identified by the Group ID attribute. Operations performed upon a
77             view group affect all views in that group. If Group ID is set to zero (0), the
78             packet is applied to an individual view, identified by the View ID attribute.
79              
80             The order of operation for views and view groups is the same as that for
81             entities. A view is first translated along the entity's X, Y, and Z axes. After
82             it is translated, the view is rotated about the eyepoint. The order of rotation
83             is first about Z axis (yaw), then the Y axis (pitch), and finally the X axis (roll).
84              
85             =head2 EXPORT
86              
87             None by default.
88              
89             #==============================================================================
90              
91             =item new $view_ctl = Rinchi::CIGIPP::ViewControl->new()
92              
93             Constructor for Rinchi::ViewControl.
94              
95             =cut
96              
97             sub new {
98 1     1 1 254 my $class = shift;
99 1   33     16 $class = ref($class) || $class;
100              
101 1         28 my $self = {
102             '_Buffer' => '',
103             '_ClassIdent' => 'f78add82-200e-11de-bdb0-001c25551abc',
104             '_Pack' => 'CCSCCSffffff',
105             '_Swap1' => 'CCvCCvVVVVVV',
106             '_Swap2' => 'CCnCCnNNNNNN',
107             'packetType' => 16,
108             'packetSize' => 32,
109             'viewIdent' => 0,
110             'groupIdent' => 0,
111             '_bitfields1' => 0, # Includes bitfields unused28, yawEnable, pitchEnable, rollEnable, zOffsetEnable, yOffsetEnable, and xOffsetEnable.
112             'yawEnable' => 0,
113             'pitchEnable' => 0,
114             'rollEnable' => 0,
115             'zOffsetEnable' => 0,
116             'yOffsetEnable' => 0,
117             'xOffsetEnable' => 0,
118             'entityIdent' => 0,
119             'xOffset' => 0,
120             'yOffset' => 0,
121             'zOffset' => 0,
122             'roll' => 0,
123             'pitch' => 0,
124             'yaw' => 0,
125             };
126              
127 1 50       10 if (@_) {
128 0 0       0 if (ref($_[0]) eq 'ARRAY') {
    0          
129 0         0 $self->{'_Buffer'} = $_[0][0];
130             } elsif (ref($_[0]) eq 'HASH') {
131 0         0 foreach my $attr (keys %{$_[0]}) {
  0         0  
132 0 0       0 $self->{"_$attr"} = $_[0]->{$attr} unless ($attr =~ /^_/);
133             }
134             }
135             }
136              
137 1         3 bless($self,$class);
138 1         3 return $self;
139             }
140              
141             #==============================================================================
142              
143             =item sub packet_type()
144              
145             $value = $view_ctl->packet_type();
146              
147             Data Packet Identifier.
148              
149             This attribute identifies this data packet as the View Control packet. The
150             value of this attribute must be 16.
151              
152             =cut
153              
154             sub packet_type() {
155 1     1 1 6 my ($self) = @_;
156 1         8 return $self->{'packetType'};
157             }
158              
159             #==============================================================================
160              
161             =item sub packet_size()
162              
163             $value = $view_ctl->packet_size();
164              
165             Data Packet Size.
166              
167             This attribute indicates the number of bytes in this data packet. The value of
168             this attribute must be 32.
169              
170             =cut
171              
172             sub packet_size() {
173 1     1 1 5 my ($self) = @_;
174 1         3 return $self->{'packetSize'};
175             }
176              
177             #==============================================================================
178              
179             =item sub view_ident([$newValue])
180              
181             $value = $view_ctl->view_ident($newValue);
182              
183             View ID.
184              
185             This attribute specifies the view to which the contents of this packet should
186             be applied. This value is ignored if the Group ID attribute contains a non-zero value.
187              
188             =cut
189              
190             sub view_ident() {
191 1     1 1 4 my ($self,$nv) = @_;
192 1 50       4 if (defined($nv)) {
193 1         2 $self->{'viewIdent'} = $nv;
194             }
195 1         3 return $self->{'viewIdent'};
196             }
197              
198             #==============================================================================
199              
200             =item sub group_ident([$newValue])
201              
202             $value = $view_ctl->group_ident($newValue);
203              
204             Group ID.
205              
206             This attribute specifies the view group to which the contents of this packet
207             are applied. If this value is zero (0), the packet is applied to the individual
208             view specified by the View ID attribute. If this value is non-zero, the packet
209             is applied to the specified view group and the View ID attribute is ignored.
210              
211             =cut
212              
213             sub group_ident() {
214 1     1 1 5 my ($self,$nv) = @_;
215 1 50       5 if (defined($nv)) {
216 1         2 $self->{'groupIdent'} = $nv;
217             }
218 1         3 return $self->{'groupIdent'};
219             }
220              
221             #==============================================================================
222              
223             =item sub yaw_enable([$newValue])
224              
225             $value = $view_ctl->yaw_enable($newValue);
226              
227             Yaw Enable.
228              
229             This attribute determines whether the Yaw attribute should be applied to the
230             specified view or view group. If this flag is set to Disable (0), the Yaw
231             attribute is ignored.
232              
233             Disable 0
234             Enable 1
235              
236             =cut
237              
238             sub yaw_enable() {
239 1     1 1 3 my ($self,$nv) = @_;
240 1 50       5 if (defined($nv)) {
241 1 50 33     7 if (($nv==0) or ($nv==1)) {
242 1         2 $self->{'yawEnable'} = $nv;
243 1         4 $self->{'_bitfields1'} |= ($nv << 5) &0x20;
244             } else {
245 0         0 carp "yaw_enable must be 0 (Disable), or 1 (Enable).";
246             }
247             }
248 1         4 return (($self->{'_bitfields1'} & 0x20) >> 5);
249             }
250              
251             #==============================================================================
252              
253             =item sub pitch_enable([$newValue])
254              
255             $value = $view_ctl->pitch_enable($newValue);
256              
257             Pitch Enable.
258              
259             This attribute determines whether the Pitch attribute should be applied to the
260             specified view or view group. If this flag is set to Disable (0), the Pitch
261             attribute is ignored.
262              
263             Disable 0
264             Enable 1
265              
266             =cut
267              
268             sub pitch_enable() {
269 1     1 1 2 my ($self,$nv) = @_;
270 1 50       3 if (defined($nv)) {
271 1 50 33     14 if (($nv==0) or ($nv==1)) {
272 1         2 $self->{'pitchEnable'} = $nv;
273 1         3 $self->{'_bitfields1'} |= ($nv << 4) &0x10;
274             } else {
275 0         0 carp "pitch_enable must be 0 (Disable), or 1 (Enable).";
276             }
277             }
278 1         4 return (($self->{'_bitfields1'} & 0x10) >> 4);
279             }
280              
281             #==============================================================================
282              
283             =item sub roll_enable([$newValue])
284              
285             $value = $view_ctl->roll_enable($newValue);
286              
287             Roll Enable.
288              
289             This attribute determines whether the Roll attribute should be applied to the
290             specified view or view group. If this flag is set to Disable (0), the Roll
291             attribute is ignored.
292              
293             Disable 0
294             Enable 1
295              
296             =cut
297              
298             sub roll_enable() {
299 1     1 1 3 my ($self,$nv) = @_;
300 1 50       4 if (defined($nv)) {
301 1 50 33     14 if (($nv==0) or ($nv==1)) {
302 1         3 $self->{'rollEnable'} = $nv;
303 1         3 $self->{'_bitfields1'} |= ($nv << 3) &0x08;
304             } else {
305 0         0 carp "roll_enable must be 0 (Disable), or 1 (Enable).";
306             }
307             }
308 1         4 return (($self->{'_bitfields1'} & 0x08) >> 3);
309             }
310              
311             #==============================================================================
312              
313             =item sub z_offset_enable([$newValue])
314              
315             $value = $view_ctl->z_offset_enable($newValue);
316              
317             Z Offset Enable.
318              
319             This attribute determines whether the Z Offset attribute should be applied to
320             the specified view or view group. If this flag is set to Disable (0), the Z
321             Offset attribute is ignored.
322              
323             Disable 0
324             Enable 1
325              
326             =cut
327              
328             sub z_offset_enable() {
329 1     1 1 3 my ($self,$nv) = @_;
330 1 50       4 if (defined($nv)) {
331 1 50 33     5 if (($nv==0) or ($nv==1)) {
332 1         3 $self->{'zOffsetEnable'} = $nv;
333 1         3 $self->{'_bitfields1'} |= ($nv << 2) &0x04;
334             } else {
335 0         0 carp "z_offset_enable must be 0 (Disable), or 1 (Enable).";
336             }
337             }
338 1         4 return (($self->{'_bitfields1'} & 0x04) >> 2);
339             }
340              
341             #==============================================================================
342              
343             =item sub y_offset_enable([$newValue])
344              
345             $value = $view_ctl->y_offset_enable($newValue);
346              
347             Y Offset Enable.
348              
349             This attribute determines whether the Y Offset attribute should be applied to
350             the specified view or view group. If this flag is set to Disable (0), the Y
351             Offset attribute is ignored.
352              
353             Disable 0
354             Enable 1
355              
356             =cut
357              
358             sub y_offset_enable() {
359 1     1 1 2 my ($self,$nv) = @_;
360 1 50       4 if (defined($nv)) {
361 1 50 33     19 if (($nv==0) or ($nv==1)) {
362 1         3 $self->{'yOffsetEnable'} = $nv;
363 1         3 $self->{'_bitfields1'} |= ($nv << 1) &0x02;
364             } else {
365 0         0 carp "y_offset_enable must be 0 (Disable), or 1 (Enable).";
366             }
367             }
368 1         3 return (($self->{'_bitfields1'} & 0x02) >> 1);
369             }
370              
371             #==============================================================================
372              
373             =item sub x_offset_enable([$newValue])
374              
375             $value = $view_ctl->x_offset_enable($newValue);
376              
377             X Offset Enable.
378              
379             This attribute determines whether the X Offset attribute should be applied to
380             the specified view or view group. If this flag is set to Disable (0), the X
381             Offset attribute is ignored.
382              
383             Disable 0
384             Enable 1
385              
386             =cut
387              
388             sub x_offset_enable() {
389 1     1 1 2 my ($self,$nv) = @_;
390 1 50       3 if (defined($nv)) {
391 1 50 33     7 if (($nv==0) or ($nv==1)) {
392 1         2 $self->{'xOffsetEnable'} = $nv;
393 1         2 $self->{'_bitfields1'} |= $nv &0x01;
394             } else {
395 0         0 carp "x_offset_enable must be 0 (Disable), or 1 (Enable).";
396             }
397             }
398 1         3 return ($self->{'_bitfields1'} & 0x01);
399             }
400              
401             #==============================================================================
402              
403             =item sub entity_ident([$newValue])
404              
405             $value = $view_ctl->entity_ident($newValue);
406              
407             Entity ID.
408              
409             This attribute specifies the entity to which the view or view group should be attached.
410              
411             =cut
412              
413             sub entity_ident() {
414 1     1 1 6 my ($self,$nv) = @_;
415 1 50       4 if (defined($nv)) {
416 1         2 $self->{'entityIdent'} = $nv;
417             }
418 1         2 return $self->{'entityIdent'};
419             }
420              
421             #==============================================================================
422              
423             =item sub x_offset([$newValue])
424              
425             $value = $view_ctl->x_offset($newValue);
426              
427             X Offset.
428              
429             This attribute specifies the position of the view eyepoint along the X axis of
430             the entity specified by the Entity ID attribute.
431              
432             =cut
433              
434             sub x_offset() {
435 1     1 1 6 my ($self,$nv) = @_;
436 1 50       4 if (defined($nv)) {
437 1         3 $self->{'xOffset'} = $nv;
438             }
439 1         4 return $self->{'xOffset'};
440             }
441              
442             #==============================================================================
443              
444             =item sub y_offset([$newValue])
445              
446             $value = $view_ctl->y_offset($newValue);
447              
448             Y Offset.
449              
450             This attribute specifies the position of the view eyepoint along the Y axis of
451             the entity specified by the Entity ID attribute.
452              
453             =cut
454              
455             sub y_offset() {
456 1     1 1 6 my ($self,$nv) = @_;
457 1 50       5 if (defined($nv)) {
458 1         2 $self->{'yOffset'} = $nv;
459             }
460 1         10 return $self->{'yOffset'};
461             }
462              
463             #==============================================================================
464              
465             =item sub z_offset([$newValue])
466              
467             $value = $view_ctl->z_offset($newValue);
468              
469             Z Offset.
470              
471             This attribute specifies the position of the view eyepoint along the Z axis of
472             the entity specified by the Entity ID attribute.
473              
474             =cut
475              
476             sub z_offset() {
477 1     1 1 6 my ($self,$nv) = @_;
478 1 50       4 if (defined($nv)) {
479 1         2 $self->{'zOffset'} = $nv;
480             }
481 1         4 return $self->{'zOffset'};
482             }
483              
484             #==============================================================================
485              
486             =item sub roll([$newValue])
487              
488             $value = $view_ctl->roll($newValue);
489              
490             Roll.
491              
492             This attribute specifies the angle of rotation of the view or view group about
493             its X axis after yaw and pitch have been applied.
494              
495             =cut
496              
497             sub roll() {
498 1     1 1 6 my ($self,$nv) = @_;
499 1 50       10 if (defined($nv)) {
500 1         3 $self->{'roll'} = $nv;
501             }
502 1         3 return $self->{'roll'};
503             }
504              
505             #==============================================================================
506              
507             =item sub pitch([$newValue])
508              
509             $value = $view_ctl->pitch($newValue);
510              
511             Pitch.
512              
513             This attribute specifies the angle of rotation of the view or view group about
514             its Y axis after yaw has been applied.
515              
516             =cut
517              
518             sub pitch() {
519 1     1 1 11 my ($self,$nv) = @_;
520 1 50       4 if (defined($nv)) {
521 1         4 $self->{'pitch'} = $nv;
522             }
523 1         3 return $self->{'pitch'};
524             }
525              
526             #==============================================================================
527              
528             =item sub yaw([$newValue])
529              
530             $value = $view_ctl->yaw($newValue);
531              
532             Yaw.
533              
534             This attribute specifies the angle of rotation of the view or view group about
535             its Z axis.
536              
537             =cut
538              
539             sub yaw() {
540 1     1 1 6 my ($self,$nv) = @_;
541 1 50       4 if (defined($nv)) {
542 1         3 $self->{'yaw'} = $nv;
543             }
544 1         3 return $self->{'yaw'};
545             }
546              
547             #==========================================================================
548              
549             =item sub pack()
550              
551             $value = $view_ctl->pack();
552              
553             Returns the packed data packet.
554              
555             =cut
556              
557             sub pack($) {
558 1     1 1 5 my $self = shift ;
559            
560 1         9 $self->{'_Buffer'} = CORE::pack($self->{'_Pack'},
561             $self->{'packetType'},
562             $self->{'packetSize'},
563             $self->{'viewIdent'},
564             $self->{'groupIdent'},
565             $self->{'_bitfields1'}, # Includes bitfields unused28, yawEnable, pitchEnable, rollEnable, zOffsetEnable, yOffsetEnable, and xOffsetEnable.
566             $self->{'entityIdent'},
567             $self->{'xOffset'},
568             $self->{'yOffset'},
569             $self->{'zOffset'},
570             $self->{'roll'},
571             $self->{'pitch'},
572             $self->{'yaw'},
573             );
574              
575 1         3 return $self->{'_Buffer'};
576             }
577              
578             #==========================================================================
579              
580             =item sub unpack()
581              
582             $value = $view_ctl->unpack();
583              
584             Unpacks the packed data packet.
585              
586             =cut
587              
588             sub unpack($) {
589 0     0 1   my $self = shift @_;
590            
591 0 0         if (@_) {
592 0           $self->{'_Buffer'} = shift @_;
593             }
594 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l) = CORE::unpack($self->{'_Pack'},$self->{'_Buffer'});
595 0           $self->{'packetType'} = $a;
596 0           $self->{'packetSize'} = $b;
597 0           $self->{'viewIdent'} = $c;
598 0           $self->{'groupIdent'} = $d;
599 0           $self->{'_bitfields1'} = $e; # Includes bitfields unused28, yawEnable, pitchEnable, rollEnable, zOffsetEnable, yOffsetEnable, and xOffsetEnable.
600 0           $self->{'entityIdent'} = $f;
601 0           $self->{'xOffset'} = $g;
602 0           $self->{'yOffset'} = $h;
603 0           $self->{'zOffset'} = $i;
604 0           $self->{'roll'} = $j;
605 0           $self->{'pitch'} = $k;
606 0           $self->{'yaw'} = $l;
607              
608 0           $self->{'yawEnable'} = $self->yaw_enable();
609 0           $self->{'pitchEnable'} = $self->pitch_enable();
610 0           $self->{'rollEnable'} = $self->roll_enable();
611 0           $self->{'zOffsetEnable'} = $self->z_offset_enable();
612 0           $self->{'yOffsetEnable'} = $self->y_offset_enable();
613 0           $self->{'xOffsetEnable'} = $self->x_offset_enable();
614              
615 0           return $self->{'_Buffer'};
616             }
617              
618             #==========================================================================
619              
620             =item sub byte_swap()
621              
622             $obj_name->byte_swap();
623              
624             Byte swaps the packed data packet.
625              
626             =cut
627              
628             sub byte_swap($) {
629 0     0 1   my $self = shift @_;
630            
631 0 0         if (@_) {
632 0           $self->{'_Buffer'} = shift @_;
633             } else {
634 0           $self->pack();
635             }
636 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l) = CORE::unpack($self->{'_Swap1'},$self->{'_Buffer'});
637              
638 0           $self->{'_Buffer'} = CORE::pack($self->{'_Swap2'},$a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l);
639 0           $self->unpack();
640              
641 0           return $self->{'_Buffer'};
642             }
643              
644             1;
645             __END__