opengl 绘制蒙皮网格的骨骼

y53ybaqx  于 2022-11-23  发布在  其他
关注(0)|答案(1)|浏览(134)

我有一个简单模型动画中每个帧的每个骨骼的JointTransform矩阵。我想把骨骼画成线。我使用OpenGl 2。我只想计算Vector3的起点和终点。我该怎么做呢?

nkcskrwz

nkcskrwz1#

这取决于矩阵是在世界空间还是局部空间中,是否将关节存储为树(或具有索引的展平数组),以及是否使用推/弹出或自己的矩阵数学。
如果要在层次中存储关节,并且数据是局部空间,则需要递归以渲染角色:

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();
}

相关问题