Archived

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

KalvinB

Mild MD2 problem

Recommended Posts

KalvinB    102
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 ]
Will post for food.

Share this post


Link to post
Share on other sites
Sander    1332
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
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]


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

Share this post


Link to post
Share on other sites
Sander    1332
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
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]


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

Share this post


Link to post
Share on other sites
KalvinB    102
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 ]


Will post for food.

Share this post


Link to post
Share on other sites