DI-Guy SDK Documentation  13.7
diguyCharacterPoseOverride.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (c) 2023 MAK Technologies, Inc.
3  * All rights reserved.
4  ****************************************************************************/
5 
6  /*********************************************************************
7  **
8  *t diguyCharacterPoseOverride
9  **
10  */
11 
12 #pragma once
13 
14 #ifdef SWIG
16 #else
17 #define CPLUSPLUS_ONLY
18 #endif
19 
20 #ifdef CPLUSPLUS_ONLY
21 #include <stdlib.h>
22 
23 class bdiPoseOverride;
24 class bdiScenarioCharacter;
25 class bdiTopology;
26 #endif
27 
28 
29 #include <declspec_diguy.h>
30 
37 class BDI_DECLSPEC_diguy diguyCharacterPoseOverride
38 {
39 public:
40 
41 #ifdef CPLUSPLUS_ONLY
42 
43  /*l
44  *b Description:
45  **
46  ** Allocates an array of floats to hold the joint angles for
47  ** each degree of freedom, or weights to specify how pose angles
48  ** will affect a character. The size of the array will be equal
49  ** to the value returned by get_num_vars().
50  **
51  ** The allocated array should be freed by calling free_pose_array().
52  **
53  ** The allocated array will contain uninitialized values.
54  **
55  ** If the array is to hold weights, each entry in the array
56  ** should be set to a valid value between 0.0 and 1.0.
57  **
58  ** If the array is to hold pose angles, each pose variable whose
59  ** corresponding weight is going to be non-0 should be set to a
60  ** valid value.
61  **
62  *b Returns:
63  **
64  ** pointer to array of floats, NULL if the array cannot be allocated
65  **
66  *b Callable From:
67  **
68  *- - C++
69  **
70  *b C++ Example:
71  **
72  ** See example for set_pose_in_radians().
73  */
74  float* allocate_pose_array();
75 
76  /*l
77  *b Description:
78  **
79  ** Frees an array allocated with allocate_pose_array().
80  **
81  *b Arguments:
82  **
83  *a array - array of pose angles to be freed
84  **
85  *b Returns:
86  **
87  ** 0 on success, -1 on failure
88  **
89  *b Callable From:
90  **
91  *- - C++
92  */
93  int free_pose_array( float* array );
94 
95 #endif
96 
97  /*l
98  *b Description:
99  **
100  ** This function returns the number of the variables
101  ** representing joint angles.
102  **
103  *b Returns:
104  **
105  ** an integer representing the number of joint angles
106  **
107  *b Callable From:
108  **
109  *- - C++
110  *- - Script
111  */
112  int get_num_vars();
113 
114 #ifdef CPLUSPLUS_ONLY
115 
116  /*l
117  *b Description:
118  **
119  ** This function allocates an array of pointer to char*s
120  ** (i.e., C-style strings).
121  **
122  ** This array can then be passed to get_var_names().
123  **
124  ** It should be freed using the function free_var_names().
125  ** The size of the array will be equal to the value returned
126  ** by get_num_vars().
127  **
128  *b Returns:
129  **
130  ** an array of pointers to char*'s (i.e. pointers to strings)
131  **
132  *b Callable From:
133  **
134  *- - C++
135  **
136  *b C++ Example:
137  **
138  ** See example for get_var_names().
139  */
140  char** allocate_var_names();
141 
142  /*l
143  *b Description:
144  **
145  ** This function fills out the passed array of strings with
146  ** the list of the names of the variables representing joint
147  ** angles.
148  **
149  *b Arguments:
150  **
151  *a var_names - an array of strings as allocated by
152  *a allocate_var_names()
153  **
154  *b Returns:
155  **
156  ** 0 on success, -1 on failure
157  **
158  *b Callable From:
159  **
160  *- - C++
161  **
162  *b C++ Example:
163  **
164  *e //
165  *e // Create a pose override for character.
166  *e //
167  *e pose_override = character1->create_pose_override();
168  *e
169  *e //
170  *e // Allocate a list of joint angle names and fill it.
171  *e // Print the joint angle names, then destroy the array.
172  *e //
173  *e char** varnames = pose_override->allocate_var_names();
174  *e pose_override->get_var_names(varnames);
175  *e
176  *e for (i = 0; i < character1->get_pose_array_size(); i++)
177  *e bdi_log_printf(BDI_LOG_INFO, "%s\n", varnames[i]);
178  *e
179  *e pose_override->free_var_names(varnames);
180  */
181  int get_var_names( char** var_names );
182 
183  /*l
184  *b Description:
185  **
186  ** This function frees the array of strings allocated by
187  ** allocate_var_names().
188  **
189  *b Arguments:
190  **
191  *a var_names - an array of strings as allocated by
192  *a allocate_var_names()
193  **
194  *b Returns:
195  **
196  ** 0 on success, -1 on failure
197  **
198  *b Callable From:
199  **
200  *- - C++
201  */
202  int free_var_names( char** var_names );
203 
204  /*l
205  *b Description:
206  **
207  ** Get the index of the given variable in the array of pose angles.
208  **
209  *b Arguments:
210  **
211  *a varname - the name of the pose angle variable whose index is desired
212  **
213  *b Returns:
214  **
215  ** index of the pose variable, if it exists, -1 if not
216  **
217  *b Callable From:
218  **
219  *- - C++
220  **
221  *b C++ Example:
222  **
223  ** See example for set_pose_in_radians().
224  */
225  int get_var_index( const char* varname );
226 
227  /*l
228  *b Description:
229  **
230  ** This function fills out the passed array of floats with the most
231  ** recent values passed in a call to set_pose_in_radians().
232  **
233  ** Note that this may not be the actual pose of the character; this
234  ** is only the pose angles for this specific pose override. Other
235  ** pose overrides, gazing, etc., will also affect the pose of the
236  ** character. Use the function diguyCharacter::get_pose_in_radians()
237  ** to read the "real" pose of the character, as computed by the DI-Guy
238  ** motion engine.
239  **
240  *b Arguments:
241  **
242  *a pose_array - array of floats allocated by allocate_pose_array()
243  **
244  *b Returns:
245  **
246  ** 0 on success, -1 on failure
247  **
248  *b Callable From:
249  **
250  *- - C++
251  */
252  int get_pose_in_radians( float* pose_array );
253 
255  int get_pose_in_quaternions( float* pose_array );
256 
257  /*l
258  *b Description:
259  **
260  ** This function specifies the joint angle data that will modify
261  ** or override the joint angles the character normally computes.
262  ** The replacement data is in pose_array.
263  **
264  ** If weights array is non-NULL, then each element specifies the
265  ** proportion of the value on pose array to mix in with the value
266  ** normally computed by the character. A weight of 0.0 means to
267  ** ignore the value in pose_array. A weight of 1.0 means fully
268  ** override the value computed by the character.
269  **
270  ** If weights_array is NULL, then default_weight will be used for
271  ** *all* of the joint angles.
272  **
273  ** Note that all weights for an Euler triple (e.g. -
274  ** q.cervical_rz/rx/ry) must be equal to ensure proper
275  ** interpolation.
276  **
277  ** Also note that the first six variables that contain the character's
278  ** overall position and orientation cannot be changed using a pose
279  ** override. These values must be changed using the functions
280  ** diguyCharacter::set_position() and
281  ** diguyCharacter::set_orientation().
282  **
283  *b Arguments:
284  **
285  *a pose_array - the array containing the pose angles for this
286  *a override object
287  *a weight_array - the multiplier used to determine how the new
288  *a pose_array values are to be combined with the
289  *a existing pose
290  *a default_weight - the value to be used to set the weights if
291  *a weights_array is NULL
292  **
293  *b Returns:
294  **
295  ** 0 on success, -1 on failure
296  **
297  *b Callable From:
298  **
299  *- - C++
300  **
301  *b C++ Example:
302  **
303  *e //
304  *e // Create a pose override for character.
305  *e //
306  *e pose_override = character1->create_pose_override();
307  *e
308  *e //
309  *e // Allocate an array for pose angles.
310  *e //
311  *e pose_array = pose_override->allocate_pose_array();
312  *e for (i=0; i<pose_override->get_num_vars(); i++)
313  *e pose_array[i] = 0.0f;
314  *e
315  *e //
316  *e // Allocate a weights_array, and initialize it to all 0s.
317  *e //
318  *e weights_array = pose_override->allocate_pose_array();
319  *e for (i=0; i<pose_override->get_num_vars(); i++)
320  *e weights_array[i] = 0.0f;
321  *e
322  *e //
323  *e // Find the indices of the character's back angles. Set the
324  *e // weights for these angles in weights_array to 1.0. This
325  *e // means that when we call set_pose_in_radians(), the values
326  *e // in pose_array will completely override the original
327  *e // data for the back.
328  *e //
329  *e back_rz_index = pose_override->get_var_index("q.back_rz");
330  *e back_rx_index = pose_override->get_var_index("q.back_rx");
331  *e back_ry_index = pose_override->get_var_index("q.back_ry");
332  *e
333  *e pose_array[back_rz_index] = 0.57f; // angle measured in radians
334  *e pose_array[back_rx_index] = 0.0f; // angle measured in radians
335  *e pose_array[back_ry_index] = 0.0f; // angle measured in radians
336  *e
337  *e weights_array[back_rz_index] = 1.0f;
338  *e weights_array[back_rx_index] = 1.0f;
339  *e weights_array[back_ry_index] = 1.0f;
340  *e
341  *e pose_override->set_pose_in_radians(pose_array,
342  *e weights_array,
343  *e 0.0f);
344  */
345  int set_pose_in_radians( float* pose_array, float* weights_array = NULL,
346  float default_weight = 1.0f );
347 
349  int set_pose_in_quaternions( float* pose_array, float* weights_array = NULL,
350  float default_weight = 1.0f );
351 
352 #endif
353 
354  /*l
355  *b Description:
356  **
357  ** Get the default weight for pose angles.
358  **
359  *b Returns:
360  **
361  ** the default pose angle weight
362  **
363  *b Callable From:
364  **
365  *- - C++
366  *- - Script
367  */
368  float get_default_weight();
369 
370  /*l
371  *b Description:
372  **
373  ** Set the default weight for pose angles.
374  **
375  ** The default weight will be used to set values in a pose's weights
376  ** array if the array passed in, for instance, set_pose_in_radians(),
377  ** is NULL.
378  **
379  *b Arguments:
380  **
381  *a default_weight - the desired default weight
382  **
383  *b Returns:
384  **
385  ** 0 on success, -1 on failure
386  **
387  *b Callable From:
388  **
389  *- - C++
390  *- - Script
391  */
392  int set_default_weight( float default_weight );
393 
394 
395  /*l
396  *b Description:
397  **
398  ** Sets an additional multiplier on the entire weight array. Defaults to 1.0f
399  **
400  *b Arguments:
401  **
402  *a weight_array_modifier - the desired weight
403  **
404  *b Returns:
405  **
406  ** 0 on success, -1 on failure
407  **
408  *b Callable From:
409  **
410  *- - C++
411  *- - Script
412  */
413  int set_weight_array_modifier( float weight_array_modifier );
414 
416  float get_weight_array_modifier();
417 
422 #ifdef CPLUSPLUS_ONLY
424  bdiPoseOverride* get_scripted_object() { return m_scripted_object; }
426 private:
427 
428  /*
429  * private constructor
430  */
431  diguyCharacterPoseOverride( bdiPoseOverride* scripted_object,
432  bdiScenarioCharacter* character );
433 
434  /*
435  * private destructor
436  */
437  virtual ~diguyCharacterPoseOverride();
438 
439 private:
440 
441  friend class bdiPoseOverride;
442  friend class diguyCharacter;
443  friend class bdiScenarioCharacter;
444 
445  /*
446  * internal data
447  */
448  bdiPoseOverride* m_scripted_object;
449  bdiScenarioCharacter* m_character;
450 
451 #endif
452 
453 };
The class that represents a DI-Guy Entity in the world.
Definition: diguyCharacter.h:81
A class that allows end users to override a character's animation on a joint level.
Definition: diguyCharacterPoseOverride.h:35