DI-Guy SDK Documentation  13.9
diguyChainSimulation.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (c) 2026 MAK Technologies, Inc.
3  * All rights reserved.
4  ****************************************************************************/
5 
6 #pragma once
7 
8 #ifdef SWIG
10 #else
11 #define CPLUSPLUS_ONLY
12 #endif
13 
14 #ifdef CPLUSPLUS_ONLY
15 class bdiScenarioChain;
16 class bdiScenarioChainSettings;
17 class diguyChainSettings;
18 class diguyPathShape;
19 #endif
20 
21 
22 #include <declspec_diguy.h>
23 
29 class BDI_DECLSPEC_diguy diguyChainSimulation
30 {
31 public:
41  /*l
42  *b Description:
43  **
44  ** This function returns the chain settings this chain simulation is
45  ** using.
46  **
47  *b Returns:
48  **
49  ** object of type diguyChainSettings; will never be NULL
50  */
51  diguyChainSettings* get_settings();
52 
53  /*l
54  *b Description:
55  **
56  ** This function sets the settings this chain simulation will use.
57  **
58  *b Arguments:
59  **
60  *a settings - name of new settings to use
61  **
62  *b Returns:
63  **
64  ** 0 on success, -1 on failure
65  */
66  int update_settings(const char* settings);
67 
68  /*l
69  *b Description:
70  **
71  ** This function runs the simulation forward the specified number of
72  ** seconds, to let the chain settle into a stable configuration.
73  **
74  ** Note that the chain will appear to achieve the new configuration
75  ** instantly.
76  **
77  ** Specifying a large amount of time can result in a frame rate
78  ** hitch.
79  **
80  *b Arguments:
81  **
82  *a time_runoff - how much time to run off, in seconds
83  **
84  *b Returns:
85  **
86  ** 0 on success, -1 on failure
87  */
88  int do_stabilization_time_runoff(float time_runoff);
89 
90  /*l
91  *b Description:
92  **
93  ** This function can 'freeze' or 'unfreeze' a chain.
94  **
95  ** If a chain is frozen, all chain masses will remain in their
96  ** current positions and will not move until the chain is unfrozen.
97  **
98  ** A frozen chain requires no simulation time.
99  **
100  *b Arguments:
101  **
102  *a is_frozen - pass 1 to freeze the chain; 0 to unfreeze
103  */
104  void set_is_frozen(int is_frozen);
105 
106  /*l
107  *b Returns:
108  **
109  ** 1 if chain is frozen, 0 if not
110  */
111  int get_is_frozen();
112 
113  /*l
114  *b Description:
115  **
116  ** This function connects a chain mass to a character, or disconnects
117  ** a chain mass if the passed character_name is NULL.
118  **
119  ** As the character moves the chain mass will move with it, dragging
120  ** adjacent masses along. This allows a firefighter to pick up one
121  ** end of a hose and drag the hose to a new location, for example.
122  **
123  ** In each time-step of the scenario a new position for the specified
124  ** chain mass will be computed based on the position of the
125  ** character.
126  **
127  ** When the chain sim is created, and when the scenario is reset, one
128  ** chain mass will be automatically connected to the chain's
129  ** character. The index of the mass that will be connected is set by
130  ** a call to
131  ** diguyChainSettings::set_index_of_chain_mass_connected_to_character().
132  **
133  ** Chain masses can be connected to a specific link of the connection
134  ** character by passing the link's name. If NULL is passed, the
135  ** connection will be made to the character's "position" link. Note
136  ** that a non-NULL link name must be used for the link offset
137  ** arguments to have an effect.
138  **
139  ** The chain mass can gradually be shifted from its current position
140  ** to the connection position using the connection_smoothing_period
141  ** argument. Passing in 0.5, for example, will cause the link to
142  ** shift to its new connection point within approximately 0.5
143  ** seconds, avoiding an abrupt and potentially ugly impulse to the
144  ** simulation.
145  **
146  *b Arguments:
147  **
148  *a chain_mass_index - index of chain mass
149  *a character_name - name of character to attach to; must not be NULL
150  *a link_name - name of link to attach to; can be NULL; if
151  *a so, will attach to character's base position
152  *a link_offset_x - link attachment offset in X
153  *a link_offset_y - link attachment offset in Y
154  *a link_offset_z - link attachment offset in Z
155  *a connection_smoothing_period - how much time to take, in seconds,
156  *a to gradually shift the chain mass
157  *a to its new connection point
158  **
159  *b Returns:
160  **
161  ** 0 on success, -1 on failure
162  */
163  int set_chain_mass_connection_character(int chain_mass_index,
164  const char* character_name,
165  const char* link_name = nullptr,
166  float link_offset_x = 0.0f,
167  float link_offset_y = 0.0f,
168  float link_offset_z = 0.0f,
169  float connection_smoothing_period = 0.1f);
170 
171  /*l
172  *b Description:
173  **
174  ** This function sets the position of one chain mass, and optionally
175  ** fixes it there.
176  **
177  ** The passed position is always relative to the chain character's
178  ** parent, if there is one.
179  **
180  ** If the fix_mass_position argument is 1, the chain mass will remain
181  ** fixed in the new position, as if
182  ** set_chain_mass_position_is_fixed(1) were called.
183  **
184  *b Arguments:
185  **
186  *a chain_mass_index - index of chain mass; pass -1 to
187  *a affect all chain masses
188  *a mass_x - position x
189  *a mass_y - position y
190  *a mass_z - position z
191  *a fix_mass_position - pass 1 to fix chain mass in place;
192  *a 0 to leave it free to move
193  **
194  *b Returns:
195  **
196  ** 0 on success, -1 on failure
197  */
198  int set_chain_mass_position(int chain_mass_index,
199  float mass_x,
200  float mass_y,
201  float mass_z,
202  int fix_mass_position);
203 
204  /*l
205  *b Description:
206  **
207  ** This function sets the positions of all chain masses to lie along
208  ** the passed path shape.
209  **
210  ** If the stretch_to_fit argument is 1, chain masses will be spaced
211  ** along the entire length of the path shape. If the path shape is
212  ** longer than the nominal length of the chain, the chain will be
213  ** stretched out. If the path shape is shorter, the chain will be
214  ** compressed.
215  **
216  *b Arguments:
217  **
218  *a path_shape - path shape for new chain mass positions
219  *a stretch_to_fit - pass 1 to stretch chain to take up entire
220  *a length of path_shape; pass 0 to leave
221  *a chain at its nominal length
222  **
223  *b Returns:
224  **
225  ** 0 on success, -1 on failure
226  */
227  int set_chain_mass_positions_along_path_shape(diguyPathShape* path_shape,
228  int stretch_to_fit = 1);
229 
230  /*l
231  *b Description:
232  **
233  ** This function can fix or unfix a chain mass in place. If it is
234  ** fixed the chain mass will remain in its current position until it
235  ** is unfixed.
236  **
237  ** Fixed chain masses do not require simulation time, so the more
238  ** masses in a chain that are fixed, the lower the computational load
239  ** of the chain simulation.
240  **
241  *b Arguments:
242  **
243  *a chain_mass_index - index of chain mass; pass -1 to
244  *a affect all chain masses
245  *a is_fixed - pass 1 to fix chain mass position;
246  *a 0 to unfix it
247  **
248  *b Returns:
249  **
250  ** 0 on success, -1 on failure
251  */
252  int set_chain_mass_position_is_fixed(int chain_mass_index,
253  int is_fixed);
254 
255  /*l
256  *b Returns:
257  **
258  ** 1 if chain mass is fixed, 0 if not
259  */
260  int get_chain_mass_position_is_fixed(int mass_index);
261 
262  /*l
263  *b Returns:
264  **
265  ** length of the chain
266  */
267  float get_length();
268 
269 
274 #ifdef CPLUSPLUS_ONLY
275 
276  bdiScenarioChain* get_scripted_object() {return m_scripted_object;}
277 
278 private:
279 
280  /*l
281  ** A private constructor.
282  */
283  diguyChainSimulation(bdiScenarioChain* scripted_object);
284 
285  /*l
286  ** A private destructor.
287  */
289 
290  /*l
291  ** A pointer to internal data.
292  */
293  bdiScenarioChain* m_scripted_object;
294 
295  friend class bdiScenarioChain;
296 
297 #endif
298 
299 };
wrapper around a chain simulation
Definition: diguyChainSimulation.h:28
Represents a scriptable api wrapping a diguy path shape, a curve defined by with a number of waypoint...
Definition: diguyPathShape.h:36
chain settings.. Rarely used
Definition: diguyChainSettings.h:32