# Calculating x,y,z of each frame in an MD2

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

## Recommended Posts

My university lecturer mentioned only briefly that it was possible to calculate the xyz sizes of an MD2 model per frame so that you can get accurate values for a bounding box.
However, this was only briefly mentioned and I could not find information relating to this. Perhaps I was not searching for the correct terminology, or I misunderstood him.

Either way, a little bit of help with this would be much appreciated.

What I want to know is, how do i get the x y and z sizes of an MD2 model in C++. In terms of loading the model, I am using an MD2 loader based off chapter 18 of "OpenGL Game Programming".

The header for what I'm using:
class MD2Model{ modelData_t *myModel; modelData_t *gunModel; float interValue; public: MD2Model(); ~MD2Model(); modelData_t* LoadMD2Model(char *filename, char *textureName); void DisplayMD2(modelData_t *model, int frameNum); void DisplayMD2Interpolate(modelData_t *model); void DisplayMD2Interpolate(modelData_t *model, int startFrame, int endFrame, float percent); private: texture_t* LoadBMPTexture(char *filename); void getTriPoints(modelData_t *model, int tIdx); };

##### Share on other sites
After loading the file, you can make an array of bounding-box structures of size [font="Lucida Console"]num_frames[/font]. For each frame, get the vertex positions. For each position, find the min+max of the x/y/z components. Use these min/max values to make an AABB and put it in the array.

Then later when you want to get an AABB for the model, you just have to use the frame-number as an index into this array.

Ideally your build-tools / exporters would do this and save the array into the file-format so you don't have to calculate it on load, but if you're using an existing format like MD2 (which is very outdated BTW) I guess you don't have that option.

##### Share on other sites

After loading the file, you can make an array of bounding-box structures of size [font="Lucida Console"]num_frames[/font]. For each frame, get the vertex positions. For each position, find the min+max of the x/y/z components. Use these min/max values to make an AABB and put it in the array.

Then later when you want to get an AABB for the model, you just have to use the frame-number as an index into this array.

Ideally your build-tools / exporters would do this and save the array into the file-format so you don't have to calculate it on load, but if you're using an existing format like MD2 (which is very outdated BTW) I guess you don't have that option.

This was my plan already, to create an array of bbs of the size of how many frames.
The problem is, I don't know how to find the min and max of the xyz components.

##### Share on other sites
Finding the min/max values in an array is a fairly common exercise.float minX = FLT_MAX, maxX = -FLT_MAX; for each vert if vert.x < minX minX = vert.x if vert.x > maxX maxX = vert.x

##### Share on other sites

Finding the min/max values in an array is a fairly common exercise.float minX = FLT_MAX, maxX = -FLT_MAX; for each vert if vert.x < minX minX = vert.x if vert.x > maxX maxX = vert.x

ok so, in terms of the md2 struct I have.

it would use the pointList?

so like this:
 float minX = 9999.0f; //high number float maxX = -9999.0f; //low number for each (pointList){ if (pointList.x < minX) minX = pointList.x; if (pointList.x > maxX) maxX = pointList.x; }

If so, omg it's so simple, how the hell did I not realize that XD. (Maybe it has something to do with the lack of sleep i've had lately working on this assignment.

Another question though, theres only 1 point list, so how would it be split up for each frame?, I can understand this working if there was only 1 frame to work with, but with something that has multiple frames, surely it would go through all the points in all the frames.

• 40
• 15
• 10
• 23
• 10