VR-Engage  2.2
Loading...
Searching...
No Matches
humanGunJoyActuator.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file humanGunJoyActuator.h
7//! \ingroup vreVrfmodel
8//! \brief Actuator that models firing of handheld weapons with joystick control
9//!
10//! This file defines the DtHumanGunJoyActuator class which extends the ballistic gun
11//! model with specialized behavior for human-held weapons. It adds the ability to
12//! aim the gun from side to side without requiring a separate turret component.
13#pragma once
14
15#include "vreVrfmodel/export.h"
17
19
21
22#include <vrfobjcore/humanLocalObjectFacade.h>
23
24class DtAnalogInputPort;
25
26namespace makVrfEvents
27{
28class DtFireEvent;
29class DtDetonationEvent;
30} // namespace makVrfEvents
31
32namespace makVre
33{
36
37//! \brief Type identifier for the human gun joystick actuator component
38const char DtHumanGunJoyActuatorType[] = "human-gun-Joystick-actuator";
39
40//! \brief Actuator for human-held weapons with joystick control
41//!
42//! DtHumanGunJoyActuator provides a model of a handheld gun/weapon that can
43//! be controlled via joystick inputs.
44//!
45//! Component Type: human-gun-Joystick-actuator
46//!
47//! Descriptor Class: DtHumanGunActuatorDescriptor, Type: vre-human-gun-actuator-descriptor
48
50{
51public:
52 //! \brief Constructor
53 //! \param name The name of this component
54 //! \param owner The local object that owns this component
55 //! \param simManager The simulation services manager
56 //! \param desc Component descriptor with configuration parameters
57 //! \param parentRegistry Optional parent registry for reader/writer functionality
58 //!
59 //! Creates a new human gun joystick actuator component with the specified parameters.
60 DtHumanGunJoyActuator(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
61 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
62
63
64 //! \brief Virtual destructor
65 //!
66 //! Cleans up resources used by the human gun joystick actuator component.
67 virtual ~DtHumanGunJoyActuator() override;
68
69 //! \brief Initializes the component
70 //! \return True if initialization is successful, false otherwise
71 //!
72 //! Performs component initialization, setting up message handlers for fire input
73 //! and initializing internal state for weapon operation.
74 virtual bool init() override;
75
76 //! \brief Gets the type identifier for this component
77 //! \return String identifying the component type (DtHumanGunJoyActuatorType)
78 //!
79 //! Implements the DtSimComponent::type() method to return the
80 //! type identifier for this component.
81 virtual const char* type() const override;
82
83 //! \brief Updates the component state each simulation frame
84 //!
85 //! Checks for transitions to/from player control. Upon taking control as a player,
86 //! disables thresholding of ammo counts (clip state properties) to ensure the most
87 //! accurate information possible for display in the HUD. Upon leaving player control,
88 //! restores thresholding of ammo counts to reduce network load for CGF entities that
89 //! don't require the same degree of precision.
90 virtual void tick() override;
91
92public:
93 //! \brief Factory method to create a new instance of this component
94 //! \param name The name for the new component
95 //! \param owner The local object that will own this component
96 //! \param simManager The simulation services manager
97 //! \param desc Optional component descriptor
98 //! \param parentRegistry Optional parent registry for reader/writer functionality
99 //! \return Pointer to the newly created component
100 //!
101 //! Static factory method used by the component creation system to instantiate
102 //! new instances of this component type.
103 static DtSimComponent* creator(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
104 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
105
106protected:
107 //! \brief Creates the process state repository for this component
108 //! \return True if PSR was created successfully, false otherwise
109 //!
110 //! Creates the process state repository for this component and adds it to the
111 //! process state repository manager. Uses the name and type specified in the
112 //! component descriptor if they exist, otherwise uses appropriate default
113 //! strings defined in procSRTypes.h.
114 virtual bool createPSR() override;
115
116 //! \brief Processes fire input messages
117 //! \param msg Pointer to the fire input message
118 //! \return Message processing result
119 //!
120 //! Handles FireInputMessage sent from role logic (human, tank, etc.) and updates
121 //! myTriggerMunition, myTriggerWorldPosition, and myTriggerWorldOrientation parameters
122 //! used for rapid fire in the tick function.
124
125 //! \brief Aims the gun in elevation
126 //! \return True if aiming in elevation is complete, false otherwise
127 //!
128 //! Adjusts the gun's elevation based on input port values or pre-calculated values.
129 virtual bool aimGunElevation();
130
131 //! \brief Creates input and output ports for this component
132 //! \return True if ports were created successfully, false otherwise
133 //!
134 //! Creates the required input and output ports for this component,
135 //! particularly the azimuth aiming port specific to the human gun actuator.
136 virtual bool createPorts() override;
137
138 //! \brief Aims the gun based on input port values
139 //! \return True if aiming is complete, false otherwise
140 //!
141 //! Aims the gun based on input port values. Uses the myAimElevationInputPort
142 //! to determine the correct elevation and the myAimAzimuthInputPort
143 //! to determine the correct azimuth, combining them to aim the weapon appropriately.
144 virtual bool aimGun() override;
145
146 //! \brief Structure to store fire event results
147 //!
148 //! Contains information about a firing event, including detonation result,
149 //! distance to target, and reference to any hit entity.
151 {
152 //! \brief Result of the detonation calculation
153 DtDetonationResult result;
154
155 //! \brief Distance to the target in meters
157
158 //! \brief Reference to the target entity, if one was hit
159 DtSimObjectReference targetEntity;
160 };
161
162 //! \brief Calculates the result of firing the weapon
163 //! \param shooterPosition The position of the shooter in world coordinates
164 //! \param shooterOrienation The orientation of the shooter in world coordinates
165 //! \param fireResult Output parameter to store the fire result data
166 //!
167 //! Performs the ballistic calculations to determine what happens when the
168 //! weapon is fired from the given position and orientation.
169 virtual void getFireResult(
170 const DtVector& shooterPosition, const DtTaitBryan shooterOrienation, DtFireResult& fireResult);
171
172 //! \brief Creates a fire event to send to the simulation
173 //! \param firingPosition The position from which the weapon is fired
174 //! \param firingOrientation The orientation of the weapon when fired
175 //! \return Pointer to the newly created fire event
176 //!
177 //! Creates a fire event interaction based on the firing position and orientation,
178 //! which will be sent to the simulation to notify other components about the firing.
179 virtual makVrfEvents::DtFireEvent* createFireInteraction(
180 const DtVector& firingPosition, const DtTaitBryan firingOrientation);
181
182 //! \brief Creates a detonation event to send to the simulation
183 //! \param firingPosition The position from which the weapon was fired
184 //! \param firingOrientation The orientation of the weapon when fired
185 //! \param fireResult Result data from the fire calculation
186 //! \param detTime Output parameter to store the detonation time
187 //! \return Pointer to the newly created detonation event
188 //!
189 //! Creates a detonation event interaction based on the firing position, orientation,
190 //! and fire result data. This event notifies other components about the impact of the projectile.
191 virtual makVrfEvents::DtDetonationEvent* createDetonationInteraction(const DtVector& firingPosition,
192 const DtTaitBryan firingOrientation, const DtFireResult& fireResult, DtReal& detTime);
193
194 //! \brief Reduces ammunition count after firing
195 //! \param amount Number of ammunition units to deplete (default: 1)
196 //!
197 //! Reduces the ammunition count in the current magazine by the specified amount,
198 //! reflecting the consumption of ammunition when firing the weapon.
199 virtual void depleteResource(int amount = 1);
200
201 //! \brief Re-initializes pointers after a restore operation
202 //!
203 //! Re-assigns pointers to extended state data since the pointers could have
204 //! become invalid during a save/restore operation.
205 virtual void setRestored();
206
207 //! \brief Checks if the weapon is allowed to fire
208 //! \return True if the weapon can fire, false otherwise
209 //!
210 //! Determines whether the weapon is currently allowed to fire based on
211 //! ammunition availability, weapon state, and other conditions.
212 virtual bool allowWeaponFiring();
213
214 //! \brief Initiates the weapon firing sequence
215 //! \return Message processing result
216 //!
217 //! Creates and sends a fire interaction event, representing the firing of the weapon.
218 //! This method is used only by VR Engage controlled entities.
220
221 //! \brief Calculates weapon recoil effects
222 //! \param worldShooterPosition The position of the shooter in world coordinates
223 //! \param worldShooterOrientation The orientation of the shooter in world coordinates
224 //! \return Modified orientation accounting for recoil
225 //!
226 //! Creates a hit offset to simulate weapon recoil. The offset increases
227 //! with the number of rounds fired in rapid succession, simulating the
228 //! cumulative effect of recoil on accuracy.
229 virtual DtTaitBryan recoilEffect(DtVector worldShooterPosition, DtTaitBryan worldShooterOrientation);
230
231protected:
232 //! \brief Default constructor (not implemented)
233 //!
234 //! Default constructor is private and not implemented to prevent
235 //! creation of instances without proper initialization.
237
238 //! \brief Copy constructor (not implemented)
239 //!
240 //! Copy constructor is private and not implemented to prevent
241 //! copy construction.
243
244 //! \brief Assignment operator (not implemented)
245 //! \return Reference to this object
246 //!
247 //! Assignment operator is private and not implemented to prevent assignment.
249
250protected:
251 //! \brief Pointer to the human gun actuator descriptor
252 //!
253 //! Contains configuration parameters for this human gun actuator component.
255
256 //! \name Ports and Port Groups
257 //! @{
258
259 //! \brief Input port for controlling weapon azimuth aim
260 //!
261 //! Receives the azimuth at which to aim the weapon, in radians.
262 //! Range: -pi to pi, with default value of 0.
263 DtAnalogInputPort* myAimAzimuthInputPort;
264
265 //! @}
266
267 //! \brief Pointer to the firepower health state value
268 //!
269 //! Tracks the health/damage state of the weapon's firing capability.
271
272 //! \brief Number of rounds remaining in current burst
273 //!
274 //! Tracks how many more rounds can be fired in the current burst firing sequence.
276
277 //! \brief Type of munition selected for firing
278 //!
279 //! Stores the munition type received from FireInputMessage to use
280 //! for subsequent firing operations.
281 DtEntityType myTriggerMunition;
282
283 //! \brief World position for weapon firing
284 //!
285 //! Stores the location of the first burst fire received from FireInputMessage,
286 //! used for subsequent rounds in a burst sequence.
288
289 //! \brief World orientation for weapon firing
290 //!
291 //! Stores the orientation of the first burst fire received from FireInputMessage,
292 //! used for subsequent rounds in a burst sequence.
294
295 //! \brief Facade for human local object access
296 //!
297 //! Provides simplified access to human-specific functionality of the local object.
298 DtHumanLocalObjectFacade myHumanLocalObjectFacade;
299
300 //! \brief Flag indicating if this entity is currently player-controlled
301 //!
302 //! Tracks whether the entity is currently under player control, which affects
303 //! how ammunition state is reported and other behaviors.
305
306 //! \brief Pointer to the munition loader component
307 //!
308 //! Convenience pointer to the munition loader component, which must be of type
309 //! DtVreMunitionLoader. Used to manage ammunition loading and state.
311};
312
313} // namespace makVre
Extends the DtBallisticGun class with joystick control capabilities.
const DtHumanGunJoyActuator & operator=(const DtHumanGunJoyActuator &orig)
Assignment operator (not implemented)
DtHumanGunJoyActuator(const DtHumanGunJoyActuator &orig)
Copy constructor (not implemented)
DtTaitBryan myTriggerWorldOrientation
World orientation for weapon firing.
Definition humanGunJoyActuator.h:293
DtVector myTriggerWorldPosition
World position for weapon firing.
Definition humanGunJoyActuator.h:287
DtVreHumanGunActuatorDescriptor * myHumanGunDescriptor
Pointer to the human gun actuator descriptor.
Definition humanGunJoyActuator.h:254
virtual void tick() override
Updates the component state each simulation frame.
DtHumanGunJoyActuator()
Default constructor (not implemented)
virtual bool init() override
Initializes the component.
virtual void depleteResource(int amount=1)
Reduces ammunition count after firing.
virtual DtTaitBryan recoilEffect(DtVector worldShooterPosition, DtTaitBryan worldShooterOrientation)
Calculates weapon recoil effects.
virtual makVre::DtVreMessageResult handleFireInput(makVre::DtVreMessage *msg)
Processes fire input messages.
DtAnalogInputPort * myAimAzimuthInputPort
Input port for controlling weapon azimuth aim.
Definition humanGunJoyActuator.h:263
DtRwInt * myFirepowerHealth
Pointer to the firepower health state value.
Definition humanGunJoyActuator.h:270
DtHumanGunJoyActuator(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Constructor.
virtual bool createPSR() override
Creates the process state repository for this component.
DtVreMunitionLoader * myVreMunitionLoader
Pointer to the munition loader component.
Definition humanGunJoyActuator.h:310
DtHumanLocalObjectFacade myHumanLocalObjectFacade
Facade for human local object access.
Definition humanGunJoyActuator.h:298
virtual makVrfEvents::DtDetonationEvent * createDetonationInteraction(const DtVector &firingPosition, const DtTaitBryan firingOrientation, const DtFireResult &fireResult, DtReal &detTime)
Creates a detonation event to send to the simulation.
virtual bool aimGunElevation()
Aims the gun in elevation.
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.
bool myPlayerControlled
Flag indicating if this entity is currently player-controlled.
Definition humanGunJoyActuator.h:304
virtual const char * type() const override
Gets the type identifier for this component.
virtual bool createPorts() override
Creates input and output ports for this component.
virtual void getFireResult(const DtVector &shooterPosition, const DtTaitBryan shooterOrienation, DtFireResult &fireResult)
Calculates the result of firing the weapon.
virtual makVrfEvents::DtFireEvent * createFireInteraction(const DtVector &firingPosition, const DtTaitBryan firingOrientation)
Creates a fire event to send to the simulation.
virtual ~DtHumanGunJoyActuator() override
Virtual destructor.
DtEntityType myTriggerMunition
Type of munition selected for firing.
Definition humanGunJoyActuator.h:281
virtual makVre::DtVreMessageResult fire()
Initiates the weapon firing sequence.
int myBurstRoundsRemaining
Number of rounds remaining in current burst.
Definition humanGunJoyActuator.h:275
virtual bool allowWeaponFiring()
Checks if the weapon is allowed to fire.
virtual void setRestored()
Re-initializes pointers after a restore operation.
virtual bool aimGun() override
Aims the gun based on input port values.
Human gun actuator descriptor for VREngage.
Definition vreHumanGunActuatorDescriptor.h:33
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Extended munition loader with VREngage-specific functionality.
Definition vreMunitionLoader.h:30
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
const char DtHumanGunJoyActuatorType[]
Type identifier for the human gun joystick actuator component.
Definition humanGunJoyActuator.h:38
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Definition vrfRemoteControlConnector.h:87
Structure to store fire event results.
Definition humanGunJoyActuator.h:151
DtDetonationResult result
Result of the detonation calculation.
Definition humanGunJoyActuator.h:153
double rangeToTarget
Distance to the target in meters.
Definition humanGunJoyActuator.h:156
DtSimObjectReference targetEntity
Reference to the target entity, if one was hit.
Definition humanGunJoyActuator.h:159
Defines the base class for all VREngage messages.
Base template class for VR-Engage simulation components.