![]() |
VR-Forces 4.0.4 Class Documentation
|
DtBallisticGun provides a simple model of a ballistic gun. More...

Public Member Functions | |
| DtBallisticGun (const DtString &name, DtVrfObject *owner, DtSimManager *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0) | |
| (const DtString&,DtVrfObject*,DtSimManager*, | |
| virtual | ~DtBallisticGun () |
| destructor | |
| virtual bool | init () |
| Overridden to cache a pointer to the entity's radio in this class. | |
| virtual void | initPendingDetonations () |
| Called in the first tick. | |
| virtual DtString | type () const |
| Returns a string identifies the class type of component. | |
| virtual void | tick () |
| Fire and detonate. | |
| virtual bool | checkHitProbability (const DtEntityType &type, DtReal range) |
| Returns true if we hit the target, false otherwise. | |
| virtual double | hitProbabilityModifier (const DtEntityType &type, DtReal range) |
| Override this function to dynamically change the probability of a hit based on factors such as current speed, weather conditions, etc. | |
| virtual DtFireInteraction * | createFireInteraction () |
| Allocates a DtFireInteraction and then uses the munition information specified on the munition and fuze ports, as well as the current target reported by the entity, to fill in the necessary fields. | |
| virtual DtDetonationInteraction * | createDetonationInteraction (DtTime &detTime, bool assureMiss=false) |
| Allocates a DtDetonationInteraction. | |
| virtual void | scheduleDetonation (DtDetonationInteraction *detInter, DtTime detTime) |
| Schedules the sending of the DtDetonationInteraction passed as the first argument at a point in the future specified by the second argument, using the DtScheduler facility (which is accessed through the DtSimManager). | |
| virtual DtString | probabilityString () const |
| virtual DtVector | calculateMuzzlePosition () const |
| Finds the correct muzzle placement for the gun. | |
| virtual DtDetonationInteraction * | createDetonationInteraction (const DtDetonationDescriptor &desc, DtTime &detTime) |
| Creates a new DtDetonationInteraction, given a DtDetonationDescriptor. | |
| virtual DtDetonationDescriptor * | createDetonationDescriptor (DtDetonationInteraction *detInter, DtTime simTime) |
| Creates and fills out a new DtDetonationDescriptor, given a DtDetonationInteraction and a time (simulation time to fire, in seconds). | |
Static Public Member Functions | |
| static void | detonationCallback (DtTimer *timer) |
| Casts the user data portion of the DtTimer passed to it to a DtDetonationTimerData object. | |
| static DtSimComponent * | creator (const DtString &name, DtVrfObject *owner, DtSimManager *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0) |
| (const DtString&,DtVrfObject*,DtSimManager*, | |
| static void | objectAddedCb (DtVrfObject *vrfObject, void *usr) |
| Calls processObjectAdded(). | |
Protected Member Functions | |
| virtual bool | createPortGroups () |
| Overridden to create local port groups. | |
| virtual bool | createPorts () |
| Overridden to create local ports. | |
| virtual bool | createPSR () |
| Creates myProcessState data member, and adds it to our process state repository manager. | |
| virtual void | processObjectAdded (DtVrfObject *vrfObject) |
| Checks pending detonation list (in the process state repository) for target with same name as new object. | |
| virtual void | addRangeItems () |
| Adds all items that have a range to the object state repository. | |
| DtBallisticGun () | |
| default constructor; not implemented | |
| DtBallisticGun (const DtBallisticGun &orig) | |
| copy constructor; not implemented | |
| const DtBallisticGun & | operator= (const DtBallisticGun &orig) |
| assignment operator; not implemented | |
Protected Attributes | |
| DtBallisticGunDescriptor * | myBalGunDescriptor |
| DtEntityIdentifier | myObjectId |
| DtReal | myMuzzleSpeed |
| DtVector | myMuzzleOffset |
| DtVrfObject * | myCurrentTarget |
| These are set by createFireInteraction and used by createDetonationInteraction. | |
| DtEventId | myCurrentEventId |
| DtReal | myCurrentRange |
| DtList | myTimerList |
| DtArtPartType | myGunArtPart |
| DtVrfBalGunPSR * | myProcessState |
| Container for state data associated with this component. | |
| bool | myFirstTick |
Ports and Port Groups | |
| DtInputPortGroup * | myBalGunControlPortGroup |
| Input Port Group Name: gun-control Input Port Group Description: | |
| DtBooleanInputPort * | myTriggerPort |
| Input Port Name: trigger Input Port Description: Edge-triggered input which fires a round whenever a new True arrives on the port. | |
| DtIntegerInputPort * | myQuantityInputPort |
| Input Port Name: quantity Input Port Description: Indicates the number of rounds to be fired with a single trigger pull. | |
| DtBooleanInputPort * | myLoadedPort |
| Input Port Name: loaded Input Port Description: Must be True for gun to fire. | |
| DtIntegerInputPort * | myLosPort |
| Input Port Name: line-of-sight Input Port Description: Indicates the result of a line of sight calculation to the current target. | |
DtBallisticGun provides a simple model of a ballistic gun.
End User Description: The ballistic gun actuator uses the ammunition data and trigger values it receives. When the trigger port has the value of true, it creates a fire interaction using the ammunition indicated and the current state of the entity at the entity’s current target. It also checks the hit probability table to decide if this should be a hit. It creates the proper detonation interaction for the determined result and schedules the interaction to be sent at the appropriate time.
Uses Descriptor Type: DtBallisticGunDescriptor
| DtBallisticGun::DtBallisticGun | ( | const DtString & | name, |
| DtVrfObject * | owner, | ||
| DtSimManager * | simManager, | ||
| DtComponentDescriptor * | desc = 0, |
||
| DtReaderWriterRegistry * | parentRegistry = 0 |
||
| ) |
(const DtString&,DtVrfObject*,DtSimManager*,
| name | Reader writer name of this component. |
| owner | The DtVrfObject that owns this component |
| simManager | The simulation manager (provides access to terrain, message interface, simulation clock). |
| desc | The component descriptor used to initialize this component. |
| parentRegistry | Pointer to the parent reader writer registry (the containing object that reads/writes this object). |
| virtual DtBallisticGun::~DtBallisticGun | ( | ) | [virtual] |
destructor
| DtBallisticGun::DtBallisticGun | ( | ) | [protected] |
default constructor; not implemented
| DtBallisticGun::DtBallisticGun | ( | const DtBallisticGun & | orig | ) | [protected] |
copy constructor; not implemented
| virtual bool DtBallisticGun::init | ( | ) | [virtual] |
Overridden to cache a pointer to the entity's radio in this class.
Reimplemented from DtActuatorComponent.
| virtual void DtBallisticGun::initPendingDetonations | ( | ) | [virtual] |
Called in the first tick.
Creates and schedules any pending detonations from detonation descriptor data in the process state repository. For those detonations whose target does not exist yet (e.g. target may be remote and not discovered yet), registers the objectAddedCb to provide an opportunity to create and schedule those pending detonations at a later time.
| virtual DtString DtBallisticGun::type | ( | ) | const [virtual] |
Returns a string identifies the class type of component.
Type values are defined in compTypes.h. DtSimComponent creation functions are registered with the DtSimComponentFactory using the type values as the key.
Reimplemented from DtSimComponent.
Reimplemented in DtBallisticGunJoy.
| virtual void DtBallisticGun::tick | ( | ) | [virtual] |
| virtual bool DtBallisticGun::checkHitProbability | ( | const DtEntityType & | type, |
| DtReal | range | ||
| ) | [virtual] |
Returns true if we hit the target, false otherwise.
Looks up a DtPrbRangeTableEntry based on entity type and range passed as arguments in the Hit Probability Table specified by the component descriptor describing this component. It uses the probability in the DtPrbRangeTableEntry indexed by the string returned by the probabilityString() function. This probability is then multiplied by the value from hitProbabilityModifier(). It then generates a random number between 0.0 and 1.0 using DtFRand(). If the value generated is less than or equal to the hit probability, true is returned. If the value generated is greater than the hit probability, false is returned.
| virtual double DtBallisticGun::hitProbabilityModifier | ( | const DtEntityType & | type, |
| DtReal | range | ||
| ) | [virtual] |
Override this function to dynamically change the probability of a hit based on factors such as current speed, weather conditions, etc.
By default, 1.0 is returned. Values less than one make a hit less likely, and values greater than one make a hit more likely.
| virtual DtFireInteraction* DtBallisticGun::createFireInteraction | ( | ) | [virtual] |
Allocates a DtFireInteraction and then uses the munition information specified on the munition and fuze ports, as well as the current target reported by the entity, to fill in the necessary fields.
It also calculates a muzzle velocity vector to store in the interaction, using myMuzzleSpeed and a unit vector pointing from the firing entity to the target. The range to the target, needed for the interaction is approximated using DtFastDist() and stored in the member variable myCurrentRange for use by createDetonationInteraction().
| virtual DtDetonationInteraction* DtBallisticGun::createDetonationInteraction | ( | DtTime & | detTime, |
| bool | assureMiss = false |
||
| ) | [virtual] |
Allocates a DtDetonationInteraction.
It calls checkHitProbability() to determine if the detonation will be a hit or a miss. If it is a hit, the interaction’s result field is set to DtDetResEntityImpact. An (approximate) impact point on the target entity is determined by shooting a ray from the center of the shooting entity to the center of the target entity. The point of intersection between this ray and the target entity’s bounding volume is then determined, and this is used as the detonation location. A round velocity vector is also calculated by using myMuzzleSpeed and a normalized version of the shooting vector. If the detonation is determined to be a miss, DtDetResGroundImpact is used for the detonation result, and a ground location is randomly selected from within a 2 ½ meter ring outside the radius of the target’s bounding volume as the detonation point. The round velocity vector is calculated by finding the unit vector from the center of the shooting entity to the impact point and scaling by myMuzzleSpeed. An approximate time to detonation is determined using the approximate distance to the target, stored by createFireInteraction() in myCurrentRange, divided by myMuzzleSpeed. This speed and the DtDetonationInteraction created are returned. If assureMiss is True, the hitProbability is skipped, and a miss is garunteed.
| virtual void DtBallisticGun::scheduleDetonation | ( | DtDetonationInteraction * | detInter, |
| DtTime | detTime | ||
| ) | [virtual] |
Schedules the sending of the DtDetonationInteraction passed as the first argument at a point in the future specified by the second argument, using the DtScheduler facility (which is accessed through the DtSimManager).
A DtDetonationTimerData object is allocated, which holds a pointer to the DtDetonationInteraction and a pointer to the DtSimManager. A DtTimer is then created that is set for the desired time and that is given the DtBallisticGun::detonationCallback() as the callback function for when the timer fires, and DtDetonationTimerData object as the user data that will be accessible to the callback. The timer is placed on the scheduler with a call to DtScheduler::addTimer(), which will assume responsibility for firing the DtTimer at the specified time. The DtTimer is also placed on a local timer list myTimerList, so that it can be deleted at a later time.
| virtual DtString DtBallisticGun::probabilityString | ( | ) | const [virtual] |
| virtual DtVector DtBallisticGun::calculateMuzzlePosition | ( | ) | const [virtual] |
Finds the correct muzzle placement for the gun.
| virtual DtDetonationInteraction* DtBallisticGun::createDetonationInteraction | ( | const DtDetonationDescriptor & | desc, |
| DtTime & | detTime | ||
| ) | [virtual] |
Creates a new DtDetonationInteraction, given a DtDetonationDescriptor.
Fills out new new interaction with data from the descriptor and returns the detonation time (time in seconds relative to current sim time). The resulting DtDetonationInteraction and DtTime can be directly passed into scheduleDetonation.
| virtual DtDetonationDescriptor* DtBallisticGun::createDetonationDescriptor | ( | DtDetonationInteraction * | detInter, |
| DtTime | simTime | ||
| ) | [virtual] |
Creates and fills out a new DtDetonationDescriptor, given a DtDetonationInteraction and a time (simulation time to fire, in seconds).
| static void DtBallisticGun::detonationCallback | ( | DtTimer * | timer | ) | [static] |
Casts the user data portion of the DtTimer passed to it to a DtDetonationTimerData object.
It then uses the pointer to the Simulation Manager provided in the DtDetonationTimerData to get a pointer to the DtExerciseConn, and sends the DtDetonationInteraction which is also in the DtDetonationTimerData object via the exercise connection. The timer is removed from the scheduler, and the DtDetonationTimerData and DtDetonationInteraction objects are deleted.
Reimplemented in DtBallisticGunJoy.
| static DtSimComponent* DtBallisticGun::creator | ( | const DtString & | name, |
| DtVrfObject * | owner, | ||
| DtSimManager * | simManager, | ||
| DtComponentDescriptor * | desc = 0, |
||
| DtReaderWriterRegistry * | parentRegistry = 0 |
||
| ) | [static] |
(const DtString&,DtVrfObject*,DtSimManager*,
| name | Reader writer name of this component. |
| owner | The DtVrfObject that owns this component |
| simManager | The simulation manager (provides access to terrain, message interface, simulation clock). |
| desc | The component descriptor used to initialize this component. |
| parentRegistry | Pointer to the parent reader writer registry (the containing object that reads/writes this object). |
Reimplemented in DtBallisticGunJoy.
| static void DtBallisticGun::objectAddedCb | ( | DtVrfObject * | vrfObject, |
| void * | usr | ||
| ) | [static] |
Calls processObjectAdded().
| virtual bool DtBallisticGun::createPortGroups | ( | ) | [protected, virtual] |
Overridden to create local port groups.
Reimplemented from DtSimComponent.
| virtual bool DtBallisticGun::createPorts | ( | ) | [protected, virtual] |
Overridden to create local ports.
Reimplemented from DtSimComponent.
Reimplemented in DtBallisticGunJoy.
| virtual bool DtBallisticGun::createPSR | ( | ) | [protected, virtual] |
Creates myProcessState data member, and adds it to our process state repository manager.
Passes in the name and type specified in the component descriptor (if they exist) to the DtVrfProcessStateRepository::createRepository factory method. If name and/or type is not specified, uses the appropriate default strings defined in procSRTypes.h.
| virtual void DtBallisticGun::processObjectAdded | ( | DtVrfObject * | vrfObject | ) | [protected, virtual] |
Checks pending detonation list (in the process state repository) for target with same name as new object.
If one exists, sets the target global id in the pending object item (a DtDetonationDescriptor), and then schedules the detonation, given the data in the descriptor.
| virtual void DtBallisticGun::addRangeItems | ( | ) | [protected, virtual] |
Adds all items that have a range to the object state repository.
| const DtBallisticGun& DtBallisticGun::operator= | ( | const DtBallisticGun & | orig | ) | [protected] |
assignment operator; not implemented
DtEntityIdentifier DtBallisticGun::myObjectId [protected] |
DtReal DtBallisticGun::myMuzzleSpeed [protected] |
DtVector DtBallisticGun::myMuzzleOffset [protected] |
DtVrfObject* DtBallisticGun::myCurrentTarget [protected] |
These are set by createFireInteraction and used by createDetonationInteraction.
DtEventId DtBallisticGun::myCurrentEventId [protected] |
DtReal DtBallisticGun::myCurrentRange [protected] |
DtList DtBallisticGun::myTimerList [protected] |
DtArtPartType DtBallisticGun::myGunArtPart [protected] |
DtVrfBalGunPSR* DtBallisticGun::myProcessState [protected] |
Container for state data associated with this component.
This state is saved and restored as part of a scenario (or checkpoint).
bool DtBallisticGun::myFirstTick [protected] |
DtInputPortGroup* DtBallisticGun::myBalGunControlPortGroup [protected] |
Input Port Group Name: gun-control
Input Port Group Description:
DtBooleanInputPort* DtBallisticGun::myTriggerPort [protected] |
Input Port Name: trigger
Input Port Description: Edge-triggered input which fires a round whenever a new True arrives on the port.
Input Port Range:
Input Port Default Value:
Input Group Parent: gun-control
DtIntegerInputPort* DtBallisticGun::myQuantityInputPort [protected] |
Input Port Name: quantity
Input Port Description: Indicates the number of rounds to be fired with a single trigger pull.
Changes the quantity field in the fire/detonate interactions/PDUs generated by this gun. If not connected, a value of 1 is used.
Input Port Range: 1+
Input Port Default Value: 1
Input Group Parent: gun-control
DtBooleanInputPort* DtBallisticGun::myLoadedPort [protected] |
Input Port Name: loaded
Input Port Description: Must be True for gun to fire.
Input Port Range:
Input Port Default Value:
Input Group Parent: gun-control
DtIntegerInputPort* DtBallisticGun::myLosPort [protected] |
Input Port Name: line-of-sight
Input Port Description: Indicates the result of a line of sight calculation to the current target.
This gun is only capable of hitting things with a Clear line of sight. If Unknown, the gun will calculate the los. Input Port Range: 0 = Unkown, 1 = Blocked, 2 = Clear
Input Port Default Value:
Input Group Parent: gun-control