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