void recurseHierarahcy(Joint* p)
glPushMatrix();
glMultMatrix(p->localTransform);
for(int i = 0; i < p->numChildren; ++i) {
Joint* child = p->getCHild(i);
glBegin(GL_LINES);
// the line starts at the origin of the parent frame...
glVertex3f(0,0,0);
// and extends to the translation of the child (in local space)
glVertex3f(child->localTransform[12],
child->localTransform[13],
child->localTransform[14]);
glEnd();
recurseHierarahcy(child);
}
glPopMatrix();
}
void drawJointLines(Joint* joints, int count)
glBegin(GL_LINES);
for(int i = 0; i < count; ++i ){
Joint* joint = joints + I;
// only draw lines for joints that have parents.
if(joint->hasParent()) {
Joint* parent = joint->getParent();
// the line extends between the parent and the child.
glVertex3f(joint->worldTransform[12],
joint->worldTransform[13],
joint->worldTransform[14]);
glVertex3f(parent->worldTransform[12],
parent->worldTransform[13],
parent->worldTransform[14]);
}
}
glEnd();
}
1条答案
按热度按时间nkcskrwz1#
这取决于矩阵是在世界空间还是局部空间中,是否将关节存储为树(或具有索引的展平数组),以及是否使用推/弹出或自己的矩阵数学。
如果要在层次中存储关节,并且数据是局部空间,则需要递归以渲染角色:
如果你有世界空间矩阵,那么你只需要连接世界空间变换之间的点......(我假设这些变换是在世界空间中,并且你已经将角色存储在一个数组中!)