VR-Engage  2.2
Loading...
Searching...
No Matches
DtCustomProjectile Class Reference

Detailed Description

PATTERN: Extending VR-Forces Projectile Classes To create custom munition types in VR-Forces:

  1. Derive from makVre::DtProjectile (or DtBallistic, DtGuided for specific types)
  2. Add any additional state needed for your behavior (for example, accumulated time in flight)
  3. Override update() to implement custom physics or behavior
  4. Implement clone(), operator==, type(), and static creator() methods
  5. Register with projectile factory in plugin initialization

This Example: Adds a time-in-flight value that accumulates the total flight time at runtime. The value is not configurable in data files and is not serialized; it exists only while the projectile is active in the simulation. This simple example can be extended with:

  • Custom guidance algorithms (target tracking, waypoint following)
  • Environmental effects (wind, gravity variations)
  • Special detonation logic (proximity fuze, timed fuze)
  • Visual effects (smoke trails, exhaust plumes)
  • Performance characteristics (fuel consumption, thrust curves)

REUSABLE: This class structure is directly reusable for any custom projectile type. Replace myTimeInFlight with your custom parameters and update() logic with your custom behavior.

#include <customProjectile.h>

Inheritance diagram for DtCustomProjectile:
[legend]

Public Member Functions

 DtCustomProjectile (const DtString &name, DtReaderWriterRegistry *const parentRegistry=nullptr)
 
 DtCustomProjectile (const DtSymbolString &name, DtReaderWriterRegistry *const parentRegistry=nullptr)
 
 DtCustomProjectile (const DtCustomProjectile &orig, DtReaderWriterRegistry *const parentRegistry=nullptr)
 
virtual ~DtCustomProjectile () override
 
DtCustomProjectileoperator= (const DtCustomProjectile &orig)
 
virtual makVre::DtProjectileclone () const override
 
bool operator== (const DtCustomProjectile &) const
 
bool operator!= (const DtCustomProjectile &rhs) const
 
virtual DtString type () const override
 
virtual makVre::DtProjectileDetonationResult update (double deltaTime) override
 
- Public Member Functions inherited from makVre::DtProjectile
 DtProjectile (const DtString &name, DtReaderWriterRegistry *const parentRegistry=NULL)
 
 DtProjectile (const DtSymbolString &name, DtReaderWriterRegistry *const parentRegistry=NULL)
 
 DtProjectile (const DtProjectile &orig, DtReaderWriterRegistry *const parentRegistry=NULL)
 
virtual ~DtProjectile () override
 
DtProjectileoperator= (const DtProjectile &orig)
 
bool operator== (const DtProjectile &) const
 
bool operator!= (const DtProjectile &rhs)
 
virtual void setMunitionType (const DtEntityType &munitionType)
 
virtual void setCrossSection (double crossSection)
 
virtual void setDragCoefficient (double dragCoefficient)
 
virtual void setMass (double mass)
 
virtual void setMaxRange (double maxRange)
 
virtual void setPosition (DtVector position)
 
virtual void setVelocity (DtVector velocity)
 
virtual void setDistanceTraveled (double distanceTraveled)
 
virtual void setFiringEntity (DtSimObject *firingEntity)
 
virtual void setPhysicalWorld (DtPhysicalWorld *physicalWorld)
 
virtual const DtEntityType & munitionType ()
 
virtual DtVector velocity ()
 
virtual void putData (std::string &fp, int indentLevel=0) override
 
virtual DtlObjPtr getData (DtlObjPtr args, const DtReaderWriter::SearchPaths &searchPaths, const DtVariableBindingsList &variableBindings) override
 

Static Public Member Functions

static makVre::DtProjectilecreator (const DtString &name, DtReaderWriterRegistry *const parentRegistry=nullptr)
 
- Static Public Member Functions inherited from makVre::DtProjectile
static void addProjectileCreatorFcn (const std::string &type, makVre::DtProjectileCreatorFcn fcn)
 
static DtProjectilecreateProjectile (DtlObjPtr mtlStream)
 
static DtProjectilecreateProjectile (const char *type, const char *pName, DtReaderWriterRegistry *const parentRegistry=NULL)
 
static DtProjectilecreator (const DtString &name, DtReaderWriterRegistry *const parentRegistry=NULL)
 
static DtProjectileFactoryfactory ()
 
static void setFactory (DtProjectileFactory *factory)
 

Protected Member Functions

 DtCustomProjectile ()
 
- Protected Member Functions inherited from makVre::DtProjectile
 DtProjectile ()
 
virtual ProjectileUpdateResult updateProjectilePosition (double deltaTime)
 
virtual DtProjectileDetonationResult checkForProjectileCollision (const ProjectileUpdateResult &projectUpdateResult)
 

Protected Attributes

double myTimeInFlight
 
- Protected Attributes inherited from makVre::DtProjectile
DtRwEntityType myMunitionType
 
DtRwReal myCrossSection
 
DtRwReal myDragCoefficient
 
DtRwReal myMass
 
DtRwReal myMaxRange
 
DtRwVector myPosition
 
DtRwVector myVelocity
 
DtRwReal myDistanceTraveled
 
DtSimObject * myFiringEntity
 
DtPhysicalWorld * myPhysicalWorld
 

Additional Inherited Members

- Static Protected Attributes inherited from makVre::DtProjectile
static DtProjectileFactorytheFactory
 

Constructor & Destructor Documentation

◆ DtCustomProjectile() [1/4]

DtCustomProjectile::DtCustomProjectile ( const DtString & name,
DtReaderWriterRegistry *const parentRegistry = nullptr )

