Advertisement

Question about GameTut#4 (MD2)

Started by July 15, 2001 05:27 AM
4 comments, last by HalfLucifer 23 years, 7 months ago
First of all, I have to say that this one is such a brilliant tutorial at all! I''ve ever seen a lot source code about MD2 loading before, however, I always got confused with them. This tutorial and code is really the clearest and nicest I ever read. Big thanks for Trent Polack''s hard works! Hey, any further plan moving on MD3 loading tutorial? However, I still got several questions in my mind so that I cannot totally understand it: Q1. Why no any vertex normals are specified using glNormal3f() while loading MD2 models? The tutorial says MD2 uses lookup table to index the normals, but I can find no predefined tables about it. Is it kept by Quake2''s main program? If I''d like to use the MD2 loading code in my program, how can I get the proper vertex normals to make lighting interaction right? Q2. In the MD2::Render(), while we''d fill the vertList[] with vertices data, about the following two lines: vertList[index].z= -((currentFrame->vertices[vertIndex].vertex[1]*currentFrame->scale[1])+currentFrame->translate[1]); vertList[index].y= ( (currentFrame->vertices[vertIndex].vertex[2]*currentFrame->scale[2])+currentFrame->translate[2]); Why the vertList[index].z is using vertex[1] and vertList[index].y is using vertex[2]? Q3. While rendering with triangle fans, why shall we use v1.SendToOGL() instead of glVertex3fv(v1.vertex) to specify vertex? I could not figure out what the SendToOGL() means and works. Q4. In the MD2_FRAME_TYP{} structure, we never used name[16] for the frame''s name in MD2 usage, why keeping this variable? Q5. How can we determine the predefined MD2 state frame number constants? For example, how can we determine that 40 frames is required from IDLE1_START to IDLE1_END, and only 6 frames is required from RUN_START to RUN_END, etc....?
Well, I have a go at answering some of your questions.....

Q1) That mysterious "anorms" file in the Quake source code is actually a list of vertex normals for for the models. The numbers all seem a little random to me but the indicies in the MD2 format correspond to the particular vertex normals from the MD2 vertex normals supplied by the engine.

Q2) The Quakes have a different coordinate system to OpenGL, in that in Quake the z axis is vertical, whereas the y axis is vertical in ogl. This line just flips the model orientation.

Q3) SendToOGL() is pretty much glVertex().

Q4) Each frame can have a name like "salute", "taunt", "stand", etc, this structure holds that information. The tut does not load it because it is not very useful normally.

Q5) Not sure, get back to you on that....

Hope this helps (but I''m not sure any of this is Gospel).
Advertisement
1) Check out my OGL tutorial. It''s also about MD2 rendering. You''ll find the anorms.h file stuff there (look at the code, you''ll see a lot of numbers somewhere)

5) Check that url:
http://www.planetquake.com/polycount/resources/quake2/q2frameslist.shtml

There''s a description on what frame is the start/end of what animation. Look at the last column of the table. With my tut you have to divide 1 from those nr-s to get the correct nr.
Don''t know about Trent Polack''s tut.



---
cone3d
http://cone3d.gz.ee
PS: The dog ate my homework
---cone3dhttp://cone3d.gamedev.netMy software never has any bugs - it just generates random features
Hey, thanks for your answers and useful info.

I''ve checked the anorm.h out.
If I''d like to apply it to my MD2 model, I should fill it with "lightNormalIndex".
Am I right? But how to index it?
Can the magic mysterious anorm.h match ANY MD2 model and get the lighting interaction right?
How does it do?
Or maybe I should calculate normals by myself while loading triangle data?
Hi...
I found this in some MD2 loader on my disk...

before you declare structurs you have :
(sorry I don''t know how to use C++ code in HTML)

#define NUMVERTEXNORMALS 162
float avertexnormals[NUMVERTEXNORMALS][3] = {
#include "anorms.h"
};

then when loading model you have :


frames.vertices[j].normal[0] = avertexnormals[frame->alias_vertices[j].lightNormalIndex][0];
frames.vertices[j].normal[1] = avertexnormals[frame->alias_vertices[j].lightNormalIndex][1];<br>frames.vertices[j].normal[2] = avertexnormals[frame->alias_vertices[j].lightNormalIndex][2];<br><br>the var names are not the same as in tutorial but I think you''l get it.<br><br>And yes, "anorms.h" can be applied to any md2 model..<br><br><br> </i> <br><br>There are more worlds than the one that you hold in your hand…
You should never let your fears become the boundaries of your dreams.
Hey, thanks a lot for your reply
While applying normals to MD2 models, I have to say that, it does looks so GREAT and so wonderful!

I''ve checked the "MD2 frame list" at Polycount:
http://www.planetquake.com/polycount/resources/quake2/q2frameslist.shtml
I found there''s something strange.
In the animation "STAND", it takes from frame #1 to frame #40; but when I tried to test it,
I found the animation "STAND" seems to be taking from frame #1 to #39, whereas #40 should be for next animation''s start frame.

Had anyone found the same problem?

This topic is closed to new replies.

Advertisement