我是否将局部空间到世界空间坐标是否正确? [英] Am I converting local space to world space coordinates properly?
本文介绍了我是否将局部空间到世界空间坐标是否正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图创建一个骨骼和IK系统。下面是是递归的方法和其计算的绝对位置和各骨的绝对角度。我把它与根骨头和zero'd参数。它工作正常,但是当我尝试使用CCD IK我得到所产生的终点和计算值之间的差异。所以,也许我这样做是错误的,即使它的工作原理。
感谢
无效骷髅:: _ updateBones(骨*根,浮realStartX,浮realStartY,浮动realStartAngle)
{
如果(根 - >!而isRelative())
{
realStartX = 0.0;
realStartY = 0.0;
realStartAngle = 0.0;
}
realStartX + =根 - >的getX();
realStartY + =根 - > getY()以;
realStartAngle + =根 - > getAngle();
浮vecX = SIN(realStartAngle);
浮vecY = COS(realStartAngle);
realStartX + =(vecX *根 - >的getLength());
realStartY + =(vecY *根 - >的getLength());
根 - >的setFrame(realStartX,realStartY,realStartAngle);
浮动角= FMOD(realStartAngle,2.0f * 3.141592f);
如果(角度θ; -3.141592f)
角+ =(2.0f * 3.141592);
否则,如果(角GT; 3.141592f)
角 - =(2.0f * 3.141592f);
对于(标准::名单<骨>:迭代它=根 - >开始();它=根 - >!到底(); ++吧)
{
_updateBones(及(*吧),realStartX,realStartY,角度);
}
}
解决方案
这看起来是错误的。
浮动vecX = SIN(realStartAngle);
浮vecY = COS(realStartAngle);
交换罪()
和 COS()
。
浮动vecX = COS(realStartAngle);
浮vecY = SIN(realStartAngle);
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);
}
}
解决方案
This looks wrong.
float vecX = sin(realStartAngle);
float vecY = cos(realStartAngle);
Swap sin()
and cos()
.
float vecX = cos(realStartAngle);
float vecY = sin(realStartAngle);
这篇关于我是否将局部空间到世界空间坐标是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文