일부 골격 애니메이션을 할 때 비슷한 문제가 발생했습니다. 이를 위해 재귀를 사용하는 것이 매우 유용합니다. 또한 뼈를 계층 적으로 구조화하십시오 (예 : 어깨가 손의 부모 인 팔뚝의 부모 등). 다음과 같이 코드를 작성할 수 있다는함으로써 :
void drawBone(Bone *root) {
if (!root) return;
glPushMatrix();
glTranslatef(root->x,root->y,0);
glRotatef(root->a,0,0,1);
// insert code to actually draw bone here
int i;
glTranslatef(root->l,0,0);
for (i=0; i<root->childCount; i++)
drawBone(root->child[i]);
glPopMatrix();
}
내 뼈 구조체는 다음과 같이 보았다 :
typedef struct _Bone {
float x,y,a,l; // position, angle, length of bone
int childCound; // number of children for this bone
struct _Bone *child[MAX_CHILD_COUNT], *parent;
} Bone;
이 website 골격 애니메이션을위한 훌륭한 자원이다.