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