Skip to content

Instantly share code, notes, and snippets.

@dwilliamson
Created July 14, 2016 13:34
Show Gist options
  • Save dwilliamson/cb43fb22db95cb41eca1329191222a1d to your computer and use it in GitHub Desktop.
Save dwilliamson/cb43fb22db95cb41eca1329191222a1d to your computer and use it in GitHub Desktop.
void cMirrorControllerImpl::Sample(scenegraph::iSkeleton::Ptr skeleton, cOrientation* blend_buffer, int bone_group, float multiplier, float& current_weight)
{
bone_group &= m_BoneGroup;
if (m_Controller)
{
// Sample input
m_Controller->Sample(skeleton, blend_buffer, bone_group, multiplier, current_weight);
// TODO: Use bone groups on the mirror ?
const tVector<scenegraph::iSkeleton::Bone>& bones = skeleton->GetBones();
int nb_bones = bones.size();
// Iterate through each sampled bone in the blend buffer
for (int i = 0; i < nb_bones; i++)
{
cOrientation& o = blend_buffer[i];
if (!(bone_group & bones[i].group))
continue;
// Mirror bone rotation on the x-axis
//o.rotation.w = maths::Sin(-maths::ASin(o.rotation.w));
//o.rotation.x = -o.rotation.x;
o.rotation.y = -o.rotation.y;
o.rotation.z = -o.rotation.z;
// Mirror bone position on x-axis
o.position.x = -o.position.x;
}
// Iterate through each bone pair
const tVector<scenegraph::iSkeleton::BonePair>& bone_pairs = skeleton->GetBonePairs();
int nb_bone_pairs = bone_pairs.size();
for (int i = 0; i < nb_bone_pairs; i++)
{
const scenegraph::iSkeleton::BonePair& bp = bone_pairs[i];
if (!(bone_group & bones[bp.left].group))
continue;
// Swap left and right bones in the skeleton
cOrientation temp = blend_buffer[bp.left];
blend_buffer[bp.left] = blend_buffer[bp.right];
blend_buffer[bp.right] = temp;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment