Game Development Reference
another pointer to the object list. Starting again at the beginning of the
list, we are now looking for objects that have 'Torso' as a parent. In this
example the first object in the list, 'Left Shoulder', has 'Torso' as a
parent. The next step is to transform 'Left Shoulder' and then from this
function call 'UpdateChildObjects', only this time with 'Left Shoulder' as
the parameter. In this next call to 'UpdateChildObjects', 'Left Bicep' has
'Left Shoulder' as a parent. So we transform 'Left Bicep' and call
'UpdateChildObjects' with 'Left Bicep' as the parameter. This is
repeated for 'Left Forearm' and 'Left Hand'. At this stage the nested
function calls are:
The key to using recursive functions is to ensure they return, otherwise
your code will hang in an endless loop. The function 'UpdateChildObjects'
returns when the entire scene list has been searched and the next
pointer is 'NULL'. In the example, 'UpdateChildObjects' for 'Left Hand'
the entire scene list will be searched and no children of 'Left Hand'
found. Having got to the object 'Right Hand' in the list, the function
returns because the 'next' pointer for 'Right Hand' is NULL. The function
call 'UpdateChildObjects' using 'Left Forearm' as a parameter having
found the child object 'Left Hand' and ensured that it is updated
continues looking at the object list by examining 'Right Forearm' and
'Right Hand', at which stage the list has been traversed and now this
function returns. Ultimately, all the calls to 'UpdateChildObjects' return
and the function pointer is back in 'UpdateAllObjects', where the
remainder of the object list is traversed, finding no other objects with no
parent. In this way, we ensure that all objects are transformed, but that
the parent of an object is transformed first.
The order of updating for the list described in Table 7.1 will be