/// 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(); }
///////////////////////////////////// // Purpose: get the relative translation // of given boneID // Output: pLoc set // Return: none ///////////////////////////////////// void IgfxObject::BoneGetTrans(s32 boneID, Vec3D *pLoc) { if(m_pCalModel) { CalSkeleton *pSkel = m_pCalModel->getSkeleton(); CalBone *pBone = pSkel->getBone(boneID); CalVector cVec = pBone->getTranslation(); pLoc->x = cVec.x; pLoc->y = cVec.y; pLoc->z = cVec.z; } }