VR-Engage  2.2
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
24#include <vrfmodel/joystickControllerInterface.h>
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
55 public DtJoystickControllerInterface
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 Creates input and output ports for this component
82 //! \return True if ports were created successfully, false otherwise
83 //!
84 //! Creates and initializes all input and output ports used by this controller
85 //! for ladder climbing-related functions.
86 virtual bool createPorts() override;
87
88 //! \brief Initializes the component
89 //! \return True if initialization is successful, false otherwise
90 //!
91 //! Performs component initialization, setting up internal state and
92 //! configuring initial ladder climbing parameters.
93 virtual bool init() override;
94
95 //! \brief Updates the controller state each simulation frame
96 //!
97 //! Processes ladder climbing-related controls and updates the human entity's
98 //! movement on ladders based on current joystick inputs. Also handles detection
99 //! of ladders and transitions between ground and ladder states.
100 virtual void tick() override;
101
102 //! \brief Factory method to create a new instance of this component
103 //! \param name The name for the new component
104 //! \param owner The local object that will own this component
105 //! \param simManager The simulation services manager
106 //! \param desc Optional component descriptor
107 //! \param parentRegistry Optional parent registry for reader/writer functionality
108 //! \return Pointer to the newly created component
109 //!
110 //! Static factory method used by the component creation system to instantiate
111 //! new instances of this component type.
112 static DtSimComponent* creator(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
113 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
114
115private:
116 //! \brief Default constructor (not implemented)
117 //!
118 //! Default constructor is private and not implemented to prevent
119 //! creation of instances without proper initialization.
121
122 //! \brief Copy constructor (not implemented)
123 //!
124 //! Copy constructor is private and not implemented to prevent
125 //! copy construction.
127
128 //! \brief Assignment operator (not implemented)
129 //! \return Reference to this object
130 //!
131 //! Assignment operator is private and not implemented to prevent assignment.
133
134protected:
135 //! \brief Processes joystick input and updates output ports
136 //! \param functionGroup The function group identifier for the input
137 //! \param function The specific function identifier within the group
138 //! \param value The input value from the joystick
139 //! \param repeat Flag indicating if this is a repeated input
140 //!
141 //! Implements the DtJoystickControllerInterface method to process joystick
142 //! input and update the controller's output ports for ladder climbing functions.
144 const DtString& functionGroup, const DtString& function, double value, bool repeat) override;
145
146 //! \brief Handles joystick connection event
147 //!
148 //! Called when a joystick is connected to the system.
149 //! Activates joystick control mode for ladder climbing functions.
150 virtual void joystickConnected() override;
151
152 //! \brief Handles joystick disconnection event
153 //!
154 //! Called when a joystick is disconnected from the system.
155 //! Deactivates joystick control mode for ladder climbing functions.
156 virtual void joystickDisconnected() override;
157
158 //! \brief Retrieves and caches the ladder climbing process state repository
159 //!
160 //! Gets a pointer to the DtVreLadderClimbingPSR which is created by another component.
161 //! This process state repository contains the ladder climbing state information
162 //! that is shared between multiple components.
164
165 //! \brief Performs initialization after all entity components are created
166 //! \return True if post-initialization is successful, false otherwise
167 //!
168 //! Called after all entity components have been created and initialized.
169 //! Calls lookupAndCacheProcessSR() to retrieve a pointer to the ladder climbing
170 //! process state repository.
171 virtual bool postAddComponentsInit() override;
172
173 //! \brief Initializes ladder movement control
174 //! \return True if initialization is successful, false otherwise
175 //!
176 //! Sets up the initial state for ladder movement control, including
177 //! configuration parameters and movement limits.
179
180 //! \brief Updates ladder movement control each simulation frame
181 //!
182 //! Performs the per-frame update of ladder climbing movement based on
183 //! current inputs and entity state. Handles movement up and down ladders.
185 //! \brief Checks if the entity is at a ladder position
186 //! \param ladder Reference to the ladder to check
187 //! \param accessPoint Output parameter to store the ladder access point
188 //! \return True if entity is at the ladder, false otherwise
189 //!
190 //! Determines if the entity is at a position where it can access the ladder.
191 //! Updates the accessPoint parameter with the closest ladder access point.
192 virtual bool atLadder(DtLadder& ladder, DtVector& accessPoint);
193 //! \brief Checks if the entity is at a specific ladder access point
194 //! \param localPosition The entity's current local position
195 //! \param ladderAccessPoint The ladder access point to check against
196 //! \param radiusSquared The squared radius to consider as "at" the access point
197 //! \return True if entity is at the ladder access point, false otherwise
198 //!
199 //! Determines if the entity is close enough to a ladder access point to
200 //! be considered "at" that point based on the specified distance threshold.
202 const DtVector& localPosition, const DtVector& ladderAccessPoint, double radiusSquared);
203 //! \brief Checks if the entity is at a ladder exit point
204 //! \param ladder The ladder to check
205 //! \param ladderAccessPoint Output parameter to store the ladder access point
206 //! \param ladderTerrainAccessPoint Output parameter to store the terrain access point
207 //! \return True if entity is at a ladder exit point, false otherwise
208 //!
209 //! Determines if the entity is at a position where it can exit the ladder.
210 //! Updates the output parameters with the access and terrain points.
211 virtual bool atLadderExitPoint(
212 const DtLadder& ladder, DtVector& ladderAccessPoint, DtVector& ladderTerrainAccessPoint);
213 //! \brief Sets the nearest ladder information and updates access point
214 //! \param ladder The ladder to set as nearest
215 //! \param ladderAccessPoint The access point for the ladder
216 //!
217 //! Updates the process state with information about the nearest ladder
218 //! and the access point that the entity should use to get on that ladder.
219 virtual void setNearestLadderAndGetOnLadderPoint(const DtLadder& ladder, const DtVector& ladderAccessPoint);
220 //! \brief Sets the entity's position
221 //! \param localPosition The new local position for the entity
222 //!
223 //! Updates the entity's position, typically used when snapping the entity
224 //! to a specific position on a ladder.
225 virtual void setEntityLocation(const DtVector& localPosition);
226 //! \brief Sets the entity's heading/orientation
227 //! \param heading The new heading angle in radians
228 //!
229 //! Updates the entity's heading, typically used to orient the entity
230 //! to face the ladder properly during climbing.
231 virtual void setEntityHeading(double heading);
232 //! \brief Sends a data request to update entity state
233 //! \param setRequest Pointer to the data request to send
234 //!
235 //! Sends a data request to modify entity state, typically used to update
236 //! position, orientation, or other properties during ladder interaction.
237 virtual void sendDataRequest(DtSetDataRequest* setRequest);
238 //! \brief Instructs the entity to stow its weapon
239 //!
240 //! Requests that the entity stow its weapon during ladder climbing,
241 //! since weapons cannot be used while climbing a ladder.
242 virtual void stowWeapon();
243 //! \brief Enables ladder climbing animation
244 //!
245 //! Sets the appropriate animation state to show the entity
246 //! climbing a ladder.
248
249 //! \brief Disables ladder climbing animation
250 //!
251 //! Reverts to normal movement animations when the entity is no
252 //! longer climbing a ladder.
254 //! \brief Checks if the entity is facing a ladder
255 //! \param ladder The ladder to check
256 //! \param ladderAccessPoint The access point for the ladder
257 //! \return True if the entity is facing the ladder, false otherwise
258 //!
259 //! Determines if the entity's current heading/orientation has it
260 //! facing toward the ladder, which is required to begin climbing.
261 virtual bool facingLadder(const DtLadder& ladder, const DtVector& ladderAccessPoint);
262 //! \brief Snaps the entity to a ladder position
263 //! \param ladderAccessPoint The access point on the ladder
264 //! \param offset The offset from the access point to position the entity
265 //! \param heading The heading to set for the entity
266 //!
267 //! Positions the entity precisely on a ladder with the correct orientation
268 //! for climbing. Applies the specified offset to prevent clipping with the ladder.
269 virtual void snapToLadder(const DtVector& ladderAccessPoint, const DtVector& offset, double heading);
270 //! \brief Calculates the local standoff vector from a ladder
271 //! \param ladder The ladder to calculate standoff from
272 //! \return The local standoff vector
273 //!
274 //! Calculates the appropriate standoff vector to position the entity at
275 //! the correct distance from the ladder during climbing. This prevents the
276 //! entity from clipping through the ladder geometry.
277 virtual DtVector localStandoffFromLadder(const DtLadder& ladder) const;
278
279protected:
280 //! \name Ports and Port Groups
281 //! @{
282
283 //! \brief Output port for ladder climbing movement direction
284 //!
285 //! Indicates the direction of climbing movement on a ladder. Negative values
286 //! indicate climbing down, positive values indicate climbing up, with the range
287 //! from -1.0 to 1.0. Used to control the animation and movement speed.
289
290 //!@}
291
292 //! \brief Current forward/backward movement input value
293 //!
294 //! Stores the value for joystick input, with values ranging from
295 //! -1.0 (climbing down) to 1.0 (climbing up).
296 double myForward;
297
298 //! \brief Pointer to the ladder climbing process state repository
299 //!
300 //! Stores state data associated with ladder climbing. This process state
301 //! repository is shared with other components and is created and destroyed
302 //! by another component. The state is saved and restored as part of a
303 //! scenario or checkpoint.
305
306
307 //! \brief Maximum speed when climbing ladders
308 //!
309 //! The maximum speed at which the entity can climb up or down ladders,
310 //! cached from the component descriptor.
312
313 //! \brief Helper class for locating ladders
314 //!
315 //! Utility object used to find the nearest ladder and access points
316 //! around the entity's current position.
318
319protected:
320 //! \brief Search radius for finding nearby ladders
321 //!
322 //! The radius (in meters) within which to search for ladders around
323 //! the entity's current position. Default is 5 meters.
325
326 //! \brief Squared distance threshold for being on a ladder
327 //!
328 //! The squared distance (in meters squared) threshold for determining if an
329 //! entity is at a ladder access point when already on the ladder. Default is
330 //! 0.25 m² (equivalent to a 0.5 m distance).
332
333 //! \brief Squared distance threshold when approaching ladders
334 //!
335 //! The squared distance (in meters squared) threshold for determining if an
336 //! entity is at a ladder access point when approaching the ladder. Default is
337 //! 1.0 m². Must be less than theLeavingAtLadderPointDistanceSqr to allow the
338 //! entity to escape a ladder without automatically re-engaging.
340
341 //! \brief Squared distance threshold when leaving ladders
342 //!
343 //! The squared distance (in meters squared) threshold for determining if an
344 //! entity is at a ladder access point when leaving the ladder. Default is
345 //! 1.25 m². Must be greater than theApproachingAtLadderPointDistanceSqr to allow
346 //! the entity to escape a ladder without automatically re-engaging.
348
349 //! \brief Half-angle for determining if entity is facing a location
350 //!
351 //! If a given location falls within this angle of the entity's current heading,
352 //! the entity is considered to be facing that location. Measured in radians.
353 //! Default is 22.5 degrees (approximately 0.393 radians).
355
356 //! \brief Time required to get on/off a ladder at the top
357 //!
358 //! The time (in seconds) it takes for an entity to complete the transition
359 //! animation and state change when getting on or off a ladder at the top.
361
362 //! \brief Distance to maintain between entity and ladder
363 //!
364 //! The offset distance (in meters) from the ladder needed to prevent the
365 //! entity's body from appearing embedded in the ladder geometry when
366 //! climbing up or down.
368
369 //! \brief Squared half-length of a typical ladder
370 //!
371 //! The squared value of half the maximum ladder length (in meters squared).
372 //! Assuming a maximum ladder length of 16ft (≈5m), half-length is 8ft (≈2.5m),
373 //! so this value is 6.25 m². Used in distance calculations during climbing.
375};
376
377} // namespace makVre
DtLadderLocator * myLadderLocator
Helper class for locating ladders.
Definition humanLadderClimbingController.h:317
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:347
static double theApproachingAtLadderPointDistanceSqr
Squared distance threshold when approaching ladders.
Definition humanLadderClimbingController.h:339
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:360
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:374
static double theFacingHalfAzimuthAngle
Half-angle for determining if entity is facing a location.
Definition humanLadderClimbingController.h:354
static double theLadderSearchRadius
Search radius for finding nearby ladders.
Definition humanLadderClimbingController.h:324
DtHumanLadderClimbingController()
Default constructor (not implemented)
double myMaxLadderClimbingSpeed
Maximum speed when climbing ladders.
Definition humanLadderClimbingController.h:311
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:304
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:331
double myForward
Current forward/backward movement input value.
Definition humanLadderClimbingController.h:296
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:367
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:288
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
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:54
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 DtHumanLadderClimbingControllerType[]
Type identifier for the human ladder climbing controller component.
Definition humanLadderClimbingController.h:43
Ladder climbing process state repository for VREngage.
Base template class for VR-Engage simulation components.