   How to draw?
  Hello,How to draw an hierarchial bone structure in OpenGL?I wrote a code:class Bone {public:Vector3 p;void Draw();typedef std::list<Bone *> BL;BL b;};void Bone::Draw() {glPushMatrix();glTranslatef(p.x,p.y,p.z); /* For now only Translation. Because i am using quaternions */glBegin(GL_LINES);glVertex3f(0,0,0);glVertex3f(/*What to write in here*/);glEnd();glTranslatef(/* And here */);for(BL::iterator i = b.begin(); i != b.end(); ++i) {(*i)->Draw();}glPopMatrix();}Please tell me which of them is better:Adding Length or Adding End PositionThanks,Kasya   
  Moving to the OpenGL forum.   ;  Sorry I haven't got time for a detailed reply. Here's how I did it:void Skeleton::DrawGL(){   vector<Joint>::iterator ji;   Joint* j;   vector<unsigned int>::const_iterator i;   glColor3f(0.0f,0.0f,0.0f);   //draw the bones   glBegin(GL_LINES);   //for each joint   for(ji=joints.begin();ji!=joints.end();ji++)   { j = &(*ji); //draw a line between it and each of it's children for(i=j->children().begin();i!=j->children().end();i++) {    glVertex3dv(joints[(*i)].absolute().pos());    glVertex3dv(joints[joints[(*i)].parent()].absolute().pos()); }   }   glEnd();   glColor3f(1.0f,1.0f,1.0f);   //draw the joints   glBegin(GL_POINTS);   //for each joint   for(ji=joints.begin();ji!=joints.end();ji++)   { j = &(*ji); //draw a point glVertex3dv(j->absolute().pos());   }   glEnd();};  Thanks for help. Is there difference between joint and bone system?   ;  No, 'bone' and 'joint' are interchangeable. I use 'joint' because it seems to fit better.One thing worth looking out for: Although I store my joints using relative positions and orientations, the code above uses the absolute positions NOT the relative ones. I found it quicker and easier to calculate this than to use the GL matrix stack to do it.   ;  I am just interested. Can i disarm a part of body using joint system? I mean maybe you remember Imran Zakaev mission in COD4: His arm disarms. Can i do it with this system? Or i have to add length or end position or something like that?Thanks,Kasya[Edited by - Kasya on May 12, 2009 11:06:42 AM];  If the arm gets blown off, it's position and orientation no longer rely on the shoulder bone's position and orientation, so there's no real use in relating it to the skeleton any more.You'd maybe switch to a different mesh/submesh for the character - the same but with the arm missing. Add an unconnected severed arm mesh, and do whatever animation or physics you like on it as a seperate entity.You could still use the same animations (i.e. with keyframes for the entire skeleton including the missing arm) with the armless mesh.   ;  Oh i understand. I never thought of that thanks!! :)   ;  You never used rotation in your code. That means you just use: instead of Translate: 1,1,1; Rotate: 45degree to yyou useTranslate (something like that): 1, sqrt(2)/2, 1if it is like that, how you animate it? You just change positions and nothing else?Kasya   ;  i wasn't readed all replys but here quick guide (pseudo code),void drawbone(bone* bn){  drawline(bone->xyz, bonechild->xyz)  for ( int i =0 ; i < bn->childcount ; i++)  {drawbone(bn->child);  }}func drawbones(){  bone* base = getbasebone()  drawbone(base)}so bone->xyz means translation row or column from your bone matrix. you need to draw first bone's translation center to it's childs center. i gave you a recursive function, which will draw entire bone structure. also you dont need to use rotation matrices because single vertex which is center of bone, doesn't has any rotation.Quote:Original post by KasyaYou never used rotation in your code. That means you just use: instead of Translate: 1,1,1; Rotate: 45degree to yyou useTranslate (something like that): 1, sqrt(2)/2, 1if it is like that, how you animate it? You just change positions and nothing else?Kasyayou dont need to use rotations while drawing lines. just interpolate between positions for animating it. you will use rotations when it has vertexes attached to it. if you asking animating with vertexes attached to it better to use quaternions for bone rotations and create a rotation matrix with it. then generate vectors of attached vertexes. ( vertexpos - bonepos ) and multiply it with rotation matrix then add bonepos to it again. while animating between two rotations, you will use spherical interpolation between two quaternions.   