Quake 2 md2 file format (theory)

I'm trying to load MD2 files into OpenGL, but I noticed that most sample programs just use

pre-compiled list of normals. something like that.....

//table of precalculated normals { -0.525731f, 0.000000f, 0.850651f }, { -0.442863f, 0.238856f, 0.864188f }, { -0.295242f, 0.000000f, 0.955423f }, { -0.309017f, 0.500000f, 0.809017f }, ... ... 

Well, that might sound pretty silly, but I thought that each model is made up of different triangles, so how then is it possible that you can use one set of precompiled normals to render all the models? This seems odd and any ideas would be appreciated.

+6
c ++ c opengl
source share
3 answers

You can use the precompiled normal table and use the lookup table to select the one that is “good enough” for the particular case. Each triangle is on a separate plane, and this is the plane that has a normal, and not the triangle itself.

For example, imagine that we have a point. Expand this point in the sphere for the purposes of this discussion, this makes conceptual understanding a little easier. If you draw a perfect circle around this sphere on the y axis, then each time rotate this circle on the x axis 1 degree, you end up with 360 circles. If you take normal with an interval of 1 degree along each of these circles, you will get 360 ** 2 points. From there, your normal is the vector from the center of the sphere to this point on the sphere, and this is normal for the plane that is tangent to a point on the sphere. What you will end up if you calculate these two for each point in this area is a pre-computed normal table, which will almost certainly be good enough for most situations. Now you just need to develop a search scheme for this data (plane → normal).

+9
source share

An answer has already been given, but I want to shed some more light on it.

The table contains vectors that cover the surface of a unit sphere quite evenly. It seems that a set of 162 vectors are icosahedron separated angles. This is done to smooth three-dimensional vectors of unit length up to an index (8 bits), see vector quantization . To store any normal vector, you can search the table for the closest match and instead store the index of that match. With this table of 162 well-distributed vectors, the angle between the original vector and the approximated one is expected to be below 11 °, which seems to be good enough for the Quake2 engine.

+6
source share

The MD2 file format indicates that each vertex has a “normal index”, and this is a search in the well-known normal table . I would suggest that these normals are distributed around the sphere. Presumably, the tool that built the model chose the most suitable of these normals for each vertex.

As for the first answer: if you want a very faceted model (for example, a cube), then each polygon really has its own normal one, and each of the vertices making up this polygon should use the same normal vector. However, if you want smooth shading (for example, a torso), for each vertex in the polygon there is usually a different normal vector. This allows you to change the lighting on the polygon, which is useful for both scenarios and pixel axes.

+1
source share

All Articles