VR-Engage  2.2
Loading...
Searching...
No Matches
ballisticGunJoyController.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file ballisticGunJoyController.h
7//! \ingroup vreVrfmodel
8//! \brief Controller for ballistic guns with joystick input support
9//!
10//! This file defines the DtBallisticGunJoyController class which extends the standard
11//! ballistic gun controller with joystick input capabilities, allowing manual control
12//! of weapon aiming and firing.
13
14#pragma once
15
16#include "vreVrfmodel/export.h"
17
18#include <vrfmodel/ballisticGunController.h>
19#include <vrfmodel/joystickControllerInterface.h>
20
21class DtConstrainedAnalogOutputPort;
22class DtBooleanOutputPort;
23class DtOutputPortGroup;
24class DtJoyDeviceControllerDescriptor;
25
26//! \brief Type identifier for the ballistic gun joy controller component
27const char DtBallisticGunJoyControllerType[] = "ballistic-gun-joy-controller";
28
29namespace makVre
30{
31//! \brief Controller for ballistic guns with joystick input capabilities
32//!
33//! DtBallisticGunJoyController extends the DtBallisticGunController class
34//! with the ability to be controlled from a joystick. It implements the
35//! DtJoystickControllerInterface to process joystick input and translate
36//! it to appropriate gun control outputs.
37//!
38//! Uses Descriptor Type: DtBallisticGunJoyControllerDescriptor
39class VREVRFMODEL_DLL DtBallisticGunJoyController : public DtBallisticGunController,
40 public DtJoystickControllerInterface
41{
42public:
43 //! \brief Constructor
44 //! \param name The name of this component
45 //! \param owner The local object that owns this component
46 //! \param simManager The simulation services manager
47 //! \param desc Component descriptor with configuration parameters
48 //! \param parentRegistry Optional parent registry for reader/writer functionality
49 //!
50 //! Creates a new ballistic gun joy controller component with the specified parameters.
51 DtBallisticGunJoyController(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
52 DtComponentDescriptor* desc, DtReaderWriterRegistry* const parentRegistry = 0);
53
54 //! \brief Virtual destructor
55 //!
56 //! Cleans up resources used by the ballistic gun joy controller component.
57 virtual ~DtBallisticGunJoyController() override;
58
59 //! \brief Gets the type identifier for this component
60 //! \return String identifying the component type (DtBallisticGunJoyControllerType)
61 //!
62 //! Implements the DtSimComponent::type() method to return the
63 //! type identifier for this component.
64 virtual const char* type() const override;
65
66 //! \brief Creates the joystick active state output port
67 //! \return True if port was created successfully, false otherwise
68 //!
69 //! Creates the output port used to indicate when joystick control is active.
70 //! This is called during initialization to set up communication with the actuator.
72
73 //! \brief Gets the joystick active state output port
74 //! \return Pointer to the joystick active output port
75 //!
76 //! Provides access to the port that indicates when joystick control is active.
77 virtual DtBooleanOutputPort* activeJoystickPort() const;
78
79 //! \brief Creates the elevation control output port
80 //! \return True if port was created successfully, false otherwise
81 //!
82 //! Creates the output port used to control gun elevation via joystick input.
83 virtual bool createElevationPort();
84
85 //! \brief Gets the elevation control output port
86 //! \return Pointer to the elevation output port
87 //!
88 //! Provides access to the port that controls gun elevation.
89 virtual DtConstrainedAnalogOutputPort* elevationPort() const;
90
91 //! \brief Selects ammunition type for the weapon
92 //! \param name The entity type of ammunition to select, or null for default
93 //! \return True if ammunition selection was successful, false otherwise
94 //!
95 //! Attempts to select the specified ammunition type for the weapon.
96 //! If no type is specified (nullType), uses the default ammunition.
97 virtual bool chooseAmmo(const DtEntityType& name = DtEntityType::nullType());
98
99 //! \brief Checks if the weapon can currently fire
100 //! \return True if the weapon can fire, false otherwise
101 //!
102 //! Determines whether the weapon is currently able to fire based on
103 //! ammunition availability and other weapon state conditions.
104 virtual bool canFire();
105
106 //! \brief Factory method to create a new instance of this component
107 //! \param name The name for the new component
108 //! \param owner The local object that will own this component
109 //! \param simManager The simulation services manager
110 //! \param desc Optional component descriptor
111 //! \param parentRegistry Optional parent registry for reader/writer functionality
112 //! \return Pointer to the newly created component
113 //!
114 //! Static factory method used by the component creation system to instantiate
115 //! new instances of this component type.
116 static DtSimComponent* creator(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
117 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
118
119protected:
120 //! \brief Updates the controller state each simulation frame
121 //!
122 //! Processes joystick input and updates output ports to control
123 //! the associated ballistic gun actuator component.
124 virtual void tick() override;
125
126 //! \brief Processes joystick input and updates output ports
127 //! \param functionGroup The function group identifier for the input
128 //! \param function The specific function identifier within the group
129 //! \param value The input value from the joystick
130 //! \param repeat Flag indicating if this is a repeated input
131 //!
132 //! Implements the DtJoystickControllerInterface method to process joystick
133 //! input and update the controller's output ports accordingly.
135 const DtString& functionGroup, const DtString& function, double value, bool repeat) override;
136 //! \brief Handles joystick connection event
137 //!
138 //! Called when a joystick is connected to the system.
139 //! Activates joystick control mode for this controller.
140 virtual void joystickConnected() override;
141 //! \brief Handles joystick disconnection event
142 //!
143 //! Called when a joystick is disconnected from the system.
144 //! Deactivates joystick control mode for this controller.
145 virtual void joystickDisconnected() override;
146
147 //! \brief Creates all required output ports for this controller
148 //! \return True if all ports were created successfully, false otherwise
149 //!
150 //! Overridden to create the specific output ports needed by this controller,
151 //! including elevation control and joystick active state ports.
152 virtual bool createPorts() override;
153
154private:
155 //! \brief Default constructor (not implemented)
156 //!
157 //! Default constructor is private and not implemented to prevent
158 //! creation of instances without proper initialization.
160
161 //! \brief Copy constructor (not implemented)
162 //!
163 //! Copy constructor is private and not implemented to prevent
164 //! copy construction.
166
167 //! \brief Assignment operator (not implemented)
168 //! \return Reference to this object
169 //!
170 //! Assignment operator is private and not implemented to prevent assignment.
172
173protected:
174 //! \name Ports and Port Groups
175 //! @{
176
177 //! Output Port Name: elevation\n
178 //! Output Port Description: \n
179 //! Output Port Range: -1. to 1.\n
180 //! Output Port Default Value: \n
181 //! Output Group Parent:
182 DtConstrainedAnalogOutputPort* myElevationPort;
183
184 //! Output Port Name: joystick-active\n
185 //! Output Port Description: Indicates whether controller behavior is being
186 //! executed through a joystick.\n
187 //! Output Port Range: \n
188 //! Output Port Default Value: false\n
189 //! Output Group Parent:
190 DtBooleanOutputPort* myActiveJoystickPort;
191
192 //! @}
193
194 //! \brief Flag indicating if the weapon is currently firing
196
197 //! \brief Flag indicating if the fire button is currently pressed
199};
200} // namespace makVre
const char DtBallisticGunJoyControllerType[]
Type identifier for the ballistic gun joy controller component.
Definition ballisticGunJoyController.h:27
virtual void joystickDisconnected() override
Handles joystick disconnection event.
virtual bool createElevationPort()
Creates the elevation control output port.
virtual ~DtBallisticGunJoyController() override
Virtual destructor.
DtBallisticGunJoyController(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc, DtReaderWriterRegistry *const parentRegistry=0)
Constructor.
const DtBallisticGunJoyController & operator=(const DtBallisticGunJoyController &orig)
Assignment operator (not implemented)
virtual bool canFire()
Checks if the weapon can currently fire.
virtual void tick() override
Updates the controller state each simulation frame.
DtBallisticGunJoyController()
Default constructor (not implemented)
DtConstrainedAnalogOutputPort * myElevationPort
Output Port Name: elevation Output Port Description: Output Port Range: -1. to 1....
Definition ballisticGunJoyController.h:182
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 myFireButtonDown
Flag indicating if the fire button is currently pressed.
Definition ballisticGunJoyController.h:198
virtual DtBooleanOutputPort * activeJoystickPort() const
Gets the joystick active state output port.
DtBooleanOutputPort * myActiveJoystickPort
Output Port Name: joystick-active Output Port Description: Indicates whether controller behavior is b...
Definition ballisticGunJoyController.h:190
bool myFiring
Flag indicating if the weapon is currently firing.
Definition ballisticGunJoyController.h:195
virtual void calcAndSetPortValues(const DtString &functionGroup, const DtString &function, double value, bool repeat) override
Processes joystick input and updates output ports.
DtBallisticGunJoyController(const DtBallisticGunJoyController &orig)
Copy constructor (not implemented)
virtual void joystickConnected() override
Handles joystick connection event.
virtual bool createActiveJoystickPort()
Creates the joystick active state output port.
virtual bool createPorts() override
Creates all required output ports for this controller.
virtual DtConstrainedAnalogOutputPort * elevationPort() const
Gets the elevation control output port.
virtual const char * type() const override
Gets the type identifier for this component.
virtual bool chooseAmmo(const DtEntityType &name=DtEntityType::nullType())
Selects ammunition type for the weapon.
Defines export macros for the vreVrfmodel library.
#define VREVRFMODEL_DLL
Definition export.h:22
Include export definitions for this library.
Definition glsVreMessageUtil.h:49