3DXI Controllers: IGameControl

IGameControl provides direct access to standard key frame controllers in 3ds Max. This is particularly useful to game developers, because they know what type of controller they are exporting as defined by their game engine.

To export key frame controllers using the 3ds Max SDK requires asking for the position controller, checking if it has the required Key interface, and then extracting the key based on the control type. 3DXI handles this automatically, allowing the developer to simply request a list of bezier position keys for export.

Along with the basic Key frame controllers, IGameControl can sample a controller. This is important for certain controllers that do not support the Key interfaces, such as biped. Each IGameControl interface maintains a control type which allows the developer to determine the control type used by IGameControl, based on the transform style. For example: if the Control is an Unsupported controller or biped, then the developer can sample it at the required rate. 3DXI provides two types of sampling: Full and Quick. Full samples the animation over the entire animation range at the specified sampling rate set by the developer. Quick samples only the controller where a key exists. Quick has limitations: it will not work for IGAME_TM sampling or controllers that do not support key setting.

IGameControl::Get...Keys() methods return a success flag as a boolean, allowing simple iteration through the key methods. Thus, if all return FALSE, no keys are found. Sampling can then be requested.

The following table lists IGameControl types and their associated meanings:

IGame Controller Type Max Controller
IGAME_UNKNOWN Procedural Controller / 3rd Party
IGAME_MAXSTD Linear, TCB, Bezier
IGAME_BIPED Biped Controller
IGAME_EULER Euler Controller
IGAME_ROT_CONSTRAINT Orientation and Look At Constraint
IGAME_POS_CONSTRAINT Path and Position Constraint.
IGAME_LINK_CONSTRAINT A Matrix3 TM constraint
IGAME_LIST A List Controller
IGAME_INDEPENDENT Independent Position controller
IGAME_MASTER Master point controller

Constraints are also supported directly by IGameControl. Like the skin access, all constraints are supported through a unified interface. The constraint is identified as a controller type. If found, the developer simply needs to obtain the constraint interface for that particular controller type. The following code is an example of this:

if(exportControllers)
{
    IGameKeyTab posKeys,rotKeys,
    IGameControl * pGC = node->GetIGameControl();
    DWORD T = pGC->GetControlType( IGAME_POS);
    //position
    if(T==IGAME_MAXSTD && pGC->GetBezierKeys(poskeys, IGAME_POS))
        DumpBezierKeys( IGAME_POS,poskeys,prsNode);
    else if(T==IGAME_POS_CONSTRAINT && !forceSample)
    {
         IGameConstraint * cnst = pGC->GetConstraint( IGAME_POS);
        DumpConstraints(prsNode,cnst);
    }
//rotation
    else if(T==IGAME_MAXSTD && pGC->GetTCBKeys(rotkeys, IGAME_ROT)
    {
        DumpTCBKeys( IGAME_ROT,rotkeys,prsNode);
    }
    else if(T==IGAME_ROT_CONSTRAINT && !forceSample)
    {
         IGameConstraint * cnst = pGC->GetConstraint( IGAME_ROT);
        DumpConstraints(prsNode,cnst);
    }
    else
        DumpSampleKeys(child,prsNode); // usually Biped
}