Hi, I am trying to display motion by parsing a bvh(bio vision hierarchy) file using immediate mode openGL. I have loaded the hierarchy data into an array of type user-defined class as shown below:
class joint
{
public:
string name;
float offset[3];
int channel_num;
int channel_order_flag;
float channels[6];
int parent_index;
public:
joint(void);
~joint(void);
};
I have loaded motion data in to a 2D array such as it is one frame for each row. I have 436 frames in a example bvh file I am trying to display. I am trying to display the data frame by frame after a time delay of 33 miliseconds after every frame. This is the code I have written and my display function also is shown.
void skeleton::drawStick(int q)
{
for(int i=1,p=6;i<26&&p<69;i++,p++)
{
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_STRIP);
glRotatef(motion[q][5],0,0,1);
glRotatef(motion[q][3],1,0,0);
glRotatef(motion[q][4],0,1,0);
glTranslatef(motion[q][0],motion[q][1],motion[q][2]);
glVertex3f(bodyPart[0].offset[0], bodyPart[0].offset[1], bodyPart[0].offset[2]);
if(bodyPart[i].parent_index!=i-1)
{
glEnd();
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_STRIP);
glRotatef(motion[q][p],0,0,1);
glRotatef(motion[q][p+1],1,0,0);
glRotatef(motion[q][p+2],0,1,0);
glTranslatef(bodyPart[bodyPart[i].parent_index].offset[0],bodyPart[bodyPart[i].parent_index].offset[1],bodyPart[bodyPart[i].parent_index].offset[2]);
glVertex3f(bodyPart[bodyPart[i].parent_index].offset[0],bodyPart[bodyPart[i].parent_index].offset[1],bodyPart[bodyPart[i].parent_index].offset[2]);
}
glRotatef(motion[q][p],0,0,1);
glRotatef(motion[q][p+1],1,0,0);
glRotatef(motion[q][p+2],0,1,0);
glTranslatef(bodyPart[i].offset[0], bodyPart[i].offset[1], bodyPart[i].offset[2]);
glVertex3f(bodyPart[i].offset[0], bodyPart[i].offset[1], bodyPart[i].offset[2]);
glEnd();
}
}
note: q is a global variable.
my display function is:
void display()
{
while(q<436)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the color buffer bit
THREED.drawGrid();
THREED.drawCS();
glMatrixMode(GL_MODELVIEW);
SKELETON.drawStick(q);
glutSwapBuffers();
q++;
break;
}
}
I am getting a messed up output of the drawing as if it has drawn all the motion data of each frame and displayed at once.
Since I am a rookie in openGL, guide me through the best way to display my motion data frame by frame correctly.
Any help will be greatly appreciated.
Thanks in advance.