CIGIPP/CollisionDetectionSegmentNotification.pm

filter: Statementstmt 67.4% 58 / 86 Branchbran 30.7% 8 / 26 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 87.5% 14 / 16 Podpod 100% 12 / 12 totaltotal 62.6% 94 / 150 CC 17 SCAR 18.7
CC
17
Cov
58%
new
19.6
unpack
6.0
byte_swap
6.0
CRAP 6.5
« CIGIPP/IGControl.pm ↑ Summary CIGIPP/TrajectoryDefinition.pm »
1 #
2 # Rinchi Common Image Generator Interface for Perl
3 # Class Identifier: f78b3b42-200e-11de-bdd3-001c25551abc
4 # Author: Brian M. Ames
5 #
6  
7 package Rinchi::CIGIPP::CollisionDetectionSegmentNotification;
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::CollisionDetectionSegmentNotification - Perl extension for the
42 Common Image Generator Interface - Collision Detection Segment Notification
43 data packet.
44 data packet.
45 =head1 SYNOPSIS
46  
47 use Rinchi::CIGIPP::CollisionDetectionSegmentNotification;
48 my $cds_ntc = Rinchi::CIGIPP::CollisionDetectionSegmentNotification->new();
49  
50 $packet_type = $cds_ntc->packet_type();
51 $packet_size = $cds_ntc->packet_size();
52 $entity_ident = $cds_ntc->entity_ident(22708);
53 $segment_ident = $cds_ntc->segment_ident(165);
54 $collision_type = $cds_ntc->collision_type(Rinchi::CIGIPP->CollisionEntity);
55 $contacted_entity_ident = $cds_ntc->contacted_entity_ident(26345);
56 $material_code = $cds_ntc->material_code(56614);
57 $intersection_distance = $cds_ntc->intersection_distance(10.493);
58  
59 =head1 DESCRIPTION
60  
61 The Collision Detection Segment Notification packet is used to notify the Host
62 when a collision occurs between a collision detection segment and a polygon.
63 When a segment intersects a polygon whose material code matches the collision
64 mask defined for the segment, the IG sends a Collision Detection Segment
65 Notification packet indicating where and with what the collision occurred. If a
66 segment intersects multiple polygons with material codes matching the mask,
67 only the closest intersection is returned. Segments are not tested against
68 polygons belonging to same the entity as the segment.
69  
70 Note that collision detection testing is performed every frame by the IG. If a
71 collision detection segment has been disabled, it will be excluded from all
72 collision testing.
73  
74 =head2 EXPORT
75  
76 None by default.
77  
78 #==============================================================================
79  
80 =item new $cds_ntc = Rinchi::CIGIPP::CollisionDetectionSegmentNotification->new()
81  
82 Constructor for Rinchi::CollisionDetectionSegmentNotification.
83  
84 =cut
85  
86 2 ▶sub new {
Subroutine new: called CC=7 SCAR=29.8
Pod documented
87 2 my $class = shift;
88 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
89  
90 2 my $self = {
91 '_Buffer' => '',
92 '_ClassIdent' => 'f78b3b42-200e-11de-bdd3-001c25551abc',
93 '_Pack' => 'CCSCCSIf',
94 '_Swap1' => 'CCvCCvVV',
95 '_Swap2' => 'CCnCCnNN',
96 'packetType' => 113,
97 'packetSize' => 16,
98 'entityIdent' => 0,
99 'segmentIdent' => 0,
100 '_bitfields1' => 0, # Includes bitfields unused83, and collisionType.
101 'collisionType' => 0,
102 'contactedEntityIdent' => 0,
103 'materialCode' => 0,
104 'intersectionDistance' => 0,
105 };
106  
107 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
108 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
109 0 $self->{'_Buffer'} = $_[0][0];
110 } elsif (ref($_[0]) eq 'HASH') {
111 0 foreach my $attr (keys %{$_[0]}) {
112 0 ▶ $self->{"_$attr"} = $_[0]->{$attr} unless ($attr =~ /^_/);
Branch: 1 branch
BranchTrueFalseTotal
unless $attr =~ /^_/ 0 0 0
113 }
114 }
115 }
116  
117 2 bless($self,$class);
118 2 return $self;
119 }
120  
121 #==============================================================================
122  
123 =item sub packet_type()
124  
125 $value = $cds_ntc->packet_type();
126  
127 Data Packet Identifier.
128  
129 This attribute identifies this data packet as the Collision Detection Segment
130 Notification packet. The value of this attribute must be 113.
131  
132 =cut
133  
134 2 ▶sub packet_type() {
Subroutine packet_type: called CC=1 SCAR=0.0
Pod documented
135 2 my ($self) = @_;
136 2 return $self->{'packetType'};
137 }
138  
139 #==============================================================================
140  
141 =item sub packet_size()
142  
143 $value = $cds_ntc->packet_size();
144  
145 Data Packet Size.
146  
147 This attribute indicates the number of bytes in this data packet. The value of
148 this attribute must be 16.
149  
150 =cut
151  
152 2 ▶sub packet_size() {
Subroutine packet_size: called CC=1 SCAR=0.0
Pod documented
153 2 my ($self) = @_;
154 2 return $self->{'packetSize'};
155 }
156  
157 #==============================================================================
158  
159 =item sub entity_ident([$newValue])
160  
161 $value = $cds_ntc->entity_ident($newValue);
162  
163 Entity ID.
164  
165 This attribute indicates the entity to which the collision detection segment belongs.
166  
167 =cut
168  
169 2 ▶sub entity_ident() {
Subroutine entity_ident: called CC=2 SCAR=7.0
Pod documented
170 2 my ($self,$nv) = @_;
171 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
172 2 $self->{'entityIdent'} = $nv;
173 }
174 2 return $self->{'entityIdent'};
175 }
176  
177 #==============================================================================
178  
179 =item sub segment_ident([$newValue])
180  
181 $value = $cds_ntc->segment_ident($newValue);
182  
183 Segment ID.
184  
185 This attribute indicates the ID of the collision detection segment along which
186 the collision occurred.
187  
188 This attribute, along with Entity ID, allows the Host to match this response
189 with the corresponding request.
190  
191 =cut
192  
193 2 ▶sub segment_ident() {
Subroutine segment_ident: called CC=2 SCAR=7.0
Pod documented
194 2 my ($self,$nv) = @_;
195 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
196 2 $self->{'segmentIdent'} = $nv;
197 }
198 2 return $self->{'segmentIdent'};
199 }
200  
201 #==============================================================================
202  
203 =item sub collision_type([$newValue])
204  
205 $value = $cds_ntc->collision_type($newValue);
206  
207 Collision Type.
208  
209 This attribute indicates whether the collision occurred with another entity or
210 with a non-entity object such as the terrain.
211  
212 CollisionNonEntity 0
213 CollisionEntity 1
214  
215 =cut
216  
217 2 ▶sub collision_type() {
Subroutine collision_type: called CC=4 SCAR=15.5
Pod documented
218 2 my ($self,$nv) = @_;
219 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
220 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
020
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
221 2 $self->{'collisionType'} = $nv;
222 2 $self->{'_bitfields1'} |= $nv &0x01;
223 } else {
224 0 carp "collision_type must be 0 (CollisionNonEntity), or 1 (CollisionEntity).";
225 }
226 }
227 2 return ($self->{'_bitfields1'} & 0x01);
228 }
229  
230 #==============================================================================
231  
232 =item sub contacted_entity_ident([$newValue])
233  
234 $value = $cds_ntc->contacted_entity_ident($newValue);
235  
236 Contacted Entity ID.
237  
238 This attribute indicates the entity with which the collision occurred.
239  
240 If Collision Type is set to Non-entity (0), this attribute is ignored.
241  
242 =cut
243  
244 2 ▶sub contacted_entity_ident() {
Subroutine contacted_entity_ident: called CC=2 SCAR=7.0
Pod documented
245 2 my ($self,$nv) = @_;
246 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
247 2 $self->{'contactedEntityIdent'} = $nv;
248 }
249 2 return $self->{'contactedEntityIdent'};
250 }
251  
252 #==============================================================================
253  
254 =item sub material_code([$newValue])
255  
256 $value = $cds_ntc->material_code($newValue);
257  
258 Material Code.
259  
260 This attribute indicates the material code of the surface at the point of collision.
261  
262 =cut
263  
264 2 ▶sub material_code() {
Subroutine material_code: called CC=2 SCAR=7.0
Pod documented
265 2 my ($self,$nv) = @_;
266 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
267 2 $self->{'materialCode'} = $nv;
268 }
269 2 return $self->{'materialCode'};
270 }
271  
272 #==============================================================================
273  
274 =item sub intersection_distance([$newValue])
275  
276 $value = $cds_ntc->intersection_distance($newValue);
277  
278 Intersection Distance.
279  
280 This attribute indicates the distance along the collision test vector from the
281 source endpoint (defined by the X1, Y1, and Z1 attributes in the Collision
282 intersection. Detection Segment Definition packet) to the point of intersection.
283  
284 =cut
285  
286 2 ▶sub intersection_distance() {
Subroutine intersection_distance: called CC=2 SCAR=7.0
Pod documented
287 2 my ($self,$nv) = @_;
288 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
289 2 $self->{'intersectionDistance'} = $nv;
290 }
291 2 return $self->{'intersectionDistance'};
292 }
293  
294 #==========================================================================
295  
296 =item sub pack()
297  
298 $value = $cds_ntc->pack();
299  
300 Returns the packed data packet.
301  
302 =cut
303  
304 2 ▶sub pack($) {
Subroutine pack: called CC=1 SCAR=0.0
Pod documented
305 2 my $self = shift ;
306
307 $self->{'_Buffer'} = CORE::pack($self->{'_Pack'},
308 $self->{'packetType'},
309 $self->{'packetSize'},
310 $self->{'entityIdent'},
311 $self->{'segmentIdent'},
312 $self->{'_bitfields1'}, # Includes bitfields unused83, and collisionType.
313 $self->{'contactedEntityIdent'},
314 $self->{'materialCode'},
315 2 $self->{'intersectionDistance'},
316 );
317  
318 2 return $self->{'_Buffer'};
319 }
320  
321 #==========================================================================
322  
323 =item sub unpack()
324  
325 $value = $cds_ntc->unpack();
326  
327 Unpacks the packed data packet.
328  
329 =cut
330  
331 0 ▶sub unpack($) {
Subroutine unpack: not called CC=2 SCAR=17.9
Pod documented
332 0 my $self = shift @_;
333
334 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
335 0 $self->{'_Buffer'} = shift @_;
336 }
337 0 my ($a,$b,$c,$d,$e,$f,$g,$h) = CORE::unpack($self->{'_Pack'},$self->{'_Buffer'});
338 0 $self->{'packetType'} = $a;
339 0 $self->{'packetSize'} = $b;
340 0 $self->{'entityIdent'} = $c;
341 0 $self->{'segmentIdent'} = $d;
342 0 $self->{'_bitfields1'} = $e; # Includes bitfields unused83, and collisionType.
343 0 $self->{'contactedEntityIdent'} = $f;
344 0 $self->{'materialCode'} = $g;
345 0 $self->{'intersectionDistance'} = $h;
346  
347 0 $self->{'collisionType'} = $self->collision_type();
348  
349 0 return $self->{'_Buffer'};
350 }
351  
352 #==========================================================================
353  
354 =item sub byte_swap()
355  
356 $obj_name->byte_swap();
357  
358 Byte swaps the packed data packet.
359  
360 =cut
361  
362 0 ▶sub byte_swap($) {
Subroutine byte_swap: not called CC=2 SCAR=17.9
Pod documented
363 0 my $self = shift @_;
364
365 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
366 0 $self->{'_Buffer'} = shift @_;
367 } else {
368 0 $self->pack();
369 }
370 0 my ($a,$b,$c,$d,$e,$f,$g,$h) = CORE::unpack($self->{'_Swap1'},$self->{'_Buffer'});
371  
372 0 $self->{'_Buffer'} = CORE::pack($self->{'_Swap2'},$a,$b,$c,$d,$e,$f,$g,$h);
373 0 $self->unpack();
374  
375 0 return $self->{'_Buffer'};
376 }
377  
378 2 1;
379 __END__
« CIGIPP/IGControl.pm ↑ Summary CIGIPP/TrajectoryDefinition.pm »