VR-Engage  2.2
Loading...
Searching...
No Matches
exampleHumanArtPartActuator.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies, Inc.
3** All rights reserved.
4*******************************************************************************/
5
6//! \file exampleHumanArtPartActuator.h
7//! \brief Actuator component demonstrating control of DI-Guy human character joints
8//!
9//! DtExampleHumanArtPartActuator shows how to manipulate articulated parts (joints)
10//! on human characters in VR-Forces. This example animates the left shoulder joint
11//! of a DI-Guy character, demonstrating the complete pattern for controlling human
12//! skeleton articulation from simulation logic.
13//!
14//! Key Patterns Demonstrated:
15//! - VR-Forces actuator component lifecycle (init, tick)
16//! - DI-Guy articulated part lookup and manipulation
17//! - Smooth joint animation using sinusoidal interpolation
18//! - Pause-aware animation (handling simulation pause/resume)
19//! - Platform-specific component access via DtPlatformLocalObjectFacade
20//!
21//! Use Cases:
22//! This pattern enables:
23//! - Procedural character animation (waving, gesturing, pointing)
24//! - Injury modeling (limping, holding injured limbs)
25//! - Equipment interaction (carrying objects, operating controls)
26//! - Behavioral animation (soldier hand signals, crew actions)
27//! - Motion capture playback (replaying recorded joint angles)
28
29#pragma once
30
31#include <vrfobjcore/actuatorComponent.h>
32#include <vrfobjcore/platformLocalObjectFacade.h>
33
34namespace makVre
35{
36//! Type identifier string for human articulated part actuator component
37constexpr char DtExampleHumanArtPartActuatorType[] = "vre-example-human-art-part-actuator";
38
39//! \brief Actuator component that animates DI-Guy human character joints
40//!
41//! PATTERN: VR-Forces Actuator Components
42//! Actuator components execute simulation-side logic on entities, controlling their
43//! behavior, appearance, and state. They are the simulation engine counterpart to
44//! player station components (DtPlayerComponent).
45//!
46//! Common Actuator Component Types:
47//! - Motion actuators: Control entity movement and navigation
48//! - Weapon actuators: Manage firing, reloading, aiming
49//! - Sensor actuators: Simulate detection and tracking
50//! - Animation actuators: Control visual appearance and articulation (this example)
51//! - Communication actuators: Handle radio and data link simulation
52//!
53//! Actuator Lifecycle:
54//! 1. Construction with entity owner and simulation services
55//! 2. init() called once after construction for initialization
56//! 3. tick() called every simulation frame to update state
57//! 4. Destruction when entity is removed or component detached
58//!
59//! DI-Guy Articulated Parts:
60//! DI-Guy human characters use a skeletal system with named joints (articulated parts).
61//! Each joint can be controlled via:
62//! - Azimuth: Rotation around vertical axis (yaw)
63//! - Elevation: Rotation around lateral axis (pitch)
64//! - Rotation: Rotation around forward axis (roll)
65//! - Angular rates: Velocities for smooth interpolation
66//!
67//! This Example:
68//! Animates the left shoulder joint with a sinusoidal motion, demonstrating:
69//! - Articulated part lookup by DI-Guy joint identifier
70//! - Setting joint angles and angular rates for smooth motion
71//! - Pause-aware animation (stops during simulation pause)
72//! - Continuous cyclical animation using time accumulation
73//!
74//! REUSABLE: This class structure applies to any actuator that needs to control
75//! human character articulation. Replace the joint identifier and animation logic
76//! to control different joints or implement different motion patterns.
77//!
78class DtExampleHumanArtPartActuator : public DtActuatorComponent
79{
80public:
81 //! \brief Constructor - Initialize actuator component for an entity
82 //!
83 //! PATTERN: VR-Forces Component Construction
84 //! VR-Forces components are constructed with references to:
85 //! - name: Component instance identifier (for debugging and logging)
86 //! - owner: The entity (DtLocalObject) this component belongs to
87 //! - simManager: Access to simulation services (time, messaging, etc.)
88 //! - desc: Component descriptor from entity definition (configuration)
89 //! - parentRegistry: Reader-writer registry for parameter serialization
90 //!
91 //! The owner provides access to entity state and other components. The
92 //! DtPlatformLocalObjectFacade helper class simplifies access to platform-specific
93 //! features like articulated parts.
94 //!
95 //! \param name Component instance name
96 //! \param owner Owning entity
97 //! \param simManager Simulation services access
98 //! \param desc Component descriptor with configuration parameters
99 //! \param parentRegistry Parent registry for parameter serialization
100 //!
101 DtExampleHumanArtPartActuator(const DtString& name,
102 DtLocalObject* owner,
103 DtSimulationServices* simManager,
104 DtComponentDescriptor* desc = nullptr,
105 DtReaderWriterRegistry* parentRegistry = nullptr);
106
107 //! Default constructor - deleted (components require owner and services)
109
110 //! Copy constructor - deleted (components are not copyable)
112
113 //! Assignment operator - deleted (components are not assignable)
115
116 //! Destructor - cleanup component resources
118
119public:
120 //! \brief Initialize component after construction
121 //!
122 //! PATTERN: VR-Forces Component Initialization
123 //! The init() method is called once after construction to perform initialization
124 //! that may depend on other components or simulation state. Always call the
125 //! base class init() first to ensure proper initialization order.
126 //!
127 //! This Example:
128 //! Performs only base class initialization. Articulated part lookup is deferred
129 //! to the first tick() call to ensure the entity's articulated part system is
130 //! fully initialized.
131 //!
132 //! \return true if initialization succeeded, false on failure
133 //!
134 virtual bool init() override;
135
136 //! \brief Return component type identifier string
137 //!
138 //! Used by VR-Forces factory system to identify component type for instantiation
139 //! and serialization. Must match the type string used in component registration.
140 //!
141 //! \return DtExampleHumanArtPartActuatorType constant
142 //!
143 virtual const char* type() const override;
144
145 //! \brief Update component state for one simulation frame
146 //!
147 //! PATTERN: Articulated Part Animation
148 //! This method demonstrates the complete pattern for animating DI-Guy joints:
149 //!
150 //! 1. Check for simulation pause (dT() == 0) and stop motion if paused
151 //! 2. Lazy lookup articulated part on first tick (ensures entity is initialized)
152 //! 3. Calculate desired joint angle and rate based on animation time
153 //! 4. Set joint angles (azimuth, elevation, rotation) and rates
154 //!
155 //! Smooth Animation:
156 //! Setting both the target angle and the angular rate produces smooth interpolated
157 //! motion. VR-Forces/DI-Guy interpolates between the current and target angles
158 //! using the provided rate.
159 //!
160 //! Animation Pattern Used:
161 //! Sinusoidal motion from 0 to π/2 radians over myAnimationInterval seconds:
162 //! - angle = maxAngle * sin(theta)
163 //! - rate = derivative of angle with respect to time
164 //!
165 //! REUSABLE: This animation pattern can be adapted for:
166 //! - Different joints (change DiGuyDisArtPartShoulderLeft to other joint IDs)
167 //! - Different motion types (linear, ease-in/out, keyframed)
168 //! - Multiple simultaneous joint animations (lookup and animate multiple parts)
169 //! - Triggered animations (respond to events rather than continuous cycles)
170 //!
171 virtual void tick() override;
172
173 //! \brief Static factory creator method for component instantiation
174 //!
175 //! PATTERN: VR-Forces Component Factory
176 //! VR-Forces uses factory methods to instantiate components from entity definitions.
177 //! This static method must match the signature expected by the component factory
178 //! and return a new instance of this component class.
179 //!
180 //! Registered in plugin initialization:
181 //! componentFactory()->addCreatorFcn(DtExampleHumanArtPartActuatorType,
182 //! &DtExampleHumanArtPartActuator::creator);
183 //!
184 //! REUSABLE: This exact signature is required for all VR-Forces components.
185 //!
186 //! \param name Component instance name
187 //! \param owner Owning entity
188 //! \param simManager Simulation services access
189 //! \param desc Component descriptor with configuration
190 //! \param parentRegistry Parent registry for parameters
191 //! \return New component instance
192 //!
193 static DtSimComponent* creator(const DtString& name,
194 DtLocalObject* owner,
195 DtSimulationServices* simManager,
196 DtComponentDescriptor* desc = nullptr,
197 DtReaderWriterRegistry* parentRegistry = nullptr);
198
199protected:
200 //! Facade providing convenient access to platform-specific entity features
201 //! Simplifies access to articulated parts, sensors, weapons, and other
202 //! platform subsystems
203 DtPlatformLocalObjectFacade myPlatformLocalObjectFacade;
204
205 //! Pointer to the left shoulder articulated part state
206 //! Null until first tick() call, then cached for efficient subsequent access
207 makVrf::DtArticulatedPartStateRepository* myLeftShoulder;
208
209 //! Animation cycle duration in seconds
210 //! The joint will complete one full motion cycle (0 to max angle and back) in this time
212
213 //! Current time within the animation cycle (0 to myAnimationInterval)
214 //! Accumulated each tick to calculate the current phase of the animation
216};
217} // namespace makVre
DtPlatformLocalObjectFacade myPlatformLocalObjectFacade
Facade providing convenient access to platform-specific entity features Simplifies access to articula...
Definition exampleHumanArtPartActuator.h:203
static DtSimComponent * creator(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=nullptr, DtReaderWriterRegistry *parentRegistry=nullptr)
Static factory creator method for component instantiation.
DtExampleHumanArtPartActuator()=delete
Default constructor - deleted (components require owner and services)
virtual ~DtExampleHumanArtPartActuator() override
Destructor - cleanup component resources.
makVrf::DtArticulatedPartStateRepository * myLeftShoulder
Pointer to the left shoulder articulated part state Null until first tick() call, then cached for eff...
Definition exampleHumanArtPartActuator.h:207
const DtExampleHumanArtPartActuator & operator=(const DtExampleHumanArtPartActuator &orig)=delete
Assignment operator - deleted (components are not assignable)
virtual bool init() override
Initialize component after construction.
double myAnimationInterval
Animation cycle duration in seconds The joint will complete one full motion cycle (0 to max angle and...
Definition exampleHumanArtPartActuator.h:211
DtExampleHumanArtPartActuator(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=nullptr, DtReaderWriterRegistry *parentRegistry=nullptr)
Constructor - Initialize actuator component for an entity.
DtExampleHumanArtPartActuator(const DtExampleHumanArtPartActuator &orig)=delete
Copy constructor - deleted (components are not copyable)
virtual const char * type() const override
Return component type identifier string.
virtual void tick() override
Update component state for one simulation frame.
double myTimeInInterval
Current time within the animation cycle (0 to myAnimationInterval) Accumulated each tick to calculate...
Definition exampleHumanArtPartActuator.h:215
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
constexpr char DtExampleHumanArtPartActuatorType[]
Type identifier string for human articulated part actuator component.
Definition exampleHumanArtPartActuator.h:37