Sign in to follow this  
ChrisArmitt

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

Recommended Posts

ChrisArmitt    109
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:
[code]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);
};[/code]

Share this post


Link to post
Share on other sites
Hodgman    51324
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 ([i]which is very outdated BTW[/i]) I guess you don't have that option.

Share this post


Link to post
Share on other sites
ChrisArmitt    109
[quote name='Hodgman' timestamp='1306063766' post='4814202']
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 ([i]which is very outdated BTW[/i]) I guess you don't have that option.
[/quote]



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 this post


Link to post
Share on other sites
Hodgman    51324
Finding the min/max values in an array is a [url="http://www.google.com.au/search?q=find%20the%20minimum%20and%20maximum%20values%20in%20an%20array"]fairly common exercise[/url].[code]float minX = FLT_MAX, maxX = -FLT_MAX;
for each vert
if vert.x < minX
minX = vert.x
if vert.x > maxX
maxX = vert.x[/code]

Share this post


Link to post
Share on other sites
ChrisArmitt    109
[quote name='Hodgman' timestamp='1306073897' post='4814229']
Finding the min/max values in an array is a [url="http://www.google.com.au/search?q=find%20the%20minimum%20and%20maximum%20values%20in%20an%20array"]fairly common exercise[/url].[code]float minX = FLT_MAX, maxX = -FLT_MAX;
for each vert
if vert.x < minX
minX = vert.x
if vert.x > maxX
maxX = vert.x[/code]
[/quote]

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

it would use the pointList?

so like this:
[code]
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;
}[/code]


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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this