VR-Engage  2.3
Loading...
Searching...
No Matches
humanLadderClimbingController.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file humanLadderClimbingController.h
7//! \ingroup vreVrfmodel
8//! \brief Joystick controller for human ladder climbing interactions
9//!
10//! This file defines the DtHumanLadderClimbingController class which enables joystick
11//! control of human entity ladder climbing. It provides capabilities for detecting
12//! and interacting with ladders, managing climbing movement, and transitioning between
13//! ground and ladder states.
14
15#pragma once
16
17#include "vreVrfmodel/export.h"
19
21
22#include <vrfobjcore/controllerComponent.h>
23
25
26class DtString;
27class DtSimulationServices;
28class DtJoyDeviceControllerDescriptor;
29class DtJoyDevice;
30class DtHumanMovementControlOutputPortGroup;
31class DtHumanStateRepository;
32class DtBooleanOutputPort;
33class DtIntegerOutputPort;
34class DtAnalogOutputPort;
35class DtSetDataRequest;
36
37namespace makVre
38{
40class DtLadderLocator;
41
42//! \brief Type identifier for the human ladder climbing controller component
43const char DtHumanLadderClimbingControllerType[] = "human-ladder-climbing-controller";
44
45//! \brief Controller for joystick-based ladder climbing interactions for human entities
46//!
47//! DtHumanLadderClimbingController enables joystick control of a human entity's
48//! ladder climbing capabilities. It manages detection of nearby ladders, movement
49//! up and down ladders, and transitions between ground movement and ladder climbing states.
50//! This controller provides realistic ladder interaction behavior including positioning,
51//! orientation, and animation control.
52//!
53//! Uses Descriptor Type: DtVreHumanJoystickMovementControllerDescriptor
56{
57public:
58 //! \brief Constructor
59 //! \param name The name of this component
60 //! \param owner The local object that owns this component
61 //! \param simManager The simulation services manager
62 //! \param desc Component descriptor with configuration parameters
63 //! \param parentRegistry Optional parent registry for reader/writer functionality
64 //!
65 //! Creates a new human ladder climbing controller component with the specified parameters.
66 DtHumanLadderClimbingController(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
67 DtComponentDescriptor* desc, DtReaderWriterRegistry* parentRegistry = 0);
68
69 //! \brief Virtual destructor
70 //!
71 //! Cleans up resources used by the human ladder climbing controller component.
73
74 //! \brief Gets the type identifier for this component
75 //! \return String identifying the component type (DtHumanLadderClimbingControllerType)
76 //!
77 //! Implements the DtSimComponent::type() method to return the
78 //! type identifier for this component.
79 virtual const char* type() const override;
80
81 //! \brief Calls base first-tick initialization and restores incoming joystick state.
82 virtual void preFirstTickInit() override;
83
84 //! \brief Creates input and output ports for this component
85 //! \return True if ports were created successfully, false otherwise
86 //!
87 //! Creates and initializes all input and output ports used by this controller
88 //! for ladder climbing-related functions.
89 virtual bool createPorts() override;
90
91 //! \brief Initializes the component
92 //! \return True if initialization is successful, false otherwise
93 //!
94 //! Performs component initialization, setting up internal state and
95 //! configuring initial ladder climbing parameters.
96 virtual bool init() override;
97
98 //! \brief Updates the controller state each simulation frame
99 //!
100 //! Processes ladder climbing-related controls and updates the human entity's
101 //! movement on ladders based on current joystick inputs. Also handles detection
102 //! of ladders and transitions between ground and ladder states.
103 virtual void tick() override;
104
105 //! \brief Factory method to create a new instance of this component
106 //! \param name The name for the new component
107 //! \param owner The local object that will own this component
108 //! \param simManager The simulation services manager
109 //! \param desc Optional component descriptor
110 //! \param parentRegistry Optional parent registry for reader/writer functionality
111 //! \return Pointer to the newly created component
112 //!
113 //! Static factory method used by the component creation system to instantiate
114 //! new instances of this component type.
115 static DtSimComponent* creator(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
116 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
117
118private:
119 //! \brief Default constructor (not implemented)
120 //!
121 //! Default constructor is private and not implemented to prevent
122 //! creation of instances without proper initialization.
124
125 //! \brief Copy constructor (not implemented)
126 //!
127 //! Copy constructor is private and not implemented to prevent
128 //! copy construction.
130
131 //! \brief Assignment operator (not implemented)
132 //! \return Reference to this object
133 //!
134 //! Assignment operator is private and not implemented to prevent assignment.
136
137protected:
138 //! \brief Processes joystick input and updates output ports
139 //! \param functionGroup The function group identifier for the input
140 //! \param function The specific function identifier within the group
141 //! \param value The input value from the joystick
142 //! \param repeat Flag indicating if this is a repeated input
143 //!
144 //! Implements the DtJoystickControllerInterface method to process joystick
145 //! input and update the controller's output ports for ladder climbing functions.
147 const DtString& functionGroup, const DtString& function, double value, bool repeat) override;
148
149 //! \brief Handles joystick connection event
150 //!
151 //! Called when a joystick is connected to the system.
152 //! Activates joystick control mode for ladder climbing functions.
153 virtual void joystickConnected() override;
154
155 //! \brief Handles joystick disconnection event
156 //!
157 //! Called when a joystick is disconnected from the system.
158 //! Deactivates joystick control mode for ladder climbing functions.
159 virtual void joystickDisconnected() override;
160
161 //! \brief Retrieves and caches the ladder climbing process state repository
162 //!
163 //! Gets a pointer to the DtVreLadderClimbingPSR which is created by another component.
164 //! This process state repository contains the ladder climbing state information
165 //! that is shared between multiple components.
167
168 //! \brief Performs initialization after all entity components are created
169 //! \return True if post-initialization is successful, false otherwise
170 //!
171 //! Called after all entity components have been created and initialized.
172 //! Calls lookupAndCacheProcessSR() to retrieve a pointer to the ladder climbing
173 //! process state repository.
174 virtual bool postAddComponentsInit() override;
175
176 //! \brief Initializes ladder movement control
177 //! \return True if initialization is successful, false otherwise
178 //!
179 //! Sets up the initial state for ladder movement control, including
180 //! configuration parameters and movement limits.
182
183 //! \brief Updates ladder movement control each simulation frame
184 //!
185 //! Performs the per-frame update of ladder climbing movement based on
186 //! current inputs and entity state. Handles movement up and down ladders.
188 //! \brief Checks if the entity is at a ladder position
189 //! \param ladder Reference to the ladder to check
190 //! \param accessPoint Output parameter to store the ladder access point
191 //! \return True if entity is at the ladder, false otherwise
192 //!
193 //! Determines if the entity is at a position where it can access the ladder.
194 //! Updates the accessPoint parameter with the closest ladder access point.
195 virtual bool atLadder(DtLadder& ladder, DtVector& accessPoint);
196 //! \brief Checks if the entity is at a specific ladder access point
197 //! \param localPosition The entity's current local position
198 //! \param ladderAccessPoint The ladder access point to check against
199 //! \param radiusSquared The squared radius to consider as "at" the access point
200 //! \return True if entity is at the ladder access point, false otherwise
201 //!
202 //! Determines if the entity is close enough to a ladder access point to
203 //! be considered "at" that point based on the specified distance threshold.
205 const DtVector& localPosition, const DtVector& ladderAccessPoint, double radiusSquared);
206 //! \brief Checks if the entity is at a ladder exit point
207 //! \param ladder The ladder to check
208 //! \param ladderAccessPoint Output parameter to store the ladder access point
209 //! \param ladderTerrainAccessPoint Output parameter to store the terrain access point
210 //! \return True if entity is at a ladder exit point, false otherwise
211 //!
212 //! Determines if the entity is at a position where it can exit the ladder.
213 //! Updates the output parameters with the access and terrain points.
214 virtual bool atLadderExitPoint(
215 const DtLadder& ladder, DtVector& ladderAccessPoint, DtVector& ladderTerrainAccessPoint);
216 //! \brief Sets the nearest ladder information and updates access point
217 //! \param ladder The ladder to set as nearest
218 //! \param ladderAccessPoint The access point for the ladder
219 //!
220 //! Updates the process state with information about the nearest ladder
221 //! and the access point that the entity should use to get on that ladder.
222 virtual void setNearestLadderAndGetOnLadderPoint(const DtLadder& ladder, const DtVector& ladderAccessPoint);
223 //! \brief Sets the entity's position
224 //! \param localPosition The new local position for the entity
225 //!
226 //! Updates the entity's position, typically used when snapping the entity
227 //! to a specific position on a ladder.
228 virtual void setEntityLocation(const DtVector& localPosition);
229 //! \brief Sets the entity's heading/orientation
230 //! \param heading The new heading angle in radians
231 //!
232 //! Updates the entity's heading, typically used to orient the entity
233 //! to face the ladder properly during climbing.
234 virtual void setEntityHeading(double heading);
235 //! \brief Sends a data request to update entity state
236 //! \param setRequest Pointer to the data request to send
237 //!
238 //! Sends a data request to modify entity state, typically used to update
239 //! position, orientation, or other properties during ladder interaction.
240 virtual void sendDataRequest(DtSetDataRequest* setRequest);
241 //! \brief Instructs the entity to stow its weapon
242 //!
243 //! Requests that the entity stow its weapon during ladder climbing,
244 //! since weapons cannot be used while climbing a ladder.
245 virtual void stowWeapon();
246 //! \brief Enables ladder climbing animation
247 //!
248 //! Sets the appropriate animation state to show the entity
249 //! climbing a ladder.
251
252 //! \brief Disables ladder climbing animation
253 //!
254 //! Reverts to normal movement animations when the entity is no
255 //! longer climbing a ladder.
257 //! \brief Checks if the entity is facing a ladder
258 //! \param ladder The ladder to check
259 //! \param ladderAccessPoint The access point for the ladder
260 //! \return True if the entity is facing the ladder, false otherwise
261 //!
262 //! Determines if the entity's current heading/orientation has it
263 //! facing toward the ladder, which is required to begin climbing.
264 virtual bool facingLadder(const DtLadder& ladder, const DtVector& ladderAccessPoint);
265 //! \brief Snaps the entity to a ladder position
266 //! \param ladderAccessPoint The access point on the ladder
267 //! \param offset The offset from the access point to position the entity
268 //! \param heading The heading to set for the entity
269 //!
270 //! Positions the entity precisely on a ladder with the correct orientation
271 //! for climbing. Applies the specified offset to prevent clipping with the ladder.
272 virtual void snapToLadder(const DtVector& ladderAccessPoint, const DtVector& offset, double heading);
273 //! \brief Calculates the local standoff vector from a ladder
274 //! \param ladder The ladder to calculate standoff from
275 //! \return The local standoff vector
276 //!
277 //! Calculates the appropriate standoff vector to position the entity at
278 //! the correct distance from the ladder during climbing. This prevents the
279 //! entity from clipping through the ladder geometry.
280 virtual DtVector localStandoffFromLadder(const DtLadder& ladder) const;
281
282protected:
283 //! \name Ports and Port Groups
284 //! @{
285
286 //! \brief Output port for ladder climbing movement direction
287 //!
288 //! Indicates the direction of climbing movement on a ladder. Negative values
289 //! indicate climbing down, positive values indicate climbing up, with the range
290 //! from -1.0 to 1.0. Used to control the animation and movement speed.
292
293 //!@}
294
295 //! \brief Current forward/backward movement input value
296 //!
297 //! Stores the value for joystick input, with values ranging from
298 //! -1.0 (climbing down) to 1.0 (climbing up).
299 double myForward;
300
301 //! \brief Pointer to the ladder climbing process state repository
302 //!
303 //! Stores state data associated with ladder climbing. This process state
304 //! repository is shared with other components and is created and destroyed
305 //! by another component. The state is saved and restored as part of a
306 //! scenario or checkpoint.
308
309
310 //! \brief Maximum speed when climbing ladders
311 //!
312 //! The maximum speed at which the entity can climb up or down ladders,
313 //! cached from the component descriptor.
315
316 //! \brief Helper class for locating ladders
317 //!
318 //! Utility object used to find the nearest ladder and access points
319 //! around the entity's current position.
321
322protected:
323 //! \brief Search radius for finding nearby ladders
324 //!
325 //! The radius (in meters) within which to search for ladders around
326 //! the entity's current position. Default is 5 meters.
328
329 //! \brief Squared distance threshold for being on a ladder
330 //!
331 //! The squared distance (in meters squared) threshold for determining if an
332 //! entity is at a ladder access point when already on the ladder. Default is
333 //! 0.25 m² (equivalent to a 0.5 m distance).
335
336 //! \brief Squared distance threshold when approaching ladders
337 //!
338 //! The squared distance (in meters squared) threshold for determining if an
339 //! entity is at a ladder access point when approaching the ladder. Default is
340 //! 1.0 m². Must be less than theLeavingAtLadderPointDistanceSqr to allow the
341 //! entity to escape a ladder without automatically re-engaging.
343
344 //! \brief Squared distance threshold when leaving ladders
345 //!
346 //! The squared distance (in meters squared) threshold for determining if an
347 //! entity is at a ladder access point when leaving the ladder. Default is
348 //! 1.25 m². Must be greater than theApproachingAtLadderPointDistanceSqr to allow
349 //! the entity to escape a ladder without automatically re-engaging.
351
352 //! \brief Half-angle for determining if entity is facing a location
353 //!
354 //! If a given location falls within this angle of the entity's current heading,
355 //! the entity is considered to be facing that location. Measured in radians.
356 //! Default is 22.5 degrees (approximately 0.393 radians).
358
359 //! \brief Time required to get on/off a ladder at the top
360 //!
361 //! The time (in seconds) it takes for an entity to complete the transition
362 //! animation and state change when getting on or off a ladder at the top.
364
365 //! \brief Distance to maintain between entity and ladder
366 //!
367 //! The offset distance (in meters) from the ladder needed to prevent the
368 //! entity's body from appearing embedded in the ladder geometry when
369 //! climbing up or down.
371
372 //! \brief Squared half-length of a typical ladder
373 //!
374 //! The squared value of half the maximum ladder length (in meters squared).
375 //! Assuming a maximum ladder length of 16ft (≈5m), half-length is 8ft (≈2.5m),
376 //! so this value is 6.25 m². Used in distance calculations during climbing.
378};
379
380} // namespace makVre
DtLadderLocator * myLadderLocator
Helper class for locating ladders.
Definition humanLadderClimbingController.h:320
virtual void stowWeapon()
Instructs the entity to stow its weapon.
virtual void snapToLadder(const DtVector &ladderAccessPoint, const DtVector &offset, double heading)
Snaps the entity to a ladder position.
virtual void enableLadderClimbingAnimation()
Enables ladder climbing animation.
virtual void joystickDisconnected() override
Handles joystick disconnection event.
virtual const char * type() const override
Gets the type identifier for this component.
virtual bool facingLadder(const DtLadder &ladder, const DtVector &ladderAccessPoint)
Checks if the entity is facing a ladder.
virtual void setEntityLocation(const DtVector &localPosition)
Sets the entity's position.
static double theLeavingAtLadderPointDistanceSqr
Squared distance threshold when leaving ladders.
Definition humanLadderClimbingController.h:350
static double theApproachingAtLadderPointDistanceSqr
Squared distance threshold when approaching ladders.
Definition humanLadderClimbingController.h:342
virtual bool atLadderExitPoint(const DtLadder &ladder, DtVector &ladderAccessPoint, DtVector &ladderTerrainAccessPoint)
Checks if the entity is at a ladder exit point.
static double theTimeItTakesToGetOnOffLadderAtTop
Time required to get on/off a ladder at the top.
Definition humanLadderClimbingController.h:363
virtual void tick() override
Updates the controller state each simulation frame.
virtual bool init() override
Initializes the component.
static double theHalfLadderLengthSquared
Squared half-length of a typical ladder.
Definition humanLadderClimbingController.h:377
static double theFacingHalfAzimuthAngle
Half-angle for determining if entity is facing a location.
Definition humanLadderClimbingController.h:357
static double theLadderSearchRadius
Search radius for finding nearby ladders.
Definition humanLadderClimbingController.h:327
DtHumanLadderClimbingController()
Default constructor (not implemented)
double myMaxLadderClimbingSpeed
Maximum speed when climbing ladders.
Definition humanLadderClimbingController.h:314
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 void tickLadderMovementControl()
Updates ladder movement control each simulation frame.
virtual void sendDataRequest(DtSetDataRequest *setRequest)
Sends a data request to update entity state.
DtHumanLadderClimbingController(const DtHumanLadderClimbingController &orig)
Copy constructor (not implemented)
virtual void disableLadderClimbingAnimation()
Disables ladder climbing animation.
DtVreLadderClimbingPSR * myProcessState
Pointer to the ladder climbing process state repository.
Definition humanLadderClimbingController.h:307
virtual bool initLadderMovementControl()
Initializes ladder movement control.
DtHumanLadderClimbingController(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc, DtReaderWriterRegistry *parentRegistry=0)
Constructor.
virtual void setEntityHeading(double heading)
Sets the entity's heading/orientation.
static double theOnLadderAtLadderPointDistanceSqr
Squared distance threshold for being on a ladder.
Definition humanLadderClimbingController.h:334
double myForward
Current forward/backward movement input value.
Definition humanLadderClimbingController.h:299
virtual void preFirstTickInit() override
Calls base first-tick initialization and restores incoming joystick state.
virtual void setNearestLadderAndGetOnLadderPoint(const DtLadder &ladder, const DtVector &ladderAccessPoint)
Sets the nearest ladder information and updates access point.
virtual void calcAndSetPortValues(const DtString &functionGroup, const DtString &function, double value, bool repeat) override
Processes joystick input and updates output ports.
virtual ~DtHumanLadderClimbingController() override
Virtual destructor.
static double theStandoffDistanceFromLadder
Distance to maintain between entity and ladder.
Definition humanLadderClimbingController.h:370
virtual void lookupAndCacheProcessSR()
Retrieves and caches the ladder climbing process state repository.
DtHumanLadderClimbingController & operator=(const DtHumanLadderClimbingController &orig)
Assignment operator (not implemented)
DtAnalogOutputPort * myLadderClimbingMovementDirectionPort
Output port for ladder climbing movement direction.
Definition humanLadderClimbingController.h:291
virtual bool atLadder(DtLadder &ladder, DtVector &accessPoint)
Checks if the entity is at a ladder position.
virtual bool createPorts() override
Creates input and output ports for this component.
virtual DtVector localStandoffFromLadder(const DtLadder &ladder) const
Calculates the local standoff vector from a ladder.
virtual bool atLadderAccessPoint(const DtVector &localPosition, const DtVector &ladderAccessPoint, double radiusSquared)
Checks if the entity is at a specific ladder access point.
virtual bool postAddComponentsInit() override
Performs initialization after all entity components are created.
virtual void joystickConnected() override
Handles joystick connection event.
Helper class that represents a climbable ladder in simulations.
Definition ladder.h:35
Helper class for finding ladders and their access points in simulations.
Definition ladderLocator.h:36
DtVreJoystickControllerInterface(DtSimComponent *component, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc)
Constructs an interface alongside an existing component base.
Process state repository for ladder climbing components.
Definition vreLadderClimbingPSR.h:61
DtVreSimComponent(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Definition vreSimComponent.h:63
Defines export macros for the vreVrfmodel library.
#define VREVRFMODEL_DLL
Definition export.h:22
!
Definition glsVreMessageUtil.h:50
const char DtHumanLadderClimbingControllerType[]
Type identifier for the human ladder climbing controller component.
Definition humanLadderClimbingController.h:43
Internal-state persistence for VRE joystick controllers.
Ladder climbing process state repository for VREngage.
Base template class for VR-Engage simulation components.