VR-Engage  2.2
Loading...
Searching...
No Matches
topAndDirectAttackMissileController.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies, Inc.
3** All rights reserved.
4*******************************************************************************/
5
6//! \file topAndDirectAttackMissileController.h
7//! \ingroup vreVrfmodel
8//! \brief Controller for modeling FGM-148 Javelin missile flight paths
9//!
10//! This file defines the DtTopAndDirectAttackMissileController class which models
11//! the movement of a Javelin missile along a path to its target. It handles both
12//! top-attack and direct-attack flight modes, managing the different phases of
13//! flight for each mode.
14//!
15// The Javelin missile has two modes of flight: top-attack and direct-attack.
16//
17// In top-attack mode, the flight has three phases:
18// 1. Climb-out - missile flights out at a steep angle.
19// 2. Altitude-hold - missile flies toward the target at maximum
20// altitude.
21// 3. Terminal - missile flies directly toward a target. The terminal angle is
22// the angle at which the missile will hit the target (inclination angle
23// from the target to the missile).
24// Note that if the target is close enough, the missile may not reach the altitude
25// hold phase and proceed directly to terminal phase.
26//
27// In direct-attack mode, the flight has two phases:
28// 1. Climb-out - missile flights out at a steep angle.
29// 3. Terminal - missile flies directly toward a target. The terminal angle is
30// the angle at which the missile will hit the target (inclination angle
31// from the target to the missile).
32
33#pragma once
34
35
36#include <vreVrfmodel/export.h>
39
40#include <vrfmodel/missileMoveToControllerComponent.h>
41
42#include <vlutil/vlString.h>
43#include <matrix/vlVector.h>
44
45class DtString;
46class DtSimulationServices;
47class DtConstrainedAnalogPort;
48class boolPort;
49class DtSimMessage;
50
51
52//! \brief Controller for missile flight paths with different attack modes
53//!
54//! Manages missile movement with specialized flight paths based on the selected
55//! attack mode (top-attack or direct-attack).
56namespace makVre
57{
58//! \brief Type identifier for the top and direct attack missile controller component
59const char DtTopAndDirectAttackMissileControllerType[] = "top-and-direct-attack-missile-controller";
60
63
64//! \brief Controller for FGM-148 Javelin missile flight paths
65//!
66//! DtTopAndDirectAttackMissileController models the movement of a Javelin missile
67//! along a path to its target, supporting two different attack modes:
68//! - Top-attack mode: Missile climbs to maximum altitude, then descends on target
69//! - Direct-attack mode: Missile follows a more direct path to the target
70//!
71//! Each mode has different flight phases, and the controller manages transitions
72//! between phases based on altitude, distance to target, and attack angles.
74 : public DtVreSimComponent<DtMissileMoveToControllerComponent>
75{
76public:
77 //! \brief Constructor
78 //! \param name The name of this component
79 //! \param owner The local object that owns this component
80 //! \param simManager The simulation services manager
81 //! \param desc Component descriptor with configuration parameters
82 //! \param parentRegistry Optional parent registry for reader/writer functionality
83 //!
84 //! Creates a new top and direct attack missile controller component with the specified parameters.
85 DtTopAndDirectAttackMissileController(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
86 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
87
88 //! \brief Virtual destructor
89 //!
90 //! Cleans up resources used by the top and direct attack missile controller component.
92
93 //! \brief Gets the type identifier for this component
94 //! \return String identifying the component type (DtTopAndDirectAttackMissileControllerType)
95 //!
96 //! Implements the DtSimComponent::type() method to return the
97 //! type identifier for this component.
98 virtual const char* type() const override;
99
100 //! \brief Performs initialization before the first simulation tick
101 //!
102 //! Gets the missile attack mode (top-attack or direct-attack) from the entity's
103 //! extended data and sets it in the process state repository. Also caches the
104 //! appropriate flight parameters based on the selected mode.
105 virtual void preFirstTickInit() override;
106
107 //! \brief Sets the target entity that the missile should fly to
108 //! \param entity UUID of the target entity
109 //!
110 //! Sets the target entity the missile should fly to. The flight path will
111 //! depend on the current attack mode (top-attack or direct-attack). The
112 //! trajectory is not direct but follows the phases defined for the selected mode.
113 virtual void setTargetEntity(const DtUUID& entity) override;
114
115 //! \brief Gets the currently set target entity
116 //! \return Reference to the current target entity
117 //!
118 //! Returns a reference to the entity currently set as the missile's target.
119 virtual DtSimObjectReference targetEntity() const override;
120
121 //! \brief Calculates steering parameters to guide the missile to target
122 //! \param relativeVelocity Relative velocity vector between missile and target
123 //! \param localPosition Current position of the missile
124 //! \param targetVelocity Velocity vector of the target
125 //! \param targetPoint Target position vector
126 //! \param maneuverAccelXOut Output parameter for X-axis maneuver acceleration
127 //! \param maneuverAccelYOut Output parameter for Y-axis maneuver acceleration
128 //! \param maneuverAccelZOut Output parameter for Z-axis maneuver acceleration
129 //!
130 //! Overrides the base class implementation to calculate steering parameters
131 //! for guiding the missile along its multi-phase flight path to the target.
132 //! Updates the output acceleration parameters to achieve the desired trajectory.
133 virtual void calculateSteering(const DtVector& relativeVelocity, const DtVector& localPosition,
134 const DtVector& targetVelocity, const DtVector& targetPoint, double& maneuverAccelXOut, double& maneuverAccelYOut,
135 double& maneuverAccelZOut) override;
136
137 //! \brief Static callback function for target point messages
138 //! \param msg The simulation message containing the target point information
139 //! \param usr User data pointer (contains the controller instance)
140 //!
141 //! Static function registered as a callback to handle target point messages.
142 //! Instances of this component register this callback with their own 'this'
143 //! pointer as user data with the message executive to receive notification
144 //! of move-to tasks.
145 static void targetPointCallback(DtSimMessage* msg, void* usr);
146
147 //! \brief Processes a target point task message
148 //! \param msg The simulation message containing the target point task
149 //!
150 //! Extracts the target entity information from the DtTargetPointTask message
151 //! and calls setTargetEntity() with the UUID of the specified target entity.
152 virtual void processTargetPointTask(DtSimMessage* msg) override;
153
154 //! \brief Factory method to create a new instance of this component
155 //! \param name The name for the new component
156 //! \param owner The local object that will own this component
157 //! \param simManager The simulation services manager
158 //! \param desc Optional component descriptor
159 //! \param parentRegistry Optional parent registry for reader/writer functionality
160 //! \return Pointer to the newly created component
161 //!
162 //! Static factory method used by the component creation system to instantiate
163 //! new instances of this component type.
164 static DtSimComponent* creator(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
165 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
166
167protected:
168 //! \brief Default constructor (protected, not for direct use)
169 //!
170 //! This constructor is protected and not meant to be called directly.
171 //! It exists because the compiler would otherwise generate an unprotected one.
173
174 //! \brief Copy constructor (protected, performs shallow copy)
175 //! \param orig The original object to copy from
176 //!
177 //! Performs a shallow copy operation that does not copy the ports.
178 //! This constructor is protected and not meant for general use.
180
181 //! \brief Assignment operator (protected, performs shallow copy)
182 //! \param orig The original object to assign from
183 //! \return Reference to this object
184 //!
185 //! Performs a shallow assignment operation similar to the copy constructor.
186 //! This operator is protected and not meant for general use.
188
189 //! \brief Registers message callbacks for handling task messages
190 //!
191 //! Registers the callback targetPointCallback() for handling
192 //! DtTargetPointTask messages sent to this missile controller.
193 virtual void registerTaskMsgCallbacks() override;
194
195 //! \brief Sets up the current control point for missile guidance
196 //! \return True if a valid control point was established, false otherwise
197 //!
198 //! Determines the appropriate working target point based on the current
199 //! flight phase (climb-out, altitude-hold, or terminal) and then calls
200 //! setTargetPoint() to update the missile's guidance system.
201 virtual bool setupControlPoint() override;
202
203 //! \brief Calculates the endpoint for the climb-out flight phase
204 //! \return Vector position for the end of the climb-out phase
205 //!
206 //! Determines the position that marks the end of the climb-out phase
207 //! based on the current missile position, target position, and configured
208 //! climb-out angle.
209 virtual DtVector calculateClimbOutPoint();
210
211 //! \brief Checks if the missile has reached its climb-out altitude
212 //! \return True if the missile has reached or exceeded the climb-out altitude
213 //!
214 //! Compares the missile's current altitude with the configured climb-out
215 //! altitude to determine if the missile should transition to the next flight phase.
217
218 //! \brief Calculates the control point for the altitude-hold flight phase
219 //! \return Vector position for the altitude-hold phase
220 //!
221 //! Returns a position directly above the target at the maximum altitude
222 //! configured for the missile. This point is used for guidance during the
223 //! altitude-hold phase of top-attack mode.
224 virtual DtVector calculateAltitudeHoldPoint();
225
226 //! \brief Checks if the missile has reached the terminal angle to target
227 //! \return True if the missile has reached or exceeded the terminal angle
228 //!
229 //! Calculates the inclination angle from the target to the missile and
230 //! determines if it has reached the configured terminal angle, indicating
231 //! that the missile should transition to the terminal phase of flight.
233
234 //! \brief Calculates the endpoint for the terminal flight phase
235 //! \return Vector position for the terminal phase targeting
236 //!
237 //! Determines the position of the target entity, accounting for any
238 //! movement during flight. This is the final aim point for the missile
239 //! during the terminal phase of flight.
240 virtual DtVector calculateTerminalPoint();
241
242 //! Moves the missile's target waypoint based on the VRE message.
243 //! Waypoint will have its position updated or be attached to a target entity.
244 //! Processes UpdateMissileTargetMessage events.
245 //! This message can either set the target to a new location or an entity.
247
248protected:
249 //! \brief Retrieves and caches the missile flight process state repository
250 //!
251 //! Looks up the missile flight process state repository and caches it for
252 //! efficient access during simulation updates. The PSR contains the state
253 //! information for the missile's flight phases and attack mode.
254 virtual void lookupAndCacheProcessSR() override;
255
256 //! This callback is necessary to make sure the handleUpdateMissileTarget callback
257 //! is registered in the main thread. It needs to be registered in that thread because
258 //! the sim's component worker threads don't tick the DtVreMessageManager.
259 static void objectAddedCallback(const DtLocalObject* simObject, void* usr);
260 virtual void processObjectAdded(const DtLocalObject* simObject);
261
262protected:
263 //! \brief Reference to the current target entity
264 //!
265 //! Reference to the current target entity that the missile is tracking.
266 //! This is updated each frame by the setupControlPoint() method.
267 DtSimObjectReference myTargetPointer;
268
269 //! \brief Flag to prevent repeated warning messages
270 //!
271 //! When true, prevents the component from repeatedly sending
272 //! 'failed to find target' warnings to the log. Ensures that
273 //! warning messages are only sent once per missile instance.
275
276 //! \brief Cached pointer to the missile flight process state repository
277 //!
278 //! Cached pointer to the derived type of process state repository used
279 //! to store missile flight state information. This avoids repeated lookups
280 //! and type casting during the missile's flight.
282
283 //! \brief Cached pointer to the component descriptor
284 //!
285 //! Cached pointer to the derived type of component descriptor that contains
286 //! configuration parameters specific to this missile controller. This allows
287 //! efficient access to configuration settings without repeated type casting.
289
290 //! \brief Cached climb-out angle for the current attack mode
291 //!
292 //! The angle used during the climb-out phase of flight. This value is set
293 //! in preFirstTickInit() based on the attack mode and remains constant
294 //! for the lifetime of the missile.
296
297 //! \brief Cached terminal angle for the current attack mode
298 //!
299 //! The angle used to determine transition to the terminal phase of flight.
300 //! This value is set in preFirstTickInit() based on the attack mode and
301 //! remains constant for the lifetime of the missile.
303
304 //! \brief Cached maximum altitude for the current attack mode
305 //!
306 //! The maximum altitude the missile should reach during flight. This value
307 //! is set in preFirstTickInit() based on the attack mode and remains
308 //! constant for the lifetime of the missile.
310
312};
313} // namespace makVre
Top and direct attack missile controller descriptor for VREngage.
Definition topAndDirectAttackMissileControllerDescriptor.h:53
double myMaxAltitude
Cached maximum altitude for the current attack mode.
Definition topAndDirectAttackMissileController.h:309
virtual void processTargetPointTask(DtSimMessage *msg) override
Processes a target point task message.
virtual DtVector calculateClimbOutPoint()
Calculates the endpoint for the climb-out flight phase.
virtual bool setupControlPoint() override
Sets up the current control point for missile guidance.
static void objectAddedCallback(const DtLocalObject *simObject, void *usr)
This callback is necessary to make sure the handleUpdateMissileTarget callback is registered in the m...
virtual void lookupAndCacheProcessSR() override
Retrieves and caches the missile flight process state repository.
virtual DtSimObjectReference targetEntity() const override
Gets the currently set target entity.
double myTerminalAngle
Cached terminal angle for the current attack mode.
Definition topAndDirectAttackMissileController.h:302
virtual void setTargetEntity(const DtUUID &entity) override
Sets the target entity that the missile should fly to.
virtual void calculateSteering(const DtVector &relativeVelocity, const DtVector &localPosition, const DtVector &targetVelocity, const DtVector &targetPoint, double &maneuverAccelXOut, double &maneuverAccelYOut, double &maneuverAccelZOut) override
Calculates steering parameters to guide the missile to target.
virtual DtVector calculateAltitudeHoldPoint()
Calculates the control point for the altitude-hold flight phase.
bool myCallbackAdded
Definition topAndDirectAttackMissileController.h:311
bool myLookupWarningSent
Flag to prevent repeated warning messages.
Definition topAndDirectAttackMissileController.h:274
const DtTopAndDirectAttackMissileController & operator=(const DtTopAndDirectAttackMissileController &orig)
Assignment operator (protected, performs shallow copy)
virtual bool reachedTerminalAngleToTarget()
Checks if the missile has reached the terminal angle to target.
DtTopAndDirectAttackMissileController(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Constructor.
static DtSimComponent * creator(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Factory method to create a new instance of this component.
virtual bool reachedClimbOutAltitude()
Checks if the missile has reached its climb-out altitude.
DtTopAndDirectMissileFlightPSR * myVreMissileFlightPSR
Cached pointer to the missile flight process state repository.
Definition topAndDirectAttackMissileController.h:281
virtual void preFirstTickInit() override
Performs initialization before the first simulation tick.
virtual void registerTaskMsgCallbacks() override
Registers message callbacks for handling task messages.
virtual DtVector calculateTerminalPoint()
Calculates the endpoint for the terminal flight phase.
virtual const char * type() const override
Gets the type identifier for this component.
virtual void processObjectAdded(const DtLocalObject *simObject)
static void targetPointCallback(DtSimMessage *msg, void *usr)
Static callback function for target point messages.
virtual ~DtTopAndDirectAttackMissileController() override
Virtual destructor.
DtSimObjectReference myTargetPointer
Reference to the current target entity.
Definition topAndDirectAttackMissileController.h:267
DtTopAndDirectAttackMissileController(const DtTopAndDirectAttackMissileController &orig)
Copy constructor (protected, performs shallow copy)
double myClimbOutAngle
Cached climb-out angle for the current attack mode.
Definition topAndDirectAttackMissileController.h:295
virtual makVre::DtVreMessageResult handleUpdateMissileTarget(makVre::DtVreMessage *msg)
Moves the missile's target waypoint based on the VRE message. Waypoint will have its position updated...
DtTopAndDirectAttackMissileControllerDescriptor * myTopAndDirectAttackMissileControllerDescriptor
Cached pointer to the component descriptor.
Definition topAndDirectAttackMissileController.h:288
DtTopAndDirectAttackMissileController()
Default constructor (protected, not for direct use)
class DtTopAndDirectMissileFlightPSR:
Definition topAndDirectMissileFlightPSR.h:33
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
DtVreSimComponent(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Definition vreSimComponent.h:54
Defines export macros for the vreVrfmodel library.
#define VREVRFMODEL_DLL
Definition export.h:22
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
const char DtTopAndDirectAttackMissileControllerType[]
Type identifier for the top and direct attack missile controller component.
Definition topAndDirectAttackMissileController.h:59
Defines the central message manager for the VREngage messaging system.
Base template class for VR-Engage simulation components.