CIGIPP/CollisionDetectionSegmentDefinition.pm

filter: Statementstmt 68.5% 74 / 108 Branchbran 35.2% 12 / 34 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 90.0% 18 / 20 Podpod 100% 16 / 16 totaltotal 64.8% 122 / 188 CC 21 SCAR 17.2
CC
21
Cov
59%
new
19.6
unpack
6.0
byte_swap
6.0
CRAP 5.6
« CIGIPP/ArticulatedPartControl.pm ↑ Summary CIGIPP/ViewControl.pm »
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 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 require Exporter;
15  
16 2 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 2 our %EXPORT_TAGS = ( 'all' => [ qw(
26
27 ) ] );
28  
29 2 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
30  
31 2 our @EXPORT = qw(
32
33 );
34  
35 2 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 2 ▶sub new {
Subroutine new: called CC=7 SCAR=29.8
Pod documented
113 2 my $class = shift;
114 2 ▶ $class = ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
115  
116 2 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 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
140 0 ▶ if (ref($_[0]) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'ARRAY') { } 0 0 0
elsif (ref $_[0] eq 'HASH') { } 0 0 0
141 0 $self->{'_Buffer'} = $_[0][0];
142 } elsif (ref($_[0]) eq 'HASH') {
143 0 foreach my $attr (keys %{$_[0]}) {
144 0 ▶ $self->{"_$attr"} = $_[0]->{$attr} unless ($attr =~ /^_/);
Branch: 1 branch
BranchTrueFalseTotal
unless $attr =~ /^_/ 0 0 0
145 }
146 }
147 }
148  
149 2 bless($self,$class);
150 2 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 2 ▶sub packet_type() {
Subroutine packet_type: called CC=1 SCAR=0.0
Pod documented
167 2 my ($self) = @_;
168 2 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 2 ▶sub packet_size() {
Subroutine packet_size: called CC=1 SCAR=0.0
Pod documented
185 2 my ($self) = @_;
186 2 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 2 ▶sub entity_ident() {
Subroutine entity_ident: called CC=2 SCAR=7.0
Pod documented
202 2 my ($self,$nv) = @_;
203 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
204 2 $self->{'entityIdent'} = $nv;
205 }
206 2 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 2 ▶sub segment_ident() {
Subroutine segment_ident: called CC=2 SCAR=7.0
Pod documented
223 2 my ($self,$nv) = @_;
224 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
225 2 $self->{'segmentIdent'} = $nv;
226 }
227 2 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 2 ▶sub segment_enable() {
Subroutine segment_enable: called CC=4 SCAR=15.5
Pod documented
247 2 my ($self,$nv) = @_;
248 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
249 2 ▶ if (($nv==0) or ($nv==1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nv == 0 or $nv == 1) { } 2 0 2
Condition33%1/3
$nv == 0 or $nv == 1
l!l&&r!l&&!r
200
MC/DC0%0/2
$nv == 0 or $nv == 1
$nv == 0 $nv == 1
Truth table33%1/3
A or B
A= $nv == 0B= $nv == 1
ABresult
1X1
011
000
250 2 $self->{'segmentEnable'} = $nv;
251 2 $self->{'_bitfields1'} |= $nv &0x01;
252 } else {
253 0 carp "segment_enable must be 0 (Disable), or 1 (Enable).";
254 }
255 }
256 2 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 2 ▶sub x1() {
Subroutine x1: called CC=2 SCAR=7.0
Pod documented
275 2 my ($self,$nv) = @_;
276 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
277 2 $self->{'x1'} = $nv;
278 }
279 2 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 2 ▶sub y1() {
Subroutine y1: called CC=2 SCAR=7.0
Pod documented
298 2 my ($self,$nv) = @_;
299 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
300 2 $self->{'y1'} = $nv;
301 }
302 2 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 2 ▶sub z1() {
Subroutine z1: called CC=2 SCAR=7.0
Pod documented
321 2 my ($self,$nv) = @_;
322 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
323 2 $self->{'z1'} = $nv;
324 }
325 2 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 2 ▶sub x2() {
Subroutine x2: called CC=2 SCAR=7.0
Pod documented
344 2 my ($self,$nv) = @_;
345 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
346 2 $self->{'x2'} = $nv;
347 }
348 2 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 2 ▶sub y2() {
Subroutine y2: called CC=2 SCAR=7.0
Pod documented
367 2 my ($self,$nv) = @_;
368 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
369 2 $self->{'y2'} = $nv;
370 }
371 2 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 2 ▶sub z2() {
Subroutine z2: called CC=2 SCAR=7.0
Pod documented
390 2 my ($self,$nv) = @_;
391 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
392 2 $self->{'z2'} = $nv;
393 }
394 2 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 2 ▶sub material_mask() {
Subroutine material_mask: called CC=2 SCAR=7.0
Pod documented
415 2 my ($self,$nv) = @_;
416 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
417 2 $self->{'materialMask'} = $nv;
418 }
419 2 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 2 ▶sub pack($) {
Subroutine pack: called CC=1 SCAR=0.0
Pod documented
433 2 my $self = shift ;
434
435 $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 2 $self->{'_unused37'},
450 );
451  
452 2 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 0 ▶sub unpack($) {
Subroutine unpack: not called CC=2 SCAR=17.9
Pod documented
466 0 my $self = shift @_;
467
468 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
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 0 ▶sub byte_swap($) {
Subroutine byte_swap: not called CC=2 SCAR=17.9
Pod documented
503 0 my $self = shift @_;
504
505 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
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 2 1;
519 __END__
« CIGIPP/ArticulatedPartControl.pm ↑ Summary CIGIPP/ViewControl.pm »