我想获取每个节点的绝对值。绝对值表示与根的距离。
如果我有一个骨架模型。
根子项是
root
left hip - child
left knee - child
left foot - child
assume that all the bones lengths are equal to 1.
root to hip = 1
hip to knee = 1
knee to foot = 1
所以如果我想从根部得到脚关节的位置,应该是3。 我说的对吗?
root to foot = root to hip + hip to knee + knee to foot = 3
所以这些是我正在使用的子程序。
void ComputeAbs()
{
for(unsigned int i=1; i<nNodes(); i++)
{
node* b = getNode(i);
if(b)
{
b->nb = ComputeAbsSum(b);
}
}
}
int ComputeAbsSum(node *b)
{
int m = b->nb;
if (b->child != NULL)
{
m *= ComputeAbsSum(b->child);
}
return m;
}
输出将像
root to hip = 3
root to knee = 2
root to foot = 1
But I want in a reverse way, i should get like this
root to hip = 1
root to knee = 2
root to foot = 3
如何实现此结果? 如何添加树子级值从子级到根部?
最终目标是通过计算关节的绝对变换来获得最终姿势。
bonePoseAbsolute[i] = bonePoseAbsolute[parentIndex] * bonePoseRelative[i];
谢谢。
看起来你的递归有问题。 尝试
int ComputeAbsSum(node *b)
{
int result = 1;
if (b->child != NULL)
result += ComputeAbsSum(b->child);
return result;
}
*编辑:如果要反向遍历树,
int ComputeAbsSumReverse(node *b)
{
int result = 1;
if (b->parent != NULL)
result += ComputeAbsSum(b->parent);
return result;
}