Ejemplo n.º 1
0
/// calculate a rotation to bring the current direction vector between parent and bone
/// to the given new direction vector (non-normalized)
ofxQuaternion IKCharacter::getRotationForParentBone( int bone_id, CalVector new_parent_to_bone_direction )
{
	CalCoreSkeleton* core_skel = skeleton->getCoreSkeleton();
	CalBone* bone = skeleton->getBone( bone_id );
	int parent_id = core_skel->getCoreBone( bone_id )->getParentId();
	CalBone* parent_bone = skeleton->getBone( parent_id );
	int parent_parent_id = parent_bone->getCoreBone()->getParentId();
	// don't rotate the base state
	if ( parent_parent_id == -1 )
		return ofxQuaternion();


	// new_parent_to_bone_direction is currently in world-space
	// we need to bring it into the space of the parent bone
	CalQuaternion bone_space_rot = bone->getRotationBoneSpace();
	bone_space_rot.invert();
	new_parent_to_bone_direction *= bone_space_rot;

	CalVector old_dir = bone->getTranslation();
	CalVector new_dir = new_parent_to_bone_direction;
	old_dir.normalize();
	new_dir.normalize();
	
	
	// rotate from one to the other
	ofxQuaternion rot;
	ofxVec3f od( old_dir.x, old_dir.y, old_dir.z );
	ofxVec3f nd( new_dir.x, new_dir.y, new_dir.z );

	rot.makeRotate( od, nd );
	
	// return
	return rot.inverse();
}
Ejemplo n.º 2
0
/////////////////////////////////////
// Purpose:	get the rotation
//			to bring a point into the 
//			bone instance space
// Output:	pQ set
// Return:	none
/////////////////////////////////////
void IgfxObject::BoneGetRotateBoneSpace(s32 boneID, Quaternion *pQ)
{
	if(m_pCalModel)
	{
		CalSkeleton *pSkel = m_pCalModel->getSkeleton();
		CalBone *pBone = pSkel->getBone(boneID);
		CalQuaternion cQuat = pBone->getRotationBoneSpace();

		pQ->x = cQuat.x;
		pQ->y = cQuat.y;
		pQ->z = cQuat.z;
		pQ->w = cQuat.w;
	}
}