• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Mild MD2 problem

## Recommended Posts

I'm writting a platform engine because I can and I'm having a small problem. If I represent the player with a cube everything is great. It's centered properly, it rotates properly, etc. However, if I render an MD2 model instead of the cube it doesn't center and rotate properly. There's no change to the translation or rotation or anything. It's just one line of code. Instead of graphicsAPI.drawcube() it's graphicsAPI.drawMD2(). When I go left the charater shifts to the left, when I go right it shifts to the right. Same on the z axis. I tried a Quake 2 model and had the same problem. I'm using GameTutorial.com's MD2 loading/rendering example with a number of bugs already worked out (including one today where if you changed the animation number in the middle of a sequence it goes bizerk for a frame) and am wondering if anyone else has had this problem as well and how they fixed it. Ben [ IcarusIndie.com | recycledrussianbrides.com ]

##### Share on other sites
I''m not exactly sure what you mean. Can you explain it a bit better perhaps? going left when you press left sounds about right (no pun intended).

Did you remember to rotate the MD2 90 degrees around the up (y) axis? MD2 orientation is normally with x-axis positive being the forwar direction, instead of z-negative witch is normally used in OpenGL.

Sander Maréchal

GSACP: GameDev Society Against Crap Posting
To join: Put these lines in your signature and don''t post crap!

##### Share on other sites
It's failing to rotate the model around the z axis properly. It's off center.

Ben

[ IcarusIndie.com | recycledrussianbrides.com ]

[edited by - KalvinB on August 15, 2003 5:29:58 PM]

##### Share on other sites
Do you use the command glScalef() or something similar in your MD2 rendering code? Most MD2 renderers do this because MD2''s are quite big (32x32x64 units). This means that rotations will also get scaled!

A better way would be to manually scale the vertices when you load the MD2 model and stay away from glScalef.

Sander Maréchal

GSACP: GameDev Society Against Crap Posting
To join: Put these lines in your signature and don''t post crap!

##### Share on other sites
The model is being manually scaled, translations in the MD2 file are thrown out and with a mild fixed adjustment to the vertices "fixes" the problem. Although there must exist some MD2 modeler that will center the vertices.

for (int j=0; j < m_Header.numVertices; j++){	pVertices[j].vertex[0] = pFrame->aliasVertices[j].vertex[0] * pFrame->scale[0]-0.05;// + pFrame->translate[0];	pVertices[j].vertex[2] = -1 * (pFrame->aliasVertices[j].vertex[1] * pFrame->scale[1]-0.05);// + pFrame->translate[1]);	pVertices[j].vertex[1] = pFrame->aliasVertices[j].vertex[2] * pFrame->scale[2];// + pFrame->translate[2];}

I''d rather not need that -0.05 in there because other models may not be off the same amount. So how do I remove the need for that adjustment in my code?

Ben

[ IcarusIndie.com | recycledrussianbrides.com ]

##### Share on other sites
In your MD2 loading routine build a bounding box, then manually translate the MD2 so that it''s center will be at 0, according to the bounding box.

Height Map Editor | Eternal Lands | Fast User Directory

• ### Forum Statistics

• Total Topics
627694
• Total Posts
2978672

• 19
• 14
• 12
• 10
• 12