コード例 #1
0
ファイル: animation.cpp プロジェクト: tapple/qavimator
void Animation::deleteKeyFrame(int jointNumber,int frameNum)
{
  // frames should always be current frame, but better play safe for future enhancements
  setFrame(frameNum);
  if(jointNumber)
  {
     BVHNode* joint=getNode(jointNumber);
     if(joint->isKeyframe(frameNum)) deleteKeyFrame(joint,frameNum);
  }
  else if(isKeyFrame()) deleteKeyFrameAllJoints();

  // tell main class that the keyframe has changed
  emit currentFrame(frameNum);
}
コード例 #2
0
ファイル: animation.cpp プロジェクト: tapple/qavimator
// 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;
  }
}
コード例 #3
0
ファイル: NiAnimation.cpp プロジェクト: hudakm/animik
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();
    }
}