VR-Engage  2.2
Loading...
Searching...
No Matches
humanJoystickMovementController.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file humanJoystickMovementController.h
7//! \ingroup vreVrfmodel
8//! \brief Joystick controller for human entity movement
9//!
10//! This file defines the DtHumanJoystickMovementController class which enables joystick
11//! control of human entity movement. It provides capabilities for controlling walking,
12//! running, strafing, turning, and posture changes through joystick inputs.
13
14#pragma once
15
16#include "vreVrfmodel/export.h"
17#include <vrfobjcore/controllerComponent.h>
18#include <vrfmodel/joystickControllerInterface.h>
19
21
22class DtString;
23class DtSimulationServices;
24class DtJoyDeviceControllerDescriptor;
25class DtJoyDevice;
26class DtHumanMovementControlOutputPortGroup;
27class DtHumanStateRepository;
28class DtBooleanOutputPort;
29class DtIntegerOutputPort;
30class DtAnalogOutputPort;
31
32namespace makVre
33{
34//! \brief Type identifier for the human joystick movement controller component
35const char DtVreHumanJoystickMovementControllerType[] = "vre-human-joystick-movement-controller";
36
37//! \brief Controller for joystick-based movement control of human entities
38//!
39//! DtHumanJoystickMovementController enables joystick control of a human entity's
40//! movement capabilities. It manages walking, running, strafing, turning, and
41//! posture changes through joystick inputs. This controller works alongside combat
42//! controllers to provide comprehensive control of human entities.
43//!
44//! Uses Descriptor Type: DtVreHumanJoystickMovementControllerDescriptor
45class VREVRFMODEL_DLL DtHumanJoystickMovementController : public DtControllerComponent,
46 public DtJoystickControllerInterface
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 movement controller component with the specified parameters.
57 DtHumanJoystickMovementController(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 movement controller component.
64
65 //! \brief Gets the type identifier for this component
66 //! \return String identifying the component type (DtVreHumanJoystickMovementControllerType)
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 Creates port groups for this component
73 //! \return True if port groups were created successfully, false otherwise
74 //!
75 //! Creates and initializes the output port groups used by this controller,
76 //! particularly the human movement control port group.
77 virtual bool createPortGroups() override;
78
79 //! \brief Creates input and output ports for this component
80 //! \return True if ports were created successfully, false otherwise
81 //!
82 //! Creates and initializes all input and output ports used by this controller
83 //! for movement-related functions, including ports for movement state and posture.
84 virtual bool createPorts() override;
85
86 //! \brief Factory method to create a new instance of this component
87 //! \param name The name for the new component
88 //! \param owner The local object that will own this component
89 //! \param simManager The simulation services manager
90 //! \param desc Optional component descriptor
91 //! \param parentRegistry Optional parent registry for reader/writer functionality
92 //! \return Pointer to the newly created component
93 //!
94 //! Static factory method used by the component creation system to instantiate
95 //! new instances of this component type.
96 static DtSimComponent* creator(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
97 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
98
99private:
100 //! \brief Default constructor (not implemented)
101 //!
102 //! Default constructor is private and not implemented to prevent
103 //! creation of instances without proper initialization.
105
106 //! \brief Copy constructor (not implemented)
107 //!
108 //! Copy constructor is private and not implemented to prevent
109 //! copy construction.
111
112 //! \brief Assignment operator (not implemented)
113 //! \return Reference to this object
114 //!
115 //! Assignment operator is private and not implemented to prevent assignment.
117
118protected:
119 //! \brief Processes joystick input and updates output ports
120 //! \param functionGroup The function group identifier for the input
121 //! \param function The specific function identifier within the group
122 //! \param value The input value from the joystick
123 //! \param repeat Flag indicating if this is a repeated input
124 //!
125 //! Implements the DtJoystickControllerInterface method to process joystick
126 //! input and update the controller's output ports for movement functions.
128 const DtString& functionGroup, const DtString& function, double value, bool repeat) override;
129
130 //! \brief Handles joystick connection event
131 //!
132 //! Called when a joystick is connected to the system.
133 //! Activates joystick control mode for movement functions.
134 virtual void joystickConnected() override;
135
136 //! \brief Handles joystick disconnection event
137 //!
138 //! Called when a joystick is disconnected from the system.
139 //! Deactivates joystick control mode for movement functions.
140 virtual void joystickDisconnected() override;
141
142 //! \brief Updates the controller state each simulation frame
143 //!
144 //! Processes movement-related controls and updates the human entity's
145 //! movement state and posture based on current joystick inputs.
146 virtual void tick() override;
147
148protected:
149 //! \name Ports and Port Groups
150 //! @{
151
152 //! \brief Output port group for human movement control
153 //!
154 //! Contains all output ports related to human movement control, including
155 //! forward/backward movement, strafing, turning, and running states.
156 DtHumanMovementControlOutputPortGroup* myHumanMovementControlOutputPortGroup;
157
158 //! \brief Output port indicating movement state
159 //!
160 //! When true, indicates that the entity is being actively moved
161 //! by this controller. Used to synchronize animations and other
162 //! movement-dependent systems.
163 DtBooleanOutputPort* myIsMovingPort;
164 //! @}
165
166 //! \brief Output port for static posture control
167 //!
168 //! Controls the static posture of the entity (standing, crouching, prone, etc.)
169 //! using integer values to represent different postures.
170 DtIntegerOutputPort* myStaticPostureOutputPort;
171
172 //! \brief Pointer to the human state repository
173 //!
174 //! Provides access to the human entity's state information for
175 //! reading and modifying state based on movement inputs.
176 DtHumanStateRepository* myHumanStateRepository;
177
178 //! \brief Pointer to the movement controller descriptor
179 //!
180 //! Provides access to component-specific configuration parameters
181 //! defined for this human joystick movement controller.
183
184 //! \brief Rate of turning in response to inputs
185 //!
186 //! Controls how quickly the human entity turns in response to yaw inputs.
188
189 //! \brief Speed multiplier for movement
190 //!
191 //! Adjusts the speed of forward/backward and strafe movement relative
192 //! to the base movement speeds defined for the entity.
194
195 //! \brief Current forward/backward movement input value
196 //!
197 //! Ranges from -1.0 (full backward) to 1.0 (full forward).
198 double myForward;
199
200 //! \brief Current strafe (sideways) movement input value
201 //!
202 //! Ranges from -1.0 (full left) to 1.0 (full right).
203 double myStrafe;
204
205 //! \brief Current yaw (turning) input value from joystick
206 //!
207 //! Controls the rate of turning, with positive values for turning right
208 //! and negative values for turning left.
209 double myYaw;
210
211 //! \brief Current yaw (turning) input value from mouse
212 //!
213 //! Additional turning input from mouse movements, added to joystick input.
215
216 //! \brief Current frontend (view) yaw angle
217 //!
218 //! The yaw angle used by the frontend/view system, which may differ
219 //! from the entity's actual orientation.
221
222 //! \brief Current frontend (view) pitch angle
223 //!
224 //! The pitch angle used by the frontend/view system, which controls
225 //! the up/down view direction.
227
228 //! \brief Current posture state of the human entity
229 //!
230 //! Integer representation of the current posture (standing, crouching, etc.)
232
233 //! \brief Flag indicating whether to force posture state
234 //!
235 //! When true, the controller will assert the current posture value
236 //! even if it conflicts with other movement states.
238
239 //! \brief Flag indicating whether to set an absolute yaw value
240 //!
241 //! When true, the controller will set the entity's yaw to the specific
242 //! value in mySetYawValue instead of using incremental turning.
244
245 //! \brief Absolute yaw value to set when mySetYaw is true
246 //!
247 //! The absolute yaw angle (in radians) to set for the entity when
248 //! mySetYaw is true.
250};
251
252} // namespace makVre
double myYaw
Current yaw (turning) input value from joystick.
Definition humanJoystickMovementController.h:209
double mySpeedFactor
Speed multiplier for movement.
Definition humanJoystickMovementController.h:193
DtHumanMovementControlOutputPortGroup * myHumanMovementControlOutputPortGroup
Output port group for human movement control.
Definition humanJoystickMovementController.h:156
DtHumanJoystickMovementController(const DtHumanJoystickMovementController &orig)
Copy constructor (not implemented)
double myTurningRate
Rate of turning in response to inputs.
Definition humanJoystickMovementController.h:187
virtual void joystickConnected() override
Handles joystick connection event.
double myFrontendPitch
Current frontend (view) pitch angle.
Definition humanJoystickMovementController.h:226
bool mySetYaw
Flag indicating whether to set an absolute yaw value.
Definition humanJoystickMovementController.h:243
DtHumanJoystickMovementController(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc, DtReaderWriterRegistry *parentRegistry=0)
Constructor.
virtual bool createPortGroups() override
Creates port groups for this component.
DtBooleanOutputPort * myIsMovingPort
Output port indicating movement state.
Definition humanJoystickMovementController.h:163
DtHumanJoystickMovementController & operator=(const DtHumanJoystickMovementController &orig)
Assignment operator (not implemented)
virtual void calcAndSetPortValues(const DtString &functionGroup, const DtString &function, double value, bool repeat) override
Processes joystick input and updates output ports.
const DtVreHumanJoystickMovementControllerDescriptor * myComponentDescriptor
Pointer to the movement controller descriptor.
Definition humanJoystickMovementController.h:182
DtIntegerOutputPort * myStaticPostureOutputPort
Output port for static posture control.
Definition humanJoystickMovementController.h:170
double myFrontendYaw
Current frontend (view) yaw angle.
Definition humanJoystickMovementController.h:220
double myStrafe
Current strafe (sideways) movement input value.
Definition humanJoystickMovementController.h:203
DtHumanJoystickMovementController()
Default constructor (not implemented)
virtual const char * type() const override
Gets the type identifier for this component.
double myForward
Current forward/backward movement input value.
Definition humanJoystickMovementController.h:198
virtual bool createPorts() override
Creates input and output ports for this component.
virtual ~DtHumanJoystickMovementController() override
Virtual destructor.
DtHumanStateRepository * myHumanStateRepository
Pointer to the human state repository.
Definition humanJoystickMovementController.h:176
double myMouseYaw
Current yaw (turning) input value from mouse.
Definition humanJoystickMovementController.h:214
bool myAssertCurrentPosture
Flag indicating whether to force posture state.
Definition humanJoystickMovementController.h:237
virtual void tick() override
Updates the controller state each simulation frame.
int myCurrentPosture
Current posture state of the human entity.
Definition humanJoystickMovementController.h:231
virtual void joystickDisconnected() override
Handles joystick disconnection 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.
double mySetYawValue
Absolute yaw value to set when mySetYaw is true.
Definition humanJoystickMovementController.h:249
Human joystick movement controller descriptor for VREngage.
Definition vreHumanJoystickMovementControllerDescriptor.h:33
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 DtVreHumanJoystickMovementControllerType[]
Type identifier for the human joystick movement controller component.
Definition humanJoystickMovementController.h:35
Human joystick movement controller descriptor for VREngage.