Am I converting local space to world space coordin

2019-08-27 01:58发布

I'm trying to create a bone and IK system. Below is the method that is recursive and that calculates the absolute positions and absolute angles of each bone. I call it with the root bone and zero'd parameters. It works fine, but when I try to use CCD IK I get discrepancies between the resulting end point and the calculated one. Therefore maybe I'm doing this wrong even though it works.

Thanks

void Skeleton::_updateBones( Bone* root,float realStartX, float realStartY, float realStartAngle )
{
    if(!root->isRelative())
    {
        realStartX = 0.0f;
        realStartY = 0.0f;
        realStartAngle = 0.0f;
    }
    realStartX += root->getX();
    realStartY += root->getY();
    realStartAngle += root->getAngle();
    float vecX = sin(realStartAngle);
    float vecY = cos(realStartAngle);

    realStartX += (vecX * root->getLength());
    realStartY += (vecY * root->getLength());

    root->setFrame(realStartX,realStartY,realStartAngle);

    float angle = fmod(realStartAngle,2.0f * 3.141592f);

    if( angle < -3.141592f )
        angle += (2.0f * 3.141592);
    else if( angle > 3.141592f )
        angle -= (2.0f * 3.141592f);
    for(std::list<Bone>::iterator it = root->begin(); it != root->end(); ++it)
    {
        _updateBones(&(*it),realStartX,realStartY,angle);
    }

}

1条回答
Anthone
2楼-- · 2019-08-27 02:47

This looks wrong.

float vecX = sin(realStartAngle);
float vecY = cos(realStartAngle);

Swap sin() and cos().

float vecX = cos(realStartAngle);
float vecY = sin(realStartAngle);
查看更多
登录 后发表回答