File Coverage

blib/lib/Rinchi/CIGIPP/CollisionDetectionSegmentDefinition.pm
Criterion Covered Total %
statement 67 101 66.3
branch 12 34 35.2
condition 2 6 33.3
subroutine 18 20 90.0
pod 16 16 100.0
total 115 177 64.9


line stmt bran cond sub pod time code
1             #
2             # Rinchi Common Image Generator Interface for Perl
3             # Class Identifier: f78aed68-200e-11de-bdb6-001c25551abc
4             # Author: Brian M. Ames
5             #
6              
7             package Rinchi::CIGIPP::CollisionDetectionSegmentDefinition;
8              
9 1     1   28 use 5.006;
  1         3  
  1         51  
10 1     1   7 use strict;
  1         2  
  1         36  
11 1     1   10 use warnings;
  1         2  
  1         42  
12 1     1   7 use Carp;
  1         2  
  1         2116  
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::CollisionDetectionSegmentDefinition - Perl extension for the
42             Common Image Generator Interface - Collision Detection Segment Definition data packet.
43             data packet.
44             =head1 SYNOPSIS
45              
46             use Rinchi::CIGIPP::CollisionDetectionSegmentDefinition;
47             my $cds_def = Rinchi::CIGIPP::CollisionDetectionSegmentDefinition->new();
48              
49             $packet_type = $cds_def->packet_type();
50             $packet_size = $cds_def->packet_size();
51             $entity_ident = $cds_def->entity_ident(58547);
52             $segment_ident = $cds_def->segment_ident(64);
53             $segment_enable = $cds_def->segment_enable(Rinchi::CIGIPP->Disable);
54             $x1 = $cds_def->x1(27.907);
55             $y1 = $cds_def->y1(79.193);
56             $z1 = $cds_def->z1(1.157);
57             $x2 = $cds_def->x2(42.937);
58             $y2 = $cds_def->y2(47.855);
59             $z2 = $cds_def->z2(49.825);
60             $material_mask = $cds_def->material_mask(38021);
61              
62             =head1 DESCRIPTION
63              
64             The Collision Detection Segment Definition packet enables the Host to define
65             one or more collision detection segments for an entity. A collision detection
66             segment is a line segment along which collision testing is performed by the IG.
67             When a collision detection segment intersects a polygon, the IG registers a
68             collision by sending a Collision Detection Segment Notification (Section
69             4.2.13) packet to the Host identifying the segment and the object with which it
70             collided.
71             Note that collision detection testing is performed every frame by the IG.
72              
73             The segment is defined by specifying the locations of its endpoints with
74             respect to the associated entity's body coordinate system.
75              
76             Collision detection volumes (segments?) are tested segment-to-polygon. An
77             entity will not perform collision detection segment testing against its own
78             geometry.
79             If the Collision Detection Enable attribute of an Entity Control packet is set
80             to Disabled (0), the referenced entity's segments will not be used for
81             collision detection segment testing. If the state of an entity is set to
82             Inactive/Standby (0) via the Entity State attribute of an Entity Control
83             packet, neither that entity's segments nor its geometry will be included in
84             collision detection segment testing.
85              
86             If an entity is destroyed, any collision detection segments defined for that
87             entity will also be destroyed.
88              
89             Although non-entity collision detection segments may be defined by the IG
90             configuration, the Host can only create collision detection segments by
91             referencing an entity. If a segment must be defined along a non-entity object,
92             the Host must first create an entity with no geometry (entity type zero) to
93             represent that object.
94              
95             Since collision tests are conducted at discrete moments in time, it is possible
96             that a segment could pass completely through a polygon between successive
97             tests, causing a missed collision. It may therefore be necessary for the IG to
98             use segment sweeping or some other mechanism to avoid this situation.
99              
100             =head2 EXPORT
101              
102             None by default.
103              
104             #==============================================================================
105              
106             =item new $cds_def = Rinchi::CIGIPP::CollisionDetectionSegmentDefinition->new()
107              
108             Constructor for Rinchi::CollisionDetectionSegmentDefinition.
109              
110             =cut
111              
112             sub new {
113 1     1 1 240 my $class = shift;
114 1   33     9 $class = ref($class) || $class;
115              
116 1         18 my $self = {
117             '_Buffer' => '',
118             '_ClassIdent' => 'f78aed68-200e-11de-bdb6-001c25551abc',
119             '_Pack' => 'CCSCCSffffffII',
120             '_Swap1' => 'CCvCCvVVVVVVVV',
121             '_Swap2' => 'CCnCCnNNNNNNNN',
122             'packetType' => 22,
123             'packetSize' => 40,
124             'entityIdent' => 0,
125             'segmentIdent' => 0,
126             '_bitfields1' => 0, # Includes bitfields unused35, and segmentEnable.
127             'segmentEnable' => 0,
128             '_unused36' => 0,
129             'x1' => 0,
130             'y1' => 0,
131             'z1' => 0,
132             'x2' => 0,
133             'y2' => 0,
134             'z2' => 0,
135             'materialMask' => 0,
136             '_unused37' => 0,
137             };
138              
139 1 50       5 if (@_) {
140 0 0       0 if (ref($_[0]) eq 'ARRAY') {
    0          
141 0         0 $self->{'_Buffer'} = $_[0][0];
142             } elsif (ref($_[0]) eq 'HASH') {
143 0         0 foreach my $attr (keys %{$_[0]}) {
  0         0  
144 0 0       0 $self->{"_$attr"} = $_[0]->{$attr} unless ($attr =~ /^_/);
145             }
146             }
147             }
148              
149 1         5 bless($self,$class);
150 1         5 return $self;
151             }
152              
153             #==============================================================================
154              
155             =item sub packet_type()
156              
157             $value = $cds_def->packet_type();
158              
159             Data Packet Identifier.
160              
161             This attribute identifies this data packet as the Collision Detection Segment
162             Definition packet. The value of this attribute must be 22.
163              
164             =cut
165              
166             sub packet_type() {
167 1     1 1 7 my ($self) = @_;
168 1         8 return $self->{'packetType'};
169             }
170              
171             #==============================================================================
172              
173             =item sub packet_size()
174              
175             $value = $cds_def->packet_size();
176              
177             Data Packet Size.
178              
179             This attribute indicates the number of bytes in this data packet. The value of
180             this attribute must be 40.
181              
182             =cut
183              
184             sub packet_size() {
185 1     1 1 5 my ($self) = @_;
186 1         3 return $self->{'packetSize'};
187             }
188              
189             #==============================================================================
190              
191             =item sub entity_ident([$newValue])
192              
193             $value = $cds_def->entity_ident($newValue);
194              
195             Entity ID.
196              
197             This attribute specifies the entity for which the segment is defined.
198              
199             =cut
200              
201             sub entity_ident() {
202 1     1 1 16 my ($self,$nv) = @_;
203 1 50       5 if (defined($nv)) {
204 1         2 $self->{'entityIdent'} = $nv;
205             }
206 1         4 return $self->{'entityIdent'};
207             }
208              
209             #==============================================================================
210              
211             =item sub segment_ident([$newValue])
212              
213             $value = $cds_def->segment_ident($newValue);
214              
215             Segment ID.
216              
217             This attribute specifies the identifier of the segment. If a segment is already
218             defined with the same Segment ID, that segment will be overwritten.
219              
220             =cut
221              
222             sub segment_ident() {
223 1     1 1 6 my ($self,$nv) = @_;
224 1 50       5 if (defined($nv)) {
225 1         3 $self->{'segmentIdent'} = $nv;
226             }
227 1         3 return $self->{'segmentIdent'};
228             }
229              
230             #==============================================================================
231              
232             =item sub segment_enable([$newValue])
233              
234             $value = $cds_def->segment_enable($newValue);
235              
236             Segment Enable.
237              
238             This attribute specifies whether the segment is enabled or disabled. If it is
239             set to Disable (0), the specified segment is ignored during collision testing.
240              
241             Disable 0
242             Enable 1
243              
244             =cut
245              
246             sub segment_enable() {
247 1     1 1 2 my ($self,$nv) = @_;
248 1 50       4 if (defined($nv)) {
249 1 50 33     6 if (($nv==0) or ($nv==1)) {
250 1         2 $self->{'segmentEnable'} = $nv;
251 1         3 $self->{'_bitfields1'} |= $nv &0x01;
252             } else {
253 0         0 carp "segment_enable must be 0 (Disable), or 1 (Enable).";
254             }
255             }
256 1         3 return ($self->{'_bitfields1'} & 0x01);
257             }
258              
259             #==============================================================================
260              
261             =item sub x1([$newValue])
262              
263             $value = $cds_def->x1($newValue);
264              
265             X1.
266              
267             This attribute specifies the X offset of one endpoint of the collision segment.
268             This offset is measured with respect to the coordinate system of the entity
269             specified by the Entity ID attribute. The X offset of the other endpoint is
270             defined by the X2 attribute.
271              
272             =cut
273              
274             sub x1() {
275 1     1 1 6 my ($self,$nv) = @_;
276 1 50       13 if (defined($nv)) {
277 1         11 $self->{'x1'} = $nv;
278             }
279 1         3 return $self->{'x1'};
280             }
281              
282             #==============================================================================
283              
284             =item sub y1([$newValue])
285              
286             $value = $cds_def->y1($newValue);
287              
288             Y1.
289              
290             This attribute specifies the Y offset of one endpoint of the collision segment.
291             This offset is measured with respect to the coordinate system of the entity
292             specified by the Entity ID attribute. The Y offset of the other endpoint is
293             defined by the Y2 attribute.
294              
295             =cut
296              
297             sub y1() {
298 1     1 1 5 my ($self,$nv) = @_;
299 1 50       3 if (defined($nv)) {
300 1         3 $self->{'y1'} = $nv;
301             }
302 1         4 return $self->{'y1'};
303             }
304              
305             #==============================================================================
306              
307             =item sub z1([$newValue])
308              
309             $value = $cds_def->z1($newValue);
310              
311             Z1.
312              
313             This attribute specifies the Z offset of one endpoint of the collision segment.
314             This offset is measured with respect to the coordinate system of the entity
315             specified by the Entity ID attribute. The Z offset of the other endpoint is
316             defined by the Z2 attribute.
317              
318             =cut
319              
320             sub z1() {
321 1     1 1 111 my ($self,$nv) = @_;
322 1 50       5 if (defined($nv)) {
323 1         3 $self->{'z1'} = $nv;
324             }
325 1         4 return $self->{'z1'};
326             }
327              
328             #==============================================================================
329              
330             =item sub x2([$newValue])
331              
332             $value = $cds_def->x2($newValue);
333              
334             X2.
335              
336             This attribute specifies the X offset of one endpoint of the collision segment.
337             This offset is measured with respect to the coordinate system of the entity
338             specified by the Entity ID attribute. The X offset of the other endpoint is
339             defined by the X1 attribute.
340              
341             =cut
342              
343             sub x2() {
344 1     1 1 6 my ($self,$nv) = @_;
345 1 50       4 if (defined($nv)) {
346 1         3 $self->{'x2'} = $nv;
347             }
348 1         4 return $self->{'x2'};
349             }
350              
351             #==============================================================================
352              
353             =item sub y2([$newValue])
354              
355             $value = $cds_def->y2($newValue);
356              
357             Y2.
358              
359             This attribute specifies the Y offset of one endpoint of the collision segment.
360             This offset is measured with respect to the coordinate system of the entity
361             specified by the Entity ID attribute. The Y offset of the other endpoint is
362             defined by the Y1 attribute.
363              
364             =cut
365              
366             sub y2() {
367 1     1 1 5 my ($self,$nv) = @_;
368 1 50       12 if (defined($nv)) {
369 1         3 $self->{'y2'} = $nv;
370             }
371 1         3 return $self->{'y2'};
372             }
373              
374             #==============================================================================
375              
376             =item sub z2([$newValue])
377              
378             $value = $cds_def->z2($newValue);
379              
380             Z2.
381              
382             This attribute specifies theZ offset of one endpoint of the collision segment.
383             This offset is measured with respect to the coordinate system of the entity
384             specified by the Entity ID attribute. The Z offset of the other endpoint is
385             defined by the Z1 attribute.
386              
387             =cut
388              
389             sub z2() {
390 1     1 1 5 my ($self,$nv) = @_;
391 1 50       6 if (defined($nv)) {
392 1         2 $self->{'z2'} = $nv;
393             }
394 1         4 return $self->{'z2'};
395             }
396              
397             #==============================================================================
398              
399             =item sub material_mask([$newValue])
400              
401             $value = $cds_def->material_mask($newValue);
402              
403             Material Mask.
404              
405             This attribute specifies the environmental and cultural features to be included
406             in or excluded from consideration for collision testing. Each bit represents a
407             range of material code values. Setting that bit to one (1) will cause the IG to
408             register hits with materials within the corresponding range.
409              
410             Refer to the appropriate IG documentation for material code assignments.
411              
412             =cut
413              
414             sub material_mask() {
415 1     1 1 5 my ($self,$nv) = @_;
416 1 50       4 if (defined($nv)) {
417 1         2 $self->{'materialMask'} = $nv;
418             }
419 1         4 return $self->{'materialMask'};
420             }
421              
422             #==========================================================================
423              
424             =item sub pack()
425              
426             $value = $cds_def->pack();
427              
428             Returns the packed data packet.
429              
430             =cut
431              
432             sub pack($) {
433 1     1 1 5 my $self = shift ;
434            
435 1         25 $self->{'_Buffer'} = CORE::pack($self->{'_Pack'},
436             $self->{'packetType'},
437             $self->{'packetSize'},
438             $self->{'entityIdent'},
439             $self->{'segmentIdent'},
440             $self->{'_bitfields1'}, # Includes bitfields unused35, and segmentEnable.
441             $self->{'_unused36'},
442             $self->{'x1'},
443             $self->{'y1'},
444             $self->{'z1'},
445             $self->{'x2'},
446             $self->{'y2'},
447             $self->{'z2'},
448             $self->{'materialMask'},
449             $self->{'_unused37'},
450             );
451              
452 1         4 return $self->{'_Buffer'};
453             }
454              
455             #==========================================================================
456              
457             =item sub unpack()
458              
459             $value = $cds_def->unpack();
460              
461             Unpacks the packed data packet.
462              
463             =cut
464              
465             sub unpack($) {
466 0     0 1   my $self = shift @_;
467            
468 0 0         if (@_) {
469 0           $self->{'_Buffer'} = shift @_;
470             }
471 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n) = CORE::unpack($self->{'_Pack'},$self->{'_Buffer'});
472 0           $self->{'packetType'} = $a;
473 0           $self->{'packetSize'} = $b;
474 0           $self->{'entityIdent'} = $c;
475 0           $self->{'segmentIdent'} = $d;
476 0           $self->{'_bitfields1'} = $e; # Includes bitfields unused35, and segmentEnable.
477 0           $self->{'_unused36'} = $f;
478 0           $self->{'x1'} = $g;
479 0           $self->{'y1'} = $h;
480 0           $self->{'z1'} = $i;
481 0           $self->{'x2'} = $j;
482 0           $self->{'y2'} = $k;
483 0           $self->{'z2'} = $l;
484 0           $self->{'materialMask'} = $m;
485 0           $self->{'_unused37'} = $n;
486              
487 0           $self->{'segmentEnable'} = $self->segment_enable();
488              
489 0           return $self->{'_Buffer'};
490             }
491              
492             #==========================================================================
493              
494             =item sub byte_swap()
495              
496             $obj_name->byte_swap();
497              
498             Byte swaps the packed data packet.
499              
500             =cut
501              
502             sub byte_swap($) {
503 0     0 1   my $self = shift @_;
504            
505 0 0         if (@_) {
506 0           $self->{'_Buffer'} = shift @_;
507             } else {
508 0           $self->pack();
509             }
510 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n) = CORE::unpack($self->{'_Swap1'},$self->{'_Buffer'});
511              
512 0           $self->{'_Buffer'} = CORE::pack($self->{'_Swap2'},$a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n);
513 0           $self->unpack();
514              
515 0           return $self->{'_Buffer'};
516             }
517              
518             1;
519             __END__