Construct projectile with string name.

PATTERN: Projectile Construction Projectiles are constructed with a name (used for identification and debugging) and an optional parent registry (for hierarchical parameter organization used by the base class).

The constructor must:

  1. Initialize the base class (DtProjectile)
  2. Initialize any custom state
Parameters
nameUnique identifier for this projectile instance
parentRegistryOptional parent registry for hierarchical organization

Referenced by DtCustomProjectile(), operator!=(), operator=(), and operator==().

◆ DtCustomProjectile() [2/4]

DtCustomProjectile::DtCustomProjectile ( const DtSymbolString & name,
DtReaderWriterRegistry *const parentRegistry = nullptr )

Construct projectile with symbol string name.

Parameters
nameSymbol string identifier for this projectile instance
parentRegistryOptional parent registry for hierarchical organization

◆ DtCustomProjectile() [3/4]

DtCustomProjectile::DtCustomProjectile ( const DtCustomProjectile & orig,
DtReaderWriterRegistry *const parentRegistry = nullptr )

Copy constructor for projectile cloning.

PATTERN: Projectile Copying Projectiles must be copyable for cloning (for example, when creating multiple rounds from a template). The copy constructor must:

  1. Copy base class state
  2. Copy all custom state
Parameters
origSource projectile to copy
parentRegistryOptional parent registry for the copy

References DtCustomProjectile().

◆ ~DtCustomProjectile()

virtual DtCustomProjectile::~DtCustomProjectile ( )
inlineoverridevirtual

Destructor - base class handles cleanup.

◆ DtCustomProjectile() [4/4]

DtCustomProjectile::DtCustomProjectile ( )
protected

Default constructor - not implemented (projectiles require names)

Member Function Documentation

◆ operator=()

DtCustomProjectile & DtCustomProjectile::operator= ( const DtCustomProjectile & orig)

Assignment operator for projectile state copying.

Must copy both base class state and all custom parameters.

Parameters
origSource projectile to copy from
Returns
Reference to this projectile for assignment chaining

References DtCustomProjectile().

◆ clone()

virtual makVre::DtProjectile * DtCustomProjectile::clone ( ) const
overridevirtual

Create a deep copy of this projectile.

Required by VR-Forces framework for projectile instantiation from templates. When multiple rounds of the same munition type are fired, the framework clones a template projectile rather than re-reading configuration files.

Returns
New projectile instance with copied state

Reimplemented from makVre::DtProjectile.

◆ operator==()

bool DtCustomProjectile::operator== ( const DtCustomProjectile & ) const

Equality comparison for projectile state.

Parameters
rhsProjectile to compare against
Returns
true if all parameters match, false otherwise

References DtCustomProjectile().

◆ operator!=()

bool DtCustomProjectile::operator!= ( const DtCustomProjectile & rhs) const
inline

Inequality comparison for projectile state.

Parameters
rhsProjectile to compare against
Returns
true if any parameters differ, false if all match

References DtCustomProjectile().

◆ type()

virtual DtString DtCustomProjectile::type ( ) const
overridevirtual

Return the class type identifier string.

PATTERN: Projectile Type Identification The type() method returns a unique string identifying this projectile class. This string is used by:

  • Factory system to create correct class instances
  • MTL file serialization to identify projectile class on load
  • Runtime type identification (alternative to dynamic_cast)

The type string must match the string used in factory registration.

Returns
Type identifier string (DtCustomProjectileType constant)

Reimplemented from makVre::DtProjectile.

◆ update()

virtual makVre::DtProjectileDetonationResult DtCustomProjectile::update ( double deltaTime)
overridevirtual

Update projectile state for one simulation frame.

PATTERN: Custom Projectile Update Logic The update() method is called once per simulation frame to advance projectile physics and behavior. Custom projectiles override this to implement:

  • Custom guidance algorithms (updating velocity/orientation)
  • Time-based effects (fuel depletion, stage separation)
  • Environmental interactions (wind drift, drag calculations)
  • Custom detonation conditions (proximity detection, time fuzes)

This Example: Increments the time-in-flight parameter by deltaTime, then calls the base class update() to perform standard projectile physics (position integration, collision detection, detonation logic).

REUSABLE: This override pattern applies to any custom update logic. Always call the base class update() unless completely replacing default physics.

Parameters
deltaTimeTime elapsed since last update in seconds
Returns
Detonation result indicating if projectile should be removed

Reimplemented from makVre::DtProjectile.

◆ creator()

static makVre::DtProjectile * DtCustomProjectile::creator ( const DtString & name,
DtReaderWriterRegistry *const parentRegistry = nullptr )
static

Static factory creator method.

PATTERN: Projectile Factory Pattern VR-Forces uses factory methods to instantiate projectiles by type name. The creator() method must be static and return a new instance of this class.

This method is registered with the projectile factory during plugin initialization: DtProjectileFactory::instance().registerProjectile( DtCustomProjectileType, &DtCustomProjectile::creator);

When MTL files reference this projectile type, the factory uses this creator to instantiate objects.

REUSABLE: This exact signature is required for all custom projectiles.

Parameters
nameName for the new projectile instance
parentRegistryOptional parent registry for the new instance
Returns
Newly created projectile instance

Member Data Documentation

◆ myTimeInFlight

double DtCustomProjectile::myTimeInFlight
protected

Custom time-in-flight parameter.

The time-in-flight value is internal simulation state. It is not configured from data files and is not serialized; it is reset to zero when the projectile is constructed and accumulates while the projectile is active.


The documentation for this class was generated from the following file: