File Coverage

blib/lib/Rinchi/CIGIPP/EntityControl.pm
Criterion Covered Total %
statement 122 188 64.8
branch 32 80 40.0
condition 15 51 29.4
subroutine 27 32 84.3
pod 28 28 100.0
total 224 379 59.1


line stmt bran cond sub pod time code
1             #
2             # Rinchi Common Image Generator Interface for Perl
3             # Class Identifier: f78ab726-200e-11de-bda2-001c25551abc
4             # Author: Brian M. Ames
5             #
6              
7             package Rinchi::CIGIPP::EntityControl;
8              
9 1     1   28 use 5.006;
  1         4  
  1         38  
10 1     1   6 use strict;
  1         1  
  1         2383  
11 1     1   12 use warnings;
  1         3  
  1         54  
12 1     1   7 use Carp;
  1         2  
  1         13412  
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.02';
36              
37             # Preloaded methods go here.
38              
39             =head1 NAME
40              
41             Rinchi::CIGIPP::EntityControl - Perl extension for the Common Image Generator
42             Interface - Entity Control data packet.
43             data packet.
44             =head1 SYNOPSIS
45              
46             use Rinchi::CIGIPP::EntityControl;
47             my $ent_ctl = Rinchi::CIGIPP::EntityControl->new();
48              
49             $packet_type = $ent_ctl->packet_type();
50             $packet_size = $ent_ctl->packet_size();
51             $entity_ident = $ent_ctl->entity_ident(18430);
52             $ground_clamp = $ent_ctl->ground_clamp(0);
53             $inherit_alpha = $ent_ctl->inherit_alpha(1);
54             $collision_detection = $ent_ctl->collision_detection(1);
55             $attach_state = $ent_ctl->attach_state(Rinchi::CIGIPP->Attach);
56             $entity_state = $ent_ctl->entity_state(Rinchi::CIGIPP->EntityInactive);
57             $extrapolation_enable = $ent_ctl->extrapolation_enable(Rinchi::CIGIPP->Disable);
58             $animation_state = $ent_ctl->animation_state(Rinchi::CIGIPP->Stop);
59             $animation_loop = $ent_ctl->animation_loop(Rinchi::CIGIPP->Continuous);
60             $animation_direction = $ent_ctl->animation_direction(Rinchi::CIGIPP->Backward);
61             $alpha = $ent_ctl->alpha(249);
62             $entity_type = $ent_ctl->entity_type(54457);
63             $parent_ident = $ent_ctl->parent_ident(38194);
64             $roll = $ent_ctl->roll(36.539);
65             $pitch = $ent_ctl->pitch(15.394);
66             $yaw = $ent_ctl->yaw(53.214);
67             $latitude = $ent_ctl->latitude(4.828);
68             $x_offset = $ent_ctl->x_offset(22.092);
69             $longitude = $ent_ctl->longitude(33.727);
70             $y_offset = $ent_ctl->y_offset(71.648);
71             $altitude = $ent_ctl->altitude(20.674);
72             $z_offset = $ent_ctl->z_offset(81.962);
73              
74             =head1 DESCRIPTION
75              
76             The Entity Control packet is used to control position, attitude, and other
77             attributes describing an entity's state. This packet may be applied to any
78             entity in the simulation, including the Ownship.
79              
80             Each entity is identified by a unique identifier called the Entity ID. When the
81             Host sends an Entity Control packet to the IG, the IG sets the state of the
82             entity object corresponding to the value of the Entity ID attribute. If the
83             specified entity does not exist, the IG will create it.
84              
85             When the IG creates an entity, it makes a copy of the geometry corresponding to
86             the value of the Entity Type attribute. This copy exists as a unique and
87             independent tree within the scene graph; therefore, any operations that modify
88             an entity's tree (e.g., part articulations) affect only that entity and its
89             children.
90             Entities can be attached to one another in a hierarchical relationship. In such
91             a hierarchy, a child entity's position is specified relative to its parent's
92             coordinate system. The Host needs only to control the parent entity in order to
93             move all lower entities in the hierarchy as a group. No explicit manipulation
94             of a child entity is necessary unless its position and attitude change with
95             respect to its parent.
96              
97             The Attach State attribute of the Entity Control packet determines whether an
98             entity is attached to a parent. If this attribute is set to Attach (1), the
99             entity is attached to the entity specified by the Parent ID attribute. The
100             Entity State attribute is used to control when an entity is visible and when
101             its geometry is loaded and unloaded. When an entity is created, the Entity
102             State attribute can be set to Active to specify that the entity should be added
103             to the scene as soon as the model geometry is loaded. The entity and any
104             children can be made invisible at any time by setting Entity State to
105             Inactive/Standby. When the entity is no longer needed, Entity State can be set
106             to Destroyed to direct the IG to unload the geometry and free any memory
107             allocated for the entity. Any children attached to the entity are also
108             destroyed.
109             Models can be preloaded to increase the speed at which they can be initially
110             displayed. For example, when an aircraft fires a missile, a new entity would
111             need to be created for that missile. Unless the missile geometry is cached, the
112             IG must load the model from its hard disk. Because of its tremendous speed, the
113             missile might fly a significant distance (and possibly beyond visual range)
114             before the disk I/O can be completed. By preloading the entity, the geometry
115             can already exist in memory and be instantly activated within the scene graph
116             when needed. To accomplish this, the Entity State flag could be set to
117             Inactive/Standby when the missile is created. Later, when the missile is
118             needed, an Entity Control packet for that entity would be sent containing the
119             proper positional data and with the Entity State flag set to Active.
120              
121             An entity can also be made invisible by setting the Alpha attribute to zero
122             (0). This attribute specifies an alpha value to be applied to the entity's
123             geometry. The Inherit Alpha attribute indicates whether a child entity's alpha
124             value is combined with that of its parent. For example, a missile attached to
125             the wing of an aircraft would typically be made invisible when the aircraft is
126             destroyed, so its Inherit Alpha attribute would be set to Inherited (1). An
127             explosion or similar animation attached to that aircraft, however, would
128             typically linger after the aircraft's destruction, so its Inherit Alpha
129             attribute would be set to Not Inherited (0).
130              
131             Note that setting the Entity State attribute to Inactive/Standby is not
132             equivalent to setting the Alpha attribute to zero (0). The Entity State
133             attribute enables or disables the entity geometry in the scene graph. The
134             entity would not be included in line of sight and collision testing, nor would
135             any transformations be applied. Any children would also be disabled. The Alpha
136             attribute, on the other hand, merely affects the opacity of the specified
137             entity.
138             The positions of top-level entities (i.e., those entities that are not
139             children) are always specified as a geodetic latitude, longitude, and altitude.
140             The positions of child entities are always specified with respect to the
141             parents' NED body coordinate system.
142              
143             In certain instances, it is desirable for the IG to "clamp" the entity to the
144             surface of the terrain. This can be used as an alternative to using HOT
145             requests and responses to determine ground elevation and slope below the
146             entity. If the Ground/Ocean Clamp attribute is set to Non-Conformal (1) or
147             Conformal (2), the Altitude attribute specifies an offset above the ground or
148             sea surface height. This is useful for specifying the vertical distance from an
149             automobile's reference point to its wheels, for instance, or from a ship's
150             reference point to its waterline. Similarly, Roll and Pitch specify rotational
151             offsets if ground or ocean clamping is enabled.
152              
153             The Animation State attribute is used to control the playback state of
154             animation entities. To start the animation sequence, the Host will send an
155             Entity Control packet with its Entity State set to Active and its Animation
156             State attribute to either Play or Resume. The Host may explicitly stop the
157             animation at any time by setting the Animation State to Stop. Setting the
158             attribute to Pause freezes the animation sequence at the current frame. Setting
159             the attribute to Resume in a subsequent frame will resume the animation from
160             its paused state; setting it to Play will play the animation again from its
161             initial state. Setting Animation State to Play during playback will restart the
162             animation.
163             Note that setting the Animation State attribute to Stop will have different
164             effects on different types of animations. Frame-based animations may simply
165             stop, or begin a termination sequence if such a sequence has been defined, at
166             the current frame. Emitter-based animations (e.g, missile trails and particle
167             systems) will stop producing new particles or segments; however, existing
168             particles or segments will continue to decay normally. Stopping an animation
169             does not implicitly remove it from the scene unless the Entity State attribute
170             is set to Inactive/Standby or Destroyed.
171              
172             If an animation has been built with a limited duration, and if the Animation
173             Loop Mode attribute is set to One-Shot, the animation will stop automatically
174             upon its completion. The IG will indicate this condition by sending an
175             Animation Stop Notification packet to the Host. If the Animation Loop Mode
176             attribute is set to Loop, the animation will immediately restart from the
177             beginning and no Animation Stop Notification packet will be sent.
178              
179             Once an Entity Control packet describing an entity is sent to the IG, the state
180             of that entity will not change until another Entity Control packet specifying
181             that entity ID is received. For example, packets describing the Ownship and a
182             wingman may be sent every frame to indicate continuous positional changes,
183             while a packet describing an inactive SAM site may be sent once during mission initialization.
184              
185             =head2 EXPORT
186              
187             None by default.
188              
189             #==============================================================================
190              
191             =item new $ent_ctl = Rinchi::CIGIPP::EntityControl->new()
192              
193             Constructor for Rinchi::EntityControl.
194              
195             =cut
196              
197             sub new {
198 1     1 1 225 my $class = shift;
199 1   33     8 $class = ref($class) || $class;
200              
201 1         26 my $self = {
202             '_Buffer' => '',
203             '_ClassIdent' => 'f78ab726-200e-11de-bda2-001c25551abc',
204             '_Pack' => 'CCSCCCCSSfffddd',
205             '_Swap1' => 'CCvCCCCvvVVVVVVVVV',
206             '_Swap2' => 'CCnCCCCnnNNNNNNNNN',
207             'packetType' => 2,
208             'packetSize' => 48,
209             'entityIdent' => 0,
210             '_bitfields1' => 0, # Includes bitfields unused3, groundClamp, inheritAlpha, collisionDetection, attachState, and entityState.
211             'groundClamp' => 0,
212             'inheritAlpha' => 0,
213             'collisionDetection' => 0,
214             'attachState' => 0,
215             'entityState' => 0,
216             '_bitfields2' => 0, # Includes bitfields unused4, extrapolationEnable, animationState, animationLoop, and animationDirection.
217             'extrapolationEnable' => 0,
218             'animationState' => 0,
219             'animationLoop' => 0,
220             'animationDirection' => 0,
221             'alpha' => 0,
222             '_unused5' => 0,
223             'entityType' => 0,
224             'parentIdent' => 0,
225             'roll' => 0,
226             'pitch' => 0,
227             'yaw' => 0,
228             'latitude_xOffset' => 0,
229             'longitude_yOffset' => 0,
230             'altitude_zOffset' => 0,
231             };
232              
233 1 50       5 if (@_) {
234 0 0       0 if (ref($_[0]) eq 'ARRAY') {
    0          
235 0         0 $self->{'_Buffer'} = $_[0][0];
236             } elsif (ref($_[0]) eq 'HASH') {
237 0         0 foreach my $attr (keys %{$_[0]}) {
  0         0  
238 0 0       0 $self->{"_$attr"} = $_[0]->{$attr} unless ($attr =~ /^_/);
239             }
240             }
241             }
242              
243 1         4 bless($self,$class);
244 1         3 return $self;
245             }
246              
247             #==============================================================================
248              
249             =item sub packet_type()
250              
251             $value = $ent_ctl->packet_type();
252              
253             Data Packet Identifier.
254              
255             This attribute identifies this data packet as the Entity Control packet. The
256             value of this attribute must be 2.
257              
258             =cut
259              
260             sub packet_type() {
261 1     1 1 9 my ($self) = @_;
262 1         9 return $self->{'packetType'};
263             }
264              
265             #==============================================================================
266              
267             =item sub packet_size()
268              
269             $value = $ent_ctl->packet_size();
270              
271             Data Packet Size.
272              
273             This attribute indicates the number of bytes in this data packet. The value of
274             this attribute must be 48.
275              
276             =cut
277              
278             sub packet_size() {
279 1     1 1 5 my ($self) = @_;
280 1         3 return $self->{'packetSize'};
281             }
282              
283             #==============================================================================
284              
285             =item sub entity_ident([$newValue])
286              
287             $value = $ent_ctl->entity_ident($newValue);
288              
289             Entity ID.
290              
291             This attribute specifies the entity to which this packet will be applied. A
292             value of zero (0) corresponds to the Ownship.
293              
294             =cut
295              
296             sub entity_ident() {
297 1     1 1 6 my ($self,$nv) = @_;
298 1 50       4 if (defined($nv)) {
299 1         2 $self->{'entityIdent'} = $nv;
300             }
301 1         4 return $self->{'entityIdent'};
302             }
303              
304             #==============================================================================
305              
306             =item sub ground_clamp([$newValue])
307              
308             $value = $ent_ctl->ground_clamp($newValue);
309              
310             Ground/Ocean Clamp.
311              
312             This attribute specifies whether the entity should be clamped to the ground or
313             water surface. If Attach State is set to Attach (1), this attribute is ignored.
314              
315             No Clamp – The entity is not clamped. The Altitude attribute specifies the
316             entity's height above Mean Sea Level. The Pitch and Roll attributes specify the
317             entity's pitch and roll relative to the geodetic reference plane.
318              
319             Non-Conformal – The entity is clamped. The Altitude attribute specifies an
320             offset above the terrain or sea level. The Pitch and Roll attributes specify
321             the entity's pitch and roll relative to the geodetic reference plane. Conformal
322             – The entity is clamped and its attitude conforms to the terrain. The Altitude
323             attribute specifies an offset above the terrain or sea level. The Pitch and
324             Roll attributes specify the entity's pitch and roll relative to the slope of
325             the terrain or water.
326              
327             =cut
328              
329             sub ground_clamp() {
330 1     1 1 6 my ($self,$nv) = @_;
331 1 50       4 if (defined($nv)) {
332 1         3 $self->{'groundClamp'} = $nv;
333 1         3 $self->{'_bitfields1'} |= ($nv << 5) &0x60;
334             }
335 1         3 return (($self->{'_bitfields1'} & 0x60) >> 5);
336             }
337              
338             #==============================================================================
339              
340             =item sub inherit_alpha([$newValue])
341              
342             $value = $ent_ctl->inherit_alpha($newValue);
343              
344             Inherit Alpha
345              
346             This attribute specifies whether the entity's alpha is combined with the
347             apparent alpha of its parent.
348              
349             Note that a change in an entity's alpha affects the entities below it in the
350             hierarchy if those entities inherit their parents' alphas.
351              
352             If Attach State is set to Detach (0), this attribute is ignored.
353              
354             =cut
355              
356             sub inherit_alpha() {
357 1     1 1 6 my ($self,$nv) = @_;
358 1 50       4 if (defined($nv)) {
359 1         3 $self->{'inheritAlpha'} = $nv;
360 1         3 $self->{'_bitfields1'} |= ($nv << 4) &0x10;
361             }
362 1         5 return (($self->{'_bitfields1'} & 0x10) >> 4);
363             }
364              
365             #==============================================================================
366              
367             =item sub collision_detection_enable([$newValue])
368              
369             $value = $ent_ctl->collision_detection_enable($newValue);
370              
371             Collision Detection Enable.
372              
373             This attribute determines whether any collision detection segments and volumes
374             associated with this entity are used as the source in collision testing.
375              
376             If this attribute is set to Enabled (1), every frame each collision detection
377             segment is tested for intersections with polygons not associated with this
378             entity and each collision detection volume is tested pair-wise with every other
379             volume that is not associated with the entity.
380              
381             If this attribute is set to Disabled (0), any collision detection segments
382             defined for the entity are ignored and any collision detection volumes are only
383             tested (as the destination) against volumes defined for entities whose
384             collision detection is enabled.
385              
386             Disable 0
387             Enable 1
388              
389             =cut
390              
391             sub collision_detection_enable() {
392 1     1 1 7 my ($self,$nv) = @_;
393 1 50       4 if (defined($nv)) {
394 1 50 33     23 if (($nv==0) or ($nv==1)) {
395 1         4 $self->{'collisionDetection'} = $nv;
396 1         2 $self->{'_bitfields1'} |= ($nv << 3) &0x08;
397             } else {
398 0         0 carp "collision_detection_enable must be 0 (Disable), or 1 (Enable).";
399             }
400             }
401 1         4 return (($self->{'_bitfields1'} & 0x08) >> 3);
402             }
403              
404             #==============================================================================
405              
406             =item sub attach_state([$newValue])
407              
408             $value = $ent_ctl->attach_state($newValue);
409              
410             Attach State.
411              
412             This attribute specifies whether the entity should be attached as a child to a
413             parent.
414             If this attribute is set to Detach (0), the entity becomes or remains a
415             top-level (non-child) entity. The Parent ID attribute is ignored. The Yaw,
416             Pitch, Roll, Latitude, Longitude, and Altitude attributes all specify the
417             entity's position relative to the geodetic coordinate system.
418              
419             If this attribute is set to Attach (1), the entity becomes or remains attached
420             to the entity specified by the Parent ID attribute. The parent must already
421             exist, having been created in a prior frame or earlier in the current frame.
422             The Yaw, Pitch, Roll, X Offset, Y Offset, and Z Offset attributes all specify
423             the entity's position relative to the parent's coordinate system.
424              
425             This attribute may be changed for a given entity at any time. The attachment or
426             detachment takes place immediately and remains in effect until changed with
427             another Entity Control packet.
428              
429             Detach 0
430             Attach 1
431              
432             =cut
433              
434             sub attach_state() {
435 1     1 1 2 my ($self,$nv) = @_;
436 1 50       5 if (defined($nv)) {
437 1 50 33     9 if (($nv==0) or ($nv==1)) {
438 1         3 $self->{'attachState'} = $nv;
439 1         3 $self->{'_bitfields1'} |= ($nv << 2) &0x04;
440             } else {
441 0         0 carp "attach_state must be 0 (Detach), or 1 (Attach).";
442             }
443             }
444 1         4 return (($self->{'_bitfields1'} & 0x04) >> 2);
445             }
446              
447             #==============================================================================
448              
449             =item sub entity_state([$newValue])
450              
451             $value = $ent_ctl->entity_state($newValue);
452              
453             Entity State.
454              
455             This attribute specifies whether the entity should be active or destroyed. It
456             may be set to one of the following values:
457              
458             Inactive/Standby – The entity is loaded, but its tree is not enabled in the
459             scene graph. The entity is invisible, and no transformations are applied.
460             Additionally, the entity is excluded from line of sight and collision testing.
461              
462             Active – The entity's tree is enabled in the scene graph. Transformations are
463             applied to the entity and it is included in line of sight and collision
464             testing.
465             Destroyed – The entity's tree is removed from the scene graph. Any children are
466             also destroyed. All other attributes in this packet are ignored.
467              
468             EntityInactive 0
469             EntityStandby 1
470             EntityActive 1
471             EntityDestroyed 2
472              
473             =cut
474              
475             sub entity_state() {
476 1     1 1 3 my ($self,$nv) = @_;
477 1 50       4 if (defined($nv)) {
478 1 50 33     9 if (($nv==0) or ($nv==1) or ($nv==1) or ($nv==2)) {
      33        
      0        
479 1         4 $self->{'entityState'} = $nv;
480 1         2 $self->{'_bitfields1'} |= $nv &0x03;
481             } else {
482 0         0 carp "entity_state must be 0 (EntityInactive), 1 (EntityStandby), 1 (EntityActive), or 2 (EntityDestroyed).";
483             }
484             }
485 1         3 return ($self->{'_bitfields1'} & 0x03);
486             }
487              
488             #==============================================================================
489              
490             =item sub extrapolation_enable([$newValue])
491              
492             $value = $ent_ctl->extrapolation_enable($newValue);
493              
494             Linear Extrapolation/Interpolation Enable
495              
496             This attribute specifies whether the entity's motion may be smoothed by
497             extrapolation or interpolation algorithms on the IG. Such smoothing may be
498             useful for compensating for lost CIGI messages, irregular frame rates,
499             asynchronous operation, etc.
500              
501             If extrapolation or interpolation is disabled globally through the
502             Extrapolation/Interpolation Enable flag of the IG Control packet, then
503             smoothing will not be applied to the entity.
504              
505             Disable 0
506             Enable 1
507              
508             =cut
509              
510             sub extrapolation_enable() {
511 1     1 1 2 my ($self,$nv) = @_;
512 1 50       5 if (defined($nv)) {
513 1 50 33     7 if (($nv==0) or ($nv==1)) {
514 1         4 $self->{'extrapolationEnable'} = $nv;
515 1         3 $self->{'_bitfields2'} |= ($nv << 4) &0x10;
516             } else {
517 0         0 carp "extrapolation_enable must be 0 (Disable), or 1 (Enable).";
518             }
519             }
520 1         3 return (($self->{'_bitfields2'} & 0x10) >> 4);
521             }
522              
523             #==============================================================================
524              
525             =item sub animation_state([$newValue])
526              
527             $value = $ent_ctl->animation_state($newValue);
528              
529             Animation State.
530              
531             This attribute specifies the state of an animation. This attribute applies only
532             when the value of the Entity Type attribute corresponds to an animation.
533              
534             Stop - Stops the animation sequence. If the animation has a termination
535             sequence or decay behavior, the animation will switch to that behavior. Has no
536             effect if the animation is currently stopped.
537              
538             Pause - Pauses playback of an animation. The entity's geometry will remain
539             visible, provided Entity State is set to Active.
540              
541             Play - Begins or restarts playback from the first animation frame.
542              
543             Continue - Continues a playing animation from the current frame of the
544             animation sequence. If the animation is paused, playback is resumed from the
545             current frame. If the animation is stopped, playback is restarted from the
546             first frame of the sequence.
547              
548             Stop 0
549             Pause 1
550             Play 2
551             Continue 3
552              
553             =cut
554              
555             sub animation_state() {
556 1     1 1 8 my ($self,$nv) = @_;
557 1 50       4 if (defined($nv)) {
558 1 50 33     7 if (($nv==0) or ($nv==1) or ($nv==2) or ($nv==3)) {
      33        
      0        
559 1         3 $self->{'animationState'} = $nv;
560 1         3 $self->{'_bitfields2'} |= ($nv << 2) &0x0C;
561             } else {
562 0         0 carp "animation_state must be 0 (Stop), 1 (Pause), 2 (Play), or 3 (Continue).";
563             }
564             }
565 1         3 return (($self->{'_bitfields2'} & 0x0C) >> 2);
566             }
567              
568             #==============================================================================
569              
570             =item sub animation_loop([$newValue])
571              
572             $value = $ent_ctl->animation_loop($newValue);
573              
574             Animation Loop Mode.
575              
576             This attribute specifies whether an animation should be a one-shot (i.e.,
577             should play once and stop) or should loop continuously.
578              
579             OneShot 0
580             Continuous 1
581              
582             =cut
583              
584             sub animation_loop() {
585 1     1 1 4 my ($self,$nv) = @_;
586 1 50       3 if (defined($nv)) {
587 1 50 33     8 if (($nv==0) or ($nv==1)) {
588 1         3 $self->{'animationLoop'} = $nv;
589 1         4 $self->{'_bitfields2'} |= ($nv << 1) &0x02;
590             } else {
591 0         0 carp "animation_loop must be 0 (OneShot), or 1 (Continuous).";
592             }
593             }
594 1         4 return (($self->{'_bitfields2'} & 0x02) >> 1);
595             }
596              
597             #==============================================================================
598              
599             =item sub animation_direction([$newValue])
600              
601             $value = $ent_ctl->animation_direction($newValue);
602              
603             Animation Direction.
604              
605             This attribute specifies the direction in which an animation plays. This
606             attribute applies only when the value of the Entity Type attribute corresponds
607             to an animation.
608              
609             Forward 0
610             Backward 1
611              
612             =cut
613              
614             sub animation_direction() {
615 1     1 1 3 my ($self,$nv) = @_;
616 1 50       4 if (defined($nv)) {
617 1 50 33     7 if (($nv==0) or ($nv==1)) {
618 1         2 $self->{'animationDirection'} = $nv;
619 1         3 $self->{'_bitfields2'} |= $nv &0x01;
620             } else {
621 0         0 carp "animation_direction must be 0 (Forward), or 1 (Backward).";
622             }
623             }
624 1         4 return ($self->{'_bitfields2'} & 0x01);
625             }
626              
627             #==============================================================================
628              
629             =item sub alpha([$newValue])
630              
631             $value = $ent_ctl->alpha($newValue);
632              
633             Alpha.
634              
635             This attribute specifies the explicit alpha to be applied to the entity's
636             geometry. A value of zero (0) corresponds to fully transparent; a value of 255
637             corresponds to fully opaque.
638              
639             =cut
640              
641             sub alpha() {
642 1     1 1 5 my ($self,$nv) = @_;
643 1 50       5 if (defined($nv)) {
644 1         2 $self->{'alpha'} = $nv;
645             }
646 1         4 return $self->{'alpha'};
647             }
648              
649             #==============================================================================
650              
651             =item sub entity_type([$newValue])
652              
653             $value = $ent_ctl->entity_type($newValue);
654              
655             Entity Type.
656              
657             This attribute specifies the type of the entity. A value of zero (0) indicates
658             a “null” type with no associated geometry. Such an entity might be used to
659             represent the Ownship or a floating camera.
660              
661             When changing entity types, the Host should first delete the entity by setting
662             the Entity State attribute to Deactivate (2) and then recreate the entity and
663             any children during a subsequent frame. If the specified type is undefined, the
664             data packet will be disregarded.
665              
666             =cut
667              
668             sub entity_type() {
669 1     1 1 6 my ($self,$nv) = @_;
670 1 50       6 if (defined($nv)) {
671 1         2 $self->{'entityType'} = $nv;
672             }
673 1         3 return $self->{'entityType'};
674             }
675              
676             #==============================================================================
677              
678             =item sub parent_ident([$newValue])
679              
680             $value = $ent_ctl->parent_ident($newValue);
681              
682             Parent ID.
683              
684             This attribute specifies the parent for the entity. If the Attach State
685             attribute is set to Detach (0), this attribute is ignored.
686              
687             The value of this attribute may be changed without first detaching the entity
688             from its existing parent.If the specified parent entity is invalid, no change
689             in the attachment will be made.
690              
691             =cut
692              
693             sub parent_ident() {
694 1     1 1 222 my ($self,$nv) = @_;
695 1 50       5 if (defined($nv)) {
696 1         10 $self->{'parentIdent'} = $nv;
697             }
698 1         4 return $self->{'parentIdent'};
699             }
700              
701             #==============================================================================
702              
703             =item sub roll([$newValue])
704              
705             $value = $ent_ctl->roll($newValue);
706              
707             Roll.
708              
709             This attribute specifies the roll angle of the entity.
710              
711             For child entities, roll is measured from the entity's reference plane after
712             yaw and pitch rotations have been applied.
713              
714             For top-level entities for which Ground/Ocean Clamp is set to No Clamp (0) or
715             Non-Conformal (1), this angle is measured from the reference plane.
716              
717             For top-level entities for which Ground/Ocean Clamp is enabled, this angle
718             specifies an angular offset from the terrain surface polygon's orientation.
719              
720             =cut
721              
722             sub roll() {
723 1     1 1 6 my ($self,$nv) = @_;
724 1 50       4 if (defined($nv)) {
725 1 50 33     9 if (($nv>=-180.0) and ($nv<=180.0)) {
726 1         4 $self->{'roll'} = $nv;
727             } else {
728 0         0 carp "roll must be from -180.0 to +180.0.";
729             }
730             }
731 1         4 return $self->{'roll'};
732             }
733              
734             #==============================================================================
735              
736             =item sub pitch([$newValue])
737              
738             $value = $ent_ctl->pitch($newValue);
739              
740             Pitch.
741              
742             This attribute specifies the pitch angle of the entity.
743              
744             For child entities, pitch is measured with respect to the entity's reference
745             plane after the yaw rotation has been applied.
746              
747             For top-level entities for which Ground/Ocean Clamp is set to No Clamp (0) or
748             Non-Conformal (1), this angle is measured from the reference plane.
749              
750             For top-level entities for which Ground/Ocean Clamp is enabled, this angle
751             specifies an angular offset from the terrain surface polygon's orientation.
752              
753             =cut
754              
755             sub pitch() {
756 1     1 1 5 my ($self,$nv) = @_;
757 1 50       3 if (defined($nv)) {
758 1 50 33     9 if (($nv>=-90) and ($nv<=90.0)) {
759 1         4 $self->{'pitch'} = $nv;
760             } else {
761 0         0 carp "pitch must be from -90.0 to +90.0.";
762             }
763             }
764 1         4 return $self->{'pitch'};
765             }
766              
767             #==============================================================================
768              
769             =item sub yaw([$newValue])
770              
771             $value = $ent_ctl->yaw($newValue);
772              
773             Yaw.
774              
775             For child entities, this attribute specifies a rotation about the child
776             entity's Z axis when the child's X axis is parallel to the parent's X axis.
777              
778             For top-level (non-child) entities, this attribute specifies the instantaneous
779             heading of the entity. This angle is measured from a line parallel to the Prime Meridian.
780              
781             =cut
782              
783             sub yaw() {
784 1     1 1 6 my ($self,$nv) = @_;
785 1 50       3 if (defined($nv)) {
786 1 50 33     9 if (($nv>=0) and ($nv<=360.0)) {
787 1         3 $self->{'yaw'} = $nv;
788             } else {
789 0         0 carp "yaw must be from 0.0 to +360.0.";
790             }
791             }
792 1         4 return $self->{'yaw'};
793             }
794              
795             #==============================================================================
796              
797             =item sub latitude([$newValue])
798              
799             $value = $ent_ctl->latitude($newValue);
800              
801             Latitude.
802              
803             For top-level (non-child) entities, this attribute specifies the entity's
804             geodetic latitude.
805              
806             =cut
807              
808             sub latitude() {
809 1     1 1 5 my ($self,$nv) = @_;
810 1 50       4 if (defined($nv)) {
811 1 50 33     9 if (($nv>=-90) and ($nv<=90.0)) {
812 1         2 $self->{'latitude_xOffset'} = $nv;
813             } else {
814 0         0 carp "latitude must be from -90.0 to +90.0.";
815             }
816             }
817 1         4 return $self->{'latitude_xOffset'};
818             }
819              
820             #==============================================================================
821              
822             =item sub x_offset([$newValue])
823              
824             $value = $ent_ctl->x_offset($newValue);
825              
826             X Offset.
827              
828             For child entities, this attribute represents the distance in meters from the
829             parent's reference point along its parent's X axis.
830              
831             =cut
832              
833             sub x_offset() {
834 0     0 1 0 my ($self,$nv) = @_;
835 0 0       0 if (defined($nv)) {
836 0         0 $self->{'latitude_xOffset'} = $nv;
837             }
838 0         0 return $self->{'latitude_xOffset'};
839             }
840              
841             #==============================================================================
842              
843             =item sub longitude([$newValue])
844              
845             $value = $ent_ctl->longitude($newValue);
846              
847             Longitude.
848              
849             For top-level (non-child) entities, this attribute specifies the entity's
850             geodetic longitude.
851              
852             =cut
853              
854             sub longitude() {
855 1     1 1 6 my ($self,$nv) = @_;
856 1 50       4 if (defined($nv)) {
857 1 50 33     15 if (($nv>=-180.0) and ($nv<=180.0)) {
858 1         3 $self->{'longitude_yOffset'} = $nv;
859             } else {
860 0         0 carp "longitude must be from -180.0 to +180.0.";
861             }
862             }
863 1         4 return $self->{'longitude_yOffset'};
864             }
865              
866             #==============================================================================
867              
868             =item sub y_offset([$newValue])
869              
870             $value = $ent_ctl->y_offset($newValue);
871              
872             Y Offset.
873              
874             For child entities, this attribute represents the distance in meters from the
875             parent's reference point along its parent's Y axis.
876              
877             =cut
878              
879             sub y_offset() {
880 0     0 1 0 my ($self,$nv) = @_;
881 0 0       0 if (defined($nv)) {
882 0         0 $self->{'longitude_yOffset'} = $nv;
883             }
884 0         0 return $self->{'longitude_yOffset'};
885             }
886              
887             #==============================================================================
888              
889             =item sub altitude([$newValue])
890              
891             $value = $ent_ctl->altitude($newValue);
892              
893             Altitude.
894              
895             For top-level (non-child) entities, this attribute specifies the entity's
896             geodetic altitude.
897              
898             =cut
899              
900             sub altitude() {
901 1     1 1 8 my ($self,$nv) = @_;
902 1 50       4 if (defined($nv)) {
903 1         3 $self->{'altitude_zOffset'} = $nv;
904             }
905 1         3 return $self->{'altitude_zOffset'};
906             }
907              
908             #==============================================================================
909              
910             =item sub z_offset([$newValue])
911              
912             $value = $ent_ctl->z_offset($newValue);
913              
914             Z Offset.
915              
916             For child entities, this attribute represents the distance in meters from the
917             parent's reference point along its parent's Z axis.
918              
919             =cut
920              
921             sub z_offset() {
922 0     0 1 0 my ($self,$nv) = @_;
923 0 0       0 if (defined($nv)) {
924 0         0 $self->{'altitude_zOffset'} = $nv;
925             }
926 0         0 return $self->{'altitude_zOffset'};
927             }
928              
929             #==========================================================================
930              
931             =item sub pack()
932              
933             $value = $ent_ctl->pack();
934              
935             Returns the packed data packet.
936              
937             =cut
938              
939             sub pack($) {
940 1     1 1 5 my $self = shift ;
941            
942 1         12 $self->{'_Buffer'} = CORE::pack($self->{'_Pack'},
943             $self->{'packetType'},
944             $self->{'packetSize'},
945             $self->{'entityIdent'},
946             $self->{'_bitfields1'}, # Includes bitfields unused3, groundClamp, inheritAlpha, collisionDetection, attachState, and entityState.
947             $self->{'_bitfields2'}, # Includes bitfields unused4, extrapolationEnable, animationState, animationLoop, and animationDirection.
948             $self->{'alpha'},
949             $self->{'_unused5'},
950             $self->{'entityType'},
951             $self->{'parentIdent'},
952             $self->{'roll'},
953             $self->{'pitch'},
954             $self->{'yaw'},
955             $self->{'latitude_xOffset'},
956             $self->{'longitude_yOffset'},
957             $self->{'altitude_zOffset'},
958             );
959              
960 1         4 return $self->{'_Buffer'};
961             }
962              
963             #==========================================================================
964              
965             =item sub unpack()
966              
967             $value = $ent_ctl->unpack();
968              
969             Unpacks the packed data packet.
970              
971             =cut
972              
973             sub unpack($) {
974 0     0 1   my $self = shift @_;
975            
976 0 0         if (@_) {
977 0           $self->{'_Buffer'} = shift @_;
978             }
979 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o) = CORE::unpack($self->{'_Pack'},$self->{'_Buffer'});
980 0           $self->{'packetType'} = $a;
981 0           $self->{'packetSize'} = $b;
982 0           $self->{'entityIdent'} = $c;
983 0           $self->{'_bitfields1'} = $d; # Includes bitfields unused3, groundClamp, inheritAlpha, collisionDetection, attachState, and entityState.
984 0           $self->{'_bitfields2'} = $e; # Includes bitfields unused4, extrapolationEnable, animationState, animationLoop, and animationDirection.
985 0           $self->{'alpha'} = $f;
986 0           $self->{'_unused5'} = $g;
987 0           $self->{'entityType'} = $h;
988 0           $self->{'parentIdent'} = $i;
989 0           $self->{'roll'} = $j;
990 0           $self->{'pitch'} = $k;
991 0           $self->{'yaw'} = $l;
992 0           $self->{'latitude_xOffset'} = $m;
993 0           $self->{'longitude_yOffset'} = $n;
994 0           $self->{'altitude_zOffset'} = $o;
995              
996 0           $self->{'groundClamp'} = $self->ground_clamp();
997 0           $self->{'inheritAlpha'} = $self->inherit_alpha();
998 0           $self->{'collisionDetection'} = $self->collision_detection_enable();
999 0           $self->{'attachState'} = $self->attach_state();
1000 0           $self->{'entityState'} = $self->entity_state();
1001 0           $self->{'extrapolationEnable'} = $self->extrapolation_enable();
1002 0           $self->{'animationState'} = $self->animation_state();
1003 0           $self->{'animationLoop'} = $self->animation_loop();
1004 0           $self->{'animationDirection'} = $self->animation_direction();
1005              
1006 0           return $self->{'_Buffer'};
1007             }
1008              
1009             #==========================================================================
1010              
1011             =item sub byte_swap()
1012              
1013             $obj_name->byte_swap();
1014              
1015             Byte swaps the packed data packet.
1016              
1017             =cut
1018              
1019             sub byte_swap($) {
1020 0     0 1   my $self = shift @_;
1021            
1022 0 0         if (@_) {
1023 0           $self->{'_Buffer'} = shift @_;
1024             } else {
1025 0           $self->pack();
1026             }
1027 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r) = CORE::unpack($self->{'_Swap1'},$self->{'_Buffer'});
1028              
1029 0           $self->{'_Buffer'} = CORE::pack($self->{'_Swap2'},$a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$n,$m,$p,$o,$r,$q);
1030 0           $self->unpack();
1031              
1032 0           return $self->{'_Buffer'};
1033             }
1034              
1035             1;
1036             __END__