VR-Engage  2.3
Loading...
Searching...
No Matches
humanJoystickCombatController.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file humanJoystickCombatController.h
7//! \ingroup vreVrfmodel
8//! \brief Joystick controller for human combat capabilities
9//!
10//! This file defines the DtHumanJoystickCombatController class which enables joystick
11//! control of combat capabilities for human entities, including weapon aiming, firing, and
12//! other combat-related actions.
13
14#pragma once
15
16#include "vreVrfmodel/export.h"
17#include <vrfobjcore/controllerComponent.h>
19
20class DtString;
21class DtSimulationServices;
22class DtJoyDeviceControllerDescriptor;
23class DtJoyDevice;
24class DtHumanStateRepository;
25class DtBooleanOutputPort;
26class DtIntegerOutputPort;
27class DtAnalogOutputPort;
28class DtVectorOutputPort;
29class DtConstrainedAnalogOutputPort;
30
31namespace makVre
32{
33
34//! \brief Type identifier for the human joystick combat controller component
35const char DtHumanJoystickCombatControllerType[] = "human-joystick-combat-controller";
36
37//! \brief Controller for joystick-based combat control of human entities
38//!
39//! DtHumanJoystickCombatController enables joystick control of a human entity's
40//! combat capabilities. It manages weapon aiming, firing, and other combat-related
41//! actions through joystick inputs. This controller works alongside movement controllers
42//! to provide comprehensive control of human entities.
43//!
44//! Uses Descriptor Type: DtHumanJoystickCombatControllerDescriptor
45class VREVRFMODEL_DLL DtHumanJoystickCombatController : public DtControllerComponent,
47{
48public:
49 //! \brief Constructor
50 //! \param name The name of this component
51 //! \param owner The local object that owns this component
52 //! \param simManager The simulation services manager
53 //! \param desc Component descriptor with configuration parameters
54 //! \param parentRegistry Optional parent registry for reader/writer functionality
55 //!
56 //! Creates a new human joystick combat controller component with the specified parameters.
57 DtHumanJoystickCombatController(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
58 DtComponentDescriptor* desc, DtReaderWriterRegistry* parentRegistry = 0);
59
60 //! \brief Virtual destructor
61 //!
62 //! Cleans up resources used by the human joystick combat controller component.
64
65 //! \brief Gets the type identifier for this component
66 //! \return String identifying the component type (DtHumanJoystickCombatControllerType)
67 //!
68 //! Implements the DtSimComponent::type() method to return the
69 //! type identifier for this component.
70 virtual const char* type() const override;
71
72 //! \brief Calls base first-tick initialization and restores incoming joystick state.
73 virtual void preFirstTickInit() override;
74
75 //! \brief Creates port groups for this component
76 //! \return True if port groups were created successfully, false otherwise
77 //!
78 //! Creates and initializes the output port groups used by this controller,
79 //! including groups for weapon aiming and ballistic gun control.
80 virtual bool createPortGroups() override;
81
82 //! \brief Creates input and output ports for this component
83 //! \return True if ports were created successfully, false otherwise
84 //!
85 //! Creates and initializes all input and output ports used by this controller
86 //! for combat-related functions, including ports for aiming, triggering, and
87 //! weapon state information.
88 virtual bool createPorts() override;
89
90 //! \brief Factory method to create a new instance of this component
91 //! \param name The name for the new component
92 //! \param owner The local object that will own this component
93 //! \param simManager The simulation services manager
94 //! \param desc Optional component descriptor
95 //! \param parentRegistry Optional parent registry for reader/writer functionality
96 //! \return Pointer to the newly created component
97 //!
98 //! Static factory method used by the component creation system to instantiate
99 //! new instances of this component type.
100 static DtSimComponent* creator(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
101 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
102
103private:
104 //! \brief Default constructor (not implemented)
105 //!
106 //! Default constructor is private and not implemented to prevent
107 //! creation of instances without proper initialization.
109
110 //! \brief Copy constructor (not implemented)
111 //!
112 //! Copy constructor is private and not implemented to prevent
113 //! copy construction.
115
116 //! \brief Assignment operator (not implemented)
117 //! \return Reference to this object
118 //!
119 //! Assignment operator is private and not implemented to prevent assignment.
121
122protected:
123 //! \brief Processes joystick input and updates output ports
124 //! \param functionGroup The function group identifier for the input
125 //! \param function The specific function identifier within the group
126 //! \param value The input value from the joystick
127 //! \param repeat Flag indicating if this is a repeated input
128 //!
129 //! Implements the DtJoystickControllerInterface method to process joystick
130 //! input and update the controller's output ports for combat functions.
132 const DtString& functionGroup, const DtString& function, double value, bool repeat) override;
133
134 //! \brief Handles joystick connection event
135 //!
136 //! Called when a joystick is connected to the system.
137 //! Activates joystick control mode for combat functions.
138 virtual void joystickConnected() override;
139
140 //! \brief Handles joystick disconnection event
141 //!
142 //! Called when a joystick is disconnected from the system.
143 //! Deactivates joystick control mode for combat functions.
144 virtual void joystickDisconnected() override;
145
146 //! \brief Updates the controller state each simulation frame
147 //!
148 //! Processes combat-related controls and updates the human entity's
149 //! weapon aiming and firing state based on current joystick inputs.
150 virtual void tick() override;
151
152
153protected:
154 //! \name Ports and Port Groups
155 //! @{
156
157
158 //! \brief Output port group for aiming weapon systems
159 //!
160 //! Contains all output ports related to weapon aiming control.
161 DtOutputPortGroup* myAimWeaponOutputPortGroup;
162
163 //! \brief Output port for enabling aiming at specific angles
164 //!
165 //! When true, allows aiming at specific elevation and azimuth angles.
166 DtBooleanOutputPort* myAimAtAnglePort;
167
168 //! \brief Output port for enabling azimuth aiming
169 //!
170 //! When true, allows aiming in azimuth (side-to-side) direction.
171 DtBooleanOutputPort* myAllowAzimuthAimingPort;
172
173 //! \brief Output port for azimuth aim angle
174 //!
175 //! Controls the azimuth angle for weapon aiming in radians.
176 DtAnalogOutputPort* myAimAzimuthOutputPort;
177
178 //! \brief Output port for elevation aim angle
179 //!
180 //! Controls the elevation angle for weapon aiming in radians.
181 DtAnalogOutputPort* myAimElevationOutputPort;
182
183 //! \brief Output port group for ballistic gun control
184 //!
185 //! Contains all output ports related to the control of ballistic guns.
186 DtOutputPortGroup* myBalGunControlPortGroup;
187
188 //! \brief Output port for weapon trigger state
189 //!
190 //! When true, indicates that the weapon trigger is pulled/activated.
191 DtBooleanOutputPort* myTriggerPort;
192
193 //! \brief Output port for ammunition quantity
194 //!
195 //! Indicates the quantity of ammunition to use for firing.
196 DtIntegerOutputPort* myQuantityOutputPort;
197
198 //! \brief Output port for loaded state
199 //!
200 //! When true, indicates that the weapon is loaded and ready to fire.
201 DtBooleanOutputPort* myLoadedPort;
202
203 //! \brief Output port for line-of-sight state
204 //!
205 //! Indicates whether a valid line-of-sight target exists.
206 DtIntegerOutputPort* myLosPort;
207
208 //! \brief Output port for primary joystick active state
209 //!
210 //! When true, indicates that primary joystick control is active.
211 DtBooleanOutputPort* myActiveJoystickPort;
212
213 //! \brief Output port for secondary joystick active state
214 //!
215 //! When true, indicates that secondary joystick control is active.
216 DtBooleanOutputPort* mySecondActiveJoystickPort;
217
218 //! \brief Pointer to the human state repository
219 //!
220 //! Access to the human entity's state information.
221 DtHumanStateRepository* myHumanStateRepository;
222
223 //! \brief Output port for elevation control
224 //!
225 //! Controls the elevation of the weapon system, with constraints on minimum and maximum values.
226 DtConstrainedAnalogOutputPort* myElevationPort;
227
228 //! \brief Flag indicating if the entity is currently aiming
229 //!
230 //! When true, the entity is actively aiming a weapon.
232
233 //! \brief Flag indicating if the trigger is currently activated
234 //!
235 //! When true, the weapon trigger is being pressed/activated.
237
238 //! \brief Rate of change for pitch (elevation) control
239 //!
240 //! Controls how quickly the weapon elevation changes in response to inputs.
242
243 //! \brief Current pitch (elevation) angle
244 //!
245 //! Stores the current pitch/elevation angle of the weapon in radians.
246 double myPitch;
247
248 //! \brief Current mouse-controlled pitch contribution
249 //!
250 //! Stores the component of pitch that is controlled by mouse input.
252
253 //! \brief Rate of change for yaw (azimuth) control
254 //!
255 //! Controls how quickly the weapon azimuth changes in response to inputs.
257
258 //! \brief Current yaw (azimuth) angle
259 //!
260 //! Stores the current yaw/azimuth angle of the weapon in radians.
261 double myYaw;
262
263 //! \brief Current mouse-controlled yaw contribution
264 //!
265 //! Stores the component of yaw that is controlled by mouse input.
267
268 //! \brief Current state of the weapon
269 //!
270 //! Stores the current operational state of the weapon system.
272
273 //! \brief Current weapon aim elevation
274 //!
275 //! Stores the current elevation angle being used for aiming the weapon.
277
278 //! \brief Current weapon aim azimuth
279 //!
280 //! Stores the current azimuth angle being used for aiming the weapon.
282};
283
284} // namespace makVre
bool myAiming
Flag indicating if the entity is currently aiming.
Definition humanJoystickCombatController.h:231
virtual void calcAndSetPortValues(const DtString &functionGroup, const DtString &function, double value, bool repeat) override
Processes joystick input and updates output ports.
DtIntegerOutputPort * myQuantityOutputPort
Output port for ammunition quantity.
Definition humanJoystickCombatController.h:196
DtOutputPortGroup * myAimWeaponOutputPortGroup
Output port group for aiming weapon systems.
Definition humanJoystickCombatController.h:161
double myCurrentAimAzimuth
Current weapon aim azimuth.
Definition humanJoystickCombatController.h:281
DtAnalogOutputPort * myAimElevationOutputPort
Output port for elevation aim angle.
Definition humanJoystickCombatController.h:181
double myMousePitch
Current mouse-controlled pitch contribution.
Definition humanJoystickCombatController.h:251
DtBooleanOutputPort * myActiveJoystickPort
Output port for primary joystick active state.
Definition humanJoystickCombatController.h:211
DtBooleanOutputPort * myLoadedPort
Output port for loaded state.
Definition humanJoystickCombatController.h:201
DtHumanJoystickCombatController()
Default constructor (not implemented)
DtHumanJoystickCombatController & operator=(const DtHumanJoystickCombatController &orig)
Assignment operator (not implemented)
double myPitch
Current pitch (elevation) angle.
Definition humanJoystickCombatController.h:246
virtual bool createPortGroups() override
Creates port groups for this component.
int myCurrentWeaponState
Current state of the weapon.
Definition humanJoystickCombatController.h:271
bool myTrigger
Flag indicating if the trigger is currently activated.
Definition humanJoystickCombatController.h:236
double myYawingRate
Rate of change for yaw (azimuth) control.
Definition humanJoystickCombatController.h:256
DtBooleanOutputPort * myAllowAzimuthAimingPort
Output port for enabling azimuth aiming.
Definition humanJoystickCombatController.h:171
DtOutputPortGroup * myBalGunControlPortGroup
Output port group for ballistic gun control.
Definition humanJoystickCombatController.h:186
DtIntegerOutputPort * myLosPort
Output port for line-of-sight state.
Definition humanJoystickCombatController.h:206
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 const char * type() const override
Gets the type identifier for this component.
virtual void preFirstTickInit() override
Calls base first-tick initialization and restores incoming joystick state.
double myPitchingRate
Rate of change for pitch (elevation) control.
Definition humanJoystickCombatController.h:241
DtConstrainedAnalogOutputPort * myElevationPort
Output port for elevation control.
Definition humanJoystickCombatController.h:226
DtBooleanOutputPort * myAimAtAnglePort
Output port for enabling aiming at specific angles.
Definition humanJoystickCombatController.h:166
DtAnalogOutputPort * myAimAzimuthOutputPort
Output port for azimuth aim angle.
Definition humanJoystickCombatController.h:176
double myYaw
Current yaw (azimuth) angle.
Definition humanJoystickCombatController.h:261
DtHumanJoystickCombatController(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc, DtReaderWriterRegistry *parentRegistry=0)
Constructor.
virtual bool createPorts() override
Creates input and output ports for this component.
DtBooleanOutputPort * myTriggerPort
Output port for weapon trigger state.
Definition humanJoystickCombatController.h:191
virtual void tick() override
Updates the controller state each simulation frame.
virtual void joystickDisconnected() override
Handles joystick disconnection event.
virtual void joystickConnected() override
Handles joystick connection event.
virtual ~DtHumanJoystickCombatController() override
Virtual destructor.
double myCurrentAimElevation
Current weapon aim elevation.
Definition humanJoystickCombatController.h:276
double myMouseYaw
Current mouse-controlled yaw contribution.
Definition humanJoystickCombatController.h:266
DtHumanStateRepository * myHumanStateRepository
Pointer to the human state repository.
Definition humanJoystickCombatController.h:221
DtBooleanOutputPort * mySecondActiveJoystickPort
Output port for secondary joystick active state.
Definition humanJoystickCombatController.h:216
DtHumanJoystickCombatController(const DtHumanJoystickCombatController &orig)
Copy constructor (not implemented)
DtVreJoystickControllerInterface(DtSimComponent *component, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc)
Constructs an interface alongside an existing component base.
Defines export macros for the vreVrfmodel library.
#define VREVRFMODEL_DLL
Definition export.h:22
!
Definition glsVreMessageUtil.h:50
const char DtHumanJoystickCombatControllerType[]
Type identifier for the human joystick combat controller component.
Definition humanJoystickCombatController.h:35
Internal-state persistence for VRE joystick controllers.