Jump to content
  • Advertisement
Sign in to follow this  
mike74

BVH

This topic is 4864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'd like to get my feet wet with skeletal animation by writing a simple program to load a BVH file. Ideally, I'd like to use a pre-existing data structure from the C++ STL. However, I can't figure out which one would be appropriate. You can take a look at a sample file at http://www.cs.wisc.edu/graphics/Courses/cs-838-1999/Jeff/Example1.bvh Please let me know if you have any ideas. Mike C. http://www.coolgroups.com/zoomer/

Share this post


Link to post
Share on other sites
Advertisement
Hmmm... How about this?

struct Joint
{
float offset[3];
int numchannels;
vector<Joint> children;
}


Mike C.
http://www.coolgroups.com/zoomer/

Share this post


Link to post
Share on other sites
In case anyone's interested, here's some code I made to load a BVH file:

#include <iostream>
#include <vector>
using namespace std;

struct Joint {
char name[80];
float offset[3];
int numchannels;
vector<Joint> v;
};

Joint createjoint(FILE *fp, char *jointname)
{
Joint j;
char line[512];
j.numchannels = 0;
char *p = jointname;
while (*p++) if (*p == '\n') *p = 0;
strncpy(j.name, jointname, 80);
while (fgets(line, 512, fp))
{
strlwr(line);
p = strstr(line, "offset");
if (p) sscanf(p+7, "%f %f %f", &j.offset[0], &j.offset[1], &j.offset[2]);
p = strstr(line, "channels");
if (p) sscanf(p+9, "%d", &j.numchannels);
p = strstr(line, "joint");
if (p) j.v.insert(j.v.begin(), createjoint(fp, p+6));
if (strstr(line, "end site")) j.v.insert(j.v.begin(), createjoint(fp, "endofsite"));
if (strstr(line, "}")) return j;
}
return j;
}

void print(Joint j)
{
cout << "name = " << j.name << endl;
cout << "offset: x=" << j.offset[0] << " y=" << j.offset[1] << " z=" << j.offset[2] << endl;
cout << "numchannels: " << j.numchannels << endl;
cout << "num children: " << j.v.size() << endl;
cout << endl;
vector<Joint>::iterator iter = j.v.begin();
while (iter != j.v.end()) print(*iter++);
}

void main(void)
{
Joint j;
FILE *fp = fopen("test.bvh", "r");
j = createjoint(fp, "root");
fclose(fp);
print(j);
}


Mike C.
http://www.coolgroups.com/zoomer/

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!