VR-Engage  2.2
Loading...
Searching...
No Matches
ballisticGunJoy.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file ballisticGunJoy.h
7//! \ingroup vreVrfmodel
8//! \brief Extends the DtBallisticGun class with joystick control capabilities
9//!
10//! This file defines the DtBallisticGunJoy class which adds joystick control
11//! functionality to the base ballistic gun implementation, allowing for manual
12//! aiming and firing via joystick input.
13
14#pragma once
15
16#include "vreVrfmodel/export.h"
17
18#include <vrfmodel/ballisticGun.h>
19#include <vrfMsgTransport/detonationEvent.h>
20
21class DtSimulationServices;
22class DtConstrainedAnalogInputPort;
23class DtBooleanInputPort;
24class DtBallisticGunDescriptor;
25
26namespace makVrf
27{
28class DtArticulatedPartStateRepository;
29}
30
31namespace makVre
32{
33const char DtBallisticGunJoyActuatorType[] = "ballistic-gun-joystick-actuator";
34
35//! \brief DtBallisticGunJoy extends the DtBallisticGun actuator class with the
36//! ability to be controlled from a joystick.
37//!
38//! Uses Descriptor Type: DtBallisticGunDescriptor
39class VREVRFMODEL_DLL DtBallisticGunJoy : public DtBallisticGun
40{
41public:
42 //! \copydoc DtSimComponent(const DtString&,DtLocalObject*,DtSimulationServices*,
43 //! DtComponentDescriptor*,DtReaderWriterRegistry* parentRegistry)
44 DtBallisticGunJoy(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
45 DtComponentDescriptor* desc, DtReaderWriterRegistry* const parentRegistry = 0);
46
47public:
48 //! \brief Virtual destructor
49 //!
50 //! Cleans up resources used by the ballistic gun joy component.
51 virtual ~DtBallisticGunJoy() override;
52
53 //! \brief Gets the type identifier for this component
54 //! \return String identifying the component type (DtBallisticGunJoyActuatorType)
55 //!
56 //! Implements the DtSimComponent::type() method to return the
57 //! type identifier for this component.
58 virtual const char* type() const override;
59
60 //! \brief Creates the input ports for the component
61 //! \return True if ports were created successfully, false otherwise
62 //!
63 //! Creates the elevation and joystick active input ports.
64 virtual bool createPorts() override;
65
66 //! \brief Sets the component descriptor and extracts configuration values
67 //! \param descriptor The component descriptor containing configuration parameters
68 //!
69 //! Overrides the base class method to extract joystick-specific values and
70 //! then calls the base class's method to set common parameters.
71 virtual void setComponentDescriptor(DtComponentDescriptor* descriptor) override;
72
73 //! \brief Updates the gun state each frame and handles firing
74 //!
75 //! Performs firing and detonation operations. Detects whether to use local
76 //! or parent function based on joystick enable/disable state.
77 virtual void tick() override;
78
79 //! \brief Sets the target for the gun
80 //! \param rotBody The articulated part state repository of the gun, or entity state if none exists
81 //! \return Distance to the target, or -1.0 if no target found
82 //!
83 //! Uses targetSelection() to try to find an entity in the gun's line
84 //! of fire; if it finds one, it sets the PSR->currentTarget.
85 virtual DtReal setTarget(makVrf::DtArticulatedPartStateRepository* rotBody);
86
87 //! \brief Creates a fire interaction event
88 //! \param rotBody The articulated part state repository of the gun, or entity state if none exists
89 //! \return Pointer to the created fire event
90 //!
91 //! Creates a fire interaction event. Uses the currentTarget in the PSR as the
92 //! fire target, if present.
93 virtual makVrfEvents::DtFireEvent* manualFireInteraction(makVrf::DtArticulatedPartStateRepository* rotBody);
94
95 //! \brief Creates a detonation interaction event
96 //! \param rotBody The articulated part state repository of the gun, or entity state if none exists
97 //! \param detTime Reference to store the detonation time
98 //! \param dist Distance to the target
99 //! \return Pointer to the created detonation event
100 //!
101 //! Creates a detonation interaction event based on the current target and distance.
102 virtual makVrfEvents::DtDetonationEvent* manualDetonationInteraction(
103 makVrf::DtArticulatedPartStateRepository* rotBody, DtReal& detTime, DtReal dist);
104
105 //! \brief Finds a target along the gun's firing direction
106 //! \param rotBody The articulated part state repository of the gun, or entity state if none exists
107 //! \param dist Reference to store the distance to the target
108 //! \return UUID of the first target found, or empty UUID if none found
109 //!
110 //! Casts a ray out from the gun to a point MAX_RANGE away (currently 4000m).
111 //! Determines, using physicalWorld->getVrfObjectsAlongChord(), if there are any
112 //! platforms, lifeforms, or cultural features on the ray. Returns the UUID of
113 //! the first one found and stores the range in the dist parameter.
114 virtual DtUUID targetSelection(makVrf::DtArticulatedPartStateRepository* rotBody, DtReal& dist);
115
116 //! \brief Calculates the distance to the current target
117 //! \return Distance to the target, or -1.0 if no target is set
118 //!
119 //! Determines the distance from the gun to the currently selected target.
120 virtual DtReal distanceToTarget();
121
122 //! \brief Timer callback for detonation events
123 //! \param timer Pointer to the timer that has expired
124 //!
125 //! Casts the user data portion of the DtTimer to a DtDetonationTimerData object.
126 //! Uses the Simulation Manager pointer in the DtDetonationTimerData to get the
127 //! DtExerciseConn, and sends the makVrfEvents::DtDetonationEvent via the exercise
128 //! connection. The timer is removed from the scheduler, and the
129 //! DtDetonationTimerData and makVrfEvents::DtDetonationEvent objects are deleted.
130 static void detonationCallback(DtTimer* timer);
131
132 //! \brief Factory method to create a new instance of this component
133 //! \param name The name for the new component
134 //! \param owner The local object that will own this component
135 //! \param simManager The simulation services manager
136 //! \param desc Optional component descriptor
137 //! \param parentRegistry Optional parent registry for reader/writer functionality
138 //! \return Pointer to the newly created component
139 //!
140 //! Static factory method used by the component creation system to instantiate
141 //! new instances of this component type.
142 static DtSimComponent* creator(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
143 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
144
145private:
146 //! \brief Default constructor (not implemented)
147 //!
148 //! Default constructor is private and not implemented to prevent
149 //! creation of instances without proper initialization.
151
152 //! \brief Copy constructor (not implemented)
153 //!
154 //! Copy constructor is private and not implemented to prevent
155 //! copy construction.
157
158 //! \brief Assignment operator (not implemented)
159 //! \return Reference to this object
160 //!
161 //! Assignment operator is private and not implemented to prevent assignment.
163
164protected:
165 //! \name Ports and Port Groups
166 //! @{
167
168 //! Input Port Name: elevation\n
169 //! Input Port Description: \n
170 //! Input Port Range: -1. to 1.\n
171 //! Input Port Default Value: \n
172 //! Input Group Parent: gun-control
173 DtConstrainedAnalogInputPort* myElevationPort;
174
175 //! Input Port Name: joystick-active\n
176 //! Input Port Description: \n
177 //! Input Port Range: \n
178 //! Input Port Default Value: \n
179 //! Input Group Parent: gun-control
180 DtBooleanInputPort* myActiveJoystickPort;
181
182 //! @}
183
184 //! \brief Flag to track missing articulation warning
185 //!
186 //! A flag to remember whether a warning message was printed about
187 //! not finding an articulated part.
189};
190} // namespace makVre
virtual DtReal distanceToTarget()
Calculates the distance to the current target.
virtual ~DtBallisticGunJoy() override
Virtual destructor.
bool myReportedNoArticulation
Flag to track missing articulation warning.
Definition ballisticGunJoy.h:188
virtual DtUUID targetSelection(makVrf::DtArticulatedPartStateRepository *rotBody, DtReal &dist)
Finds a target along the gun's firing direction.
virtual makVrfEvents::DtFireEvent * manualFireInteraction(makVrf::DtArticulatedPartStateRepository *rotBody)
Creates a fire interaction event.
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.
DtConstrainedAnalogInputPort * myElevationPort
Input Port Name: elevation Input Port Description: Input Port Range: -1. to 1. Input Port Default Va...
Definition ballisticGunJoy.h:173
virtual const char * type() const override
Gets the type identifier for this component.
virtual makVrfEvents::DtDetonationEvent * manualDetonationInteraction(makVrf::DtArticulatedPartStateRepository *rotBody, DtReal &detTime, DtReal dist)
Creates a detonation interaction event.
DtBallisticGunJoy(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc, DtReaderWriterRegistry *const parentRegistry=0)
static void detonationCallback(DtTimer *timer)
Timer callback for detonation events.
virtual DtReal setTarget(makVrf::DtArticulatedPartStateRepository *rotBody)
Sets the target for the gun.
virtual void setComponentDescriptor(DtComponentDescriptor *descriptor) override
Sets the component descriptor and extracts configuration values.
DtBooleanInputPort * myActiveJoystickPort
Input Port Name: joystick-active Input Port Description: Input Port Range: Input Port Default Value...
Definition ballisticGunJoy.h:180
const DtBallisticGunJoy & operator=(const DtBallisticGunJoy &orig)
Assignment operator (not implemented)
DtBallisticGunJoy()
Default constructor (not implemented)
DtBallisticGunJoy(const DtBallisticGunJoy &orig)
Copy constructor (not implemented)
virtual void tick() override
Updates the gun state each frame and handles firing.
virtual bool createPorts() override
Creates the input ports for the component.
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 DtBallisticGunJoyActuatorType[]
Definition ballisticGunJoy.h:33
Definition connectorAccessory.h:39