Animation::Animation(BVH* newBVH,const QString& bvhFile) : frame(0),totalFrames(0),mirrored(false) { qDebug("Animation::Animation(%px)",this); bvh=newBVH; if(!bvh) { qDebug("Animation::Animation(): BVH initialisation failed."); return; } QString fileName; // pick up path from src.pro qmake file's DEFINES section, i.e. usr/share/qavimator //dataPath=QAVIMATOR_DATAPATH; #ifdef __APPLE__ dataPath=QApplication::applicationDirPath() + "/../Resources"; #else dataPath=QAVIMATOR_DATAPATH; #endif // load BVH that defines motion if (!bvhFile.isEmpty()) fileName=bvhFile; else fileName=dataPath+"/"+DEFAULT_POSE; loadBVH(fileName); calcPartMirrors(); useRotationLimits(true); setNumberOfFrames(bvh->lastLoadedNumberOfFrames); setAvatarScale(bvh->lastLoadedAvatarScale); setFigureType(bvh->lastLoadedFigureType); setLoopInPoint(bvh->lastLoadedLoopIn); setLoopOutPoint(bvh->lastLoadedLoopOut); setFrameTime(bvh->lastLoadedFrameTime); positionNode=bvh->lastLoadedPositionNode; addKeyFrameAllJoints(); ikTree.set(frames); setIK(IK_LHAND, false); setIK(IK_RHAND, false); setIK(IK_LFOOT, false); setIK(IK_RFOOT, false); setLoop(false); setDirty(false); currentPlayTime=0.0; setPlaystate(PLAYSTATE_STOPPED); connect(&timer,SIGNAL(timeout()),this,SLOT(playbackTimeout())); }
// returns TRUE if frame is now a keyframe for entire animation, FALSE if not bool Animation::toggleKeyFrameAllJoints() { if(frame==0) return true; // first frame will always stay keyframe if(isKeyFrame()) { deleteKeyFrameAllJoints(); return false; } else { addKeyFrameAllJoints(); return true; } }
void NiAnimation::updateSkeletonAnimation(xn::UserGenerator &user_generator) { XnUInt16 num_users = MAX_USERS; user_generator.GetUsers(all_users, num_users); // tracking only default (first) person if (!user_generator.GetSkeletonCap().IsTracking(DEFAULT_USER)) return; // POSITION // animik: x,y,z € <-196, 196> XnSkeletonJointPosition torso; user_generator.GetSkeletonCap().GetSkeletonJointPosition(all_users[0], XN_SKEL_TORSO, torso); if (torso.fConfidence == 1) setPosition(torso.position.X*MM0, torso.position.Y*MM0+40, 150-torso.position.Z*MM0); // ROTATION double x, y, z, tx, ty, tz; // hip -> abdomen -> chest -> ... if (calculateRotation(user_generator, XN_SKEL_LEFT_HIP, tx, ty, tz, MM1) && calculateRotation(user_generator, XN_SKEL_RIGHT_HIP, x, y, z, MM1)) setRotation(getNodeByName("hip"), (x+tx)/2, (y+ty)/2, (z+tz)/2); if (calculateRotation(user_generator, XN_SKEL_TORSO, x, y, z, MM1)) setRotation(getNodeByName("abdomen"), x, y, z); if (calculateRotation(user_generator, XN_SKEL_NECK, tx, ty, tz, MM1)) // !!! + torso ^ setRotation(getNodeByName("chest"), (x+tx)/2, (y+ty)/2, (z+tz)/2); // ... -> neck -> head if (calculateRotation(user_generator, XN_SKEL_NECK, x, y, z, MM1)) setRotation(getNodeByName("neck"), x, y, z); if (calculateRotation(user_generator, XN_SKEL_HEAD, x, y, z, MM1)) setRotation(getNodeByName("head"), x, y, z); if (!global_mirror) { // ... -> lCollar -> lShldr -> lForeArm -> lHand if (calculateRotation(user_generator, XN_SKEL_LEFT_COLLAR, x, y, z, MM2)) setRotation(getNodeByName("rCollar"), x, y, z/MM2); if (calculateRotation(user_generator, XN_SKEL_LEFT_SHOULDER, x, y, z, MM2)) setRotation(getNodeByName("rShldr"), x, y*MM2, z/MM2); if (calculateRotation(user_generator, XN_SKEL_LEFT_ELBOW, x, y, z, MM2)) setRotation(getNodeByName("rForeArm"), x, y, z); if (calculateRotation(user_generator, XN_SKEL_LEFT_HAND, x, y, z, MM2)) setRotation(getNodeByName("rHand"), x, y, z/MM2); // ... -> rCollar -> rShldr -> rForeArm -> rHand if (calculateRotation(user_generator, XN_SKEL_RIGHT_COLLAR, x, y, z, MM2)) setRotation(getNodeByName("lCollar"), x, y, z/MM2); if (calculateRotation(user_generator, XN_SKEL_RIGHT_SHOULDER, x, y, z, MM2)) setRotation(getNodeByName("lShldr"), x, y*MM2, z/MM2); if (calculateRotation(user_generator, XN_SKEL_RIGHT_ELBOW, x, y, z, MM2)) setRotation(getNodeByName("lForeArm"), x, y, z); if (calculateRotation(user_generator, XN_SKEL_RIGHT_HAND, x, y, z, MM2)) setRotation(getNodeByName("lHand"), x, y, z/MM2); // hip -> lThigh -> lShin -> lFoot if (calculateRotation(user_generator, XN_SKEL_RIGHT_HIP, x, y, z, MM3) ) setRotation(getNodeByName("lThigh"), x/MM3, y, z); if (calculateRotation(user_generator, XN_SKEL_RIGHT_KNEE, x, y, z, MM3)) setRotation(getNodeByName("lShin"), x, y, z); if (calculateRotation(user_generator, XN_SKEL_RIGHT_FOOT, x, y, z, MM3)) setRotation(getNodeByName("lFoot"), x/MM3, y, z); // hip -> rThigh -> rShin -> rFoot if (calculateRotation(user_generator, XN_SKEL_LEFT_HIP, x, y, z, MM3)) setRotation(getNodeByName("rThigh"), x/MM3, y, z); if (calculateRotation(user_generator, XN_SKEL_LEFT_KNEE, x, y, z, MM3)) setRotation(getNodeByName("rShin"), x, y, z); if (calculateRotation(user_generator, XN_SKEL_LEFT_FOOT, x, y, z, MM3)) setRotation(getNodeByName("rFoot"), x/MM3, y, z); } else { // ... -> lCollar -> lShldr -> lForeArm -> lHand if (calculateRotation(user_generator, XN_SKEL_LEFT_COLLAR, x, y, z, MM2)) setRotation(getNodeByName("lCollar"), x, y, z/MM2); if (calculateRotation(user_generator, XN_SKEL_LEFT_SHOULDER, x, y, z, MM2)) setRotation(getNodeByName("lShldr"), x, y*MM2, z/MM2); if (calculateRotation(user_generator, XN_SKEL_LEFT_ELBOW, x, y, z, MM2)) setRotation(getNodeByName("lForeArm"), x, y, z); if (calculateRotation(user_generator, XN_SKEL_LEFT_HAND, x, y, z, MM2)) setRotation(getNodeByName("lHand"), x, y, z/MM2); // ... -> rCollar -> rShldr -> rForeArm -> rHand if (calculateRotation(user_generator, XN_SKEL_RIGHT_COLLAR, x, y, z, MM2)) setRotation(getNodeByName("rCollar"), x, y, z/MM2); if (calculateRotation(user_generator, XN_SKEL_RIGHT_SHOULDER, x, y, z, MM2)) setRotation(getNodeByName("rShldr"), x, y*MM2, z/MM2); if (calculateRotation(user_generator, XN_SKEL_RIGHT_ELBOW, x, y, z, MM2)) setRotation(getNodeByName("rForeArm"), x, y, z); if (calculateRotation(user_generator, XN_SKEL_RIGHT_HAND, x, y, z, MM2)) setRotation(getNodeByName("rHand"), x, y, z/MM2); // hip -> lThigh -> lShin -> lFoot if (calculateRotation(user_generator, XN_SKEL_RIGHT_HIP, x, y, z, MM3) ) setRotation(getNodeByName("rThigh"), x/MM3, y, z); if (calculateRotation(user_generator, XN_SKEL_RIGHT_KNEE, x, y, z, MM3)) setRotation(getNodeByName("rShin"), x, y, z); if (calculateRotation(user_generator, XN_SKEL_RIGHT_FOOT, x, y, z, MM3)) setRotation(getNodeByName("rFoot"), x/MM3, y, z); // hip -> rThigh -> rShin -> rFoot if (calculateRotation(user_generator, XN_SKEL_LEFT_HIP, x, y, z, MM3)) setRotation(getNodeByName("lThigh"), x/MM3, y, z); if (calculateRotation(user_generator, XN_SKEL_LEFT_KNEE, x, y, z, MM3)) setRotation(getNodeByName("lShin"), x, y, z); if (calculateRotation(user_generator, XN_SKEL_LEFT_FOOT, x, y, z, MM3)) setRotation(getNodeByName("lFoot"), x/MM3, y, z); } // add frame to animation if (is_recording) { setFrame(current_frame++); if (current_frame % 10 == 0) addKeyFrameAllJoints(); else deleteKeyFrameAllJoints(); } }
void Animation::pasteFrame() { bvh->bvhSetFrameData(frames,frame); addKeyFrameAllJoints(); }