datadescriptionscattersqt.h

datadescriptionscattersqt.h

This code example shows how to set and retrieve character animations using a data set that follows the HIKDataDescription structure, in conjunction with the HIKSetCharacterStateTransformTQS() / HIKGetCharacterStateTransformTQS() functions. In this example, the TQS values are ordered differently within the data block (S first at offset 0, Q at offset 32, and T at offset 80). In addition, these values are interleaved with arbitrary data not used by HumanIK.

#include <humanik.h>
class YourNodeData {
public:
__declspec(align(16)) float scale[4];
int somedata;
__declspec(align(16)) float quaternion[4];
bool someotherdata;
float postrotation[4];
__declspec(align(16)) float transform[4];
};
int gScatterSQT[] = {
0,1,2,3,4,HIKDataDescription::HIKNotUsed,5,6,7,8,9,10,
11,12,13,14,HIKDataDescription::HIKNotUsed,15,16,
HIKDataDescription::HIKNotUsed,17,18,19,20,23,24,
41,42,43,44,45,HIKDataDescription::HIKNotUsed,46,
47,48,50,HIKDataDescription::HIKNotUsed,51,52,53,
54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,74,
75,76,HIKDataDescription::HIKNotUsed,77,78,79,80,81,
82,83,84,85,86,87,88,HIKDataDescription::HIKNotUsed,
};
// Each data description applies to a single character. Other characters may share the same data description ONLY if their skeletons contain
// the same Nodes.
HIKDataDescription gScatterSQTDD = {
HIKGlobalSpace, 80, 32, 0, sizeof(YourNodeData), gScatterSQT
};
// For the purposes of this example, the animation data set is hard-coded below. In your game, this should be replaced with the data from your
// FK character animations.
// PLEASE NOTE that the data set MUST be aligned on 16 bytes.
YourNodeData gSrcAnimScatterSQT[][78] = {
// First frame of animation.
{
{ 0.1650f, 0.1650f, 0.1650f, 1.0000f, 0, 0.7071f, 0.0000f, 0.0000f, -0.7071f, false, 1.0000f, 0.0000f, 1.0000f, 0.0000f, 0.0000f, 0.0000f, 0.0000f, 0.0000f },
{ 0.1650f, 0.1650f, 0.1650f, 1.0000f, 1, -0.5467f, 0.0041f, -0.0513f, 0.8357f, true, 1.0000f, 0.0000f, 1.0000f, 0.0000f, -45.9543f, 87.8138f, -205.8150f, 0.0000f },
{ 0.1650f, 0.1650f, 0.1650f, 1.0000f, 2, -0.3937f, 0.5796f, -0.4090f, 0.5847f, false, 1.0000f, 0.0000f, 1.0000f, 0.0000f, -36.9173f, 85.1093f, -203.8390f, 0.0000f },
{ 0.1650f, 0.1650f, 0.1650f, 1.0000f, 3, -0.2165f, 0.6683f, -0.2402f, 0.6700f, true, 1.0000f, 0.0000f, 1.0000f, 0.0000f, -37.1718f, 47.8651f, -218.0180f, 0.0000f },
{ 0.1650f, 0.1650f, 0.1650f, 1.0000f, 4, 0.5176f, -0.5323f, 0.5517f, -0.3799f, false, 1.0000f, 0.0000f, 1.0000f, 0.0000f, -37.5291f, 22.2028f, -251.2470f, 0.0000f },
/* Unused */ { 1.0000f, 1.0000f, 1.0000f, 1.0000f, 5, 0.0000f, 0.0000f, 0.0000f, 1.0000f, true, 1.0000f, 0.0000f, 1.0000f, 0.0000f, 0.0000f, 0.0000f, 0.0000f, 0.0000f },
{ 0.1650f, 0.1650f, 0.1650f, 1.0000f, 5, 0.1685f, 0.7450f, 0.1959f, 0.6150f, true, 1.0000f, 0.0000f, 1.0000f, 0.0000f, -55.4791f, 86.7912f, -204.7580f, 0.0000f },
{ 0.1650f, 0.1650f, 0.1650f, 1.0000f, 6, 0.6955f, 0.3066f, 0.6062f, 0.2338f, false, 1.0000f, 0.0000f, 1.0000f, 0.0000f, -48.0319f, 67.1858f, -170.8700f, 0.0000f },
...
{ 0.1650f, 0.1650f, 0.1650f, 1.0000f, 9, -0.4713f, 0.3514f, -0.4028f, 0.7015f, true, 1.0000f, 0.0000f, 1.0000f, 0.0000f, -25.7819f, 132.2600f, -178.6560f, 0.0000f },
{ 0.1650f, 0.1650f, 0.1650f, 1.0000f, 10, 0.4871f, 0.2165f, 0.8449f, -0.0461f, false, 1.0000f, 0.0000f, 1.0000f, 0.0000f, -15.5359f, 110.8230f, -181.3670f, 0.0000f },
{ 0.1650f, 0.1650f, 0.1650f, 1.0000f, 11, 0.3258f, 0.2741f, 0.9029f, -0.0588f, true, 1.0000f, 0.0000f, 1.0000f, 0.0000f, -30.4233f, 114.6230f, -157.2910f, 0.0000f },
{ 0.1650f, 0.1650f, 0.1650f, 1.0000f, 12, 0.7977f, -0.0323f, 0.5224f, 0.2995f, false, 1.0000f, 0.0000f, 1.0000f, 0.0000f, -61.6569f, 136.5460f, -186.2980f, 0.0000f },
},
// Second frame of animation.
{
...
},
// Other animation frames...
...
};
void main()
{
// Initialize your game engine.
...
// The usual HumanIK initialization code goes here.
HIKCharacterState* lCharacterState;
// Other initialization that must be carried out before the game loop starts.
....
// Game loop.
for(;;)
{
// Update the game world, and retrieve FK joint animation from the animation curve.
...
// Data flow from your game engine to the HumanIK engine.
HIKSetCharacterStateTransformTQS(lCharacterState, &gScatterSQTDD, (void *)gSrcAnimScatterSQT[ gametime ]);
// Call the HumanIK IK solver.
// Data flow from the HumanIK engine to your game engine.
HIKGetCharacterStateTransformTQS(lCharacterState, &gScatterSQTDD, (void *)gSrcAnimScatterSQT[ gametime ]);
// Render your scene.
...
}
// Clean up your game engine.
...
// The usual HIK cleanup code goes here.
....
}