I am implementing entities into my BSP engine, as you know many entities are MD3’s. I have written the code to read and render MD3/entities. But I have two problems as you can see here .
The first problem is the model is on/in the floor but I have put in code to make the model rendered in the correct angle, for some reason it does not work. Can someone please take a look at it and tell me whats wrong?
//move the model to were it should be in the map
glTranslatef(entities[i].origin->x, entities[i].origin->y, entities[i].origin->z);
//rotate the model
glRotatef(entities[i].angle, entities[i].origin->x, entities[i].origin->y, entities[i].origin->z);
The second problem is its not textured. All MD3’s have pathes to images that they use by default stored in them(the skins you have to load but dont use). These textures are almost always used, the only time there not is in player models, they use skin files. I have put in code to read and render the textures but for some reason they still do not show up. Can someone tell me whats wrong with my code?
//this will render a model in a given frame
void NuclearMD3::Render(int Frame)
static time_t oldtime = 0;
if(oldtime == 0)
oldtime = time(0);
//find the starting index for the key frame we are on
int currentindex = Frame * meshes[i].meshheader.vertcount;
//find the next index key frame;
int nextindex = (Frame + 1) * meshes[i].meshheader.vertcount;
//if it has been skinned render the skinned textures
//if we dont have a texture turn texture mapping off
//if there are default textures render them
//this gets the index for our current point in the face list
int index = meshes[i].triangles[j].vertexindices[k];
//if we have texture coords set them
time_t currtime = time(0);
double t = difftime(time(0), oldtime);
oldtime = currtime;
//find the current and next frames vertex
Vect3 p1(meshes[i].verts[currentindex + index].vertex);
Vect3 p2(meshes[i].verts[nextindex + index].vertex);
glVertex3f(p1.x + t * (p2.x - p1.x), p1.y + t * (p2.y - p1.y), p1.z + t * (p2.z - p1.z));
I don’t know if this is an ‘advanced’ problem, but just a quick comment:
In your top code block, when you do your glRotatef call you are passing in the origin of your model as the axis to rotate around. This is almost certainly wrong. You should be passing in some unit vector (not a position) to rotate around. Try (0,1,0).
As for your skins not showing up, I’d reccomend tracing the code that actually loads the texture images for the skin.
I tryed glRotatef(entities[i].angle, entities[i].origin->x, entities[i].origin->y, entities[i].origin->z) out of depriation since nothing else worked. I tryed glRotatef(entitie[i].angle, 0, 1, 0) and its still in the ground. Anyone know how to get it upright?
[This message has been edited by nukem (edited 08-25-2003).]
Quake 3 (and every other engine by Carmack) uses a different coord system than OpenGL’s. Carmack has z and y axis swapped. Where +z is going up and +y is going out of the monitor (or is it the other way around for y, I forget exactly atm). So try swapping your y and Zs and see if that helps.
I do swap the x and the y with this code
//get the xyz data from the entitie string
float* temp = GetABCData(line);
//copy y into a temp var
float temp2 = temp;
//copy z into y
temp = temp;
//copy the oposite of y into z
temp = -temp2;
Also for the rotation code I have tryed glRoatef(entities[i].angle, 0, 1 ,0) changing the 1 around but I get pretty much the same results everytime its not up right. I think it has something to do with that code though.
if your coord sys is gl this should work, probably
glRotatef ( -90, 1, 0, 0 );
glRotatef ( -90, 0, 0, 1 );
Try center object. Take MD3 Object BBox
// and now rotate
May be help
[This message has been edited by bozland (edited 08-26-2003).]
I figured out what was wrong. I didnt switch the z and y in the MD3 model. I thought you only had to do it in the BSP. I still have the problem with the textures. Im going to play around with that tonight. Im 100% sure its not an error when loading because the same code loads all my other textures and they load fine, plug theres a hell of alot of error checking.
Heh, I knew that’s what the problem was. I ran into the same thing a long time ago. About the textures, let me guess, it’s upside down isn’t it? What’s happening is the t texture coord is going the wrong direction. Replace t with 1-t and it should work.
Nope, whats wrong with the textures is they dont show at all. All I see is a big black object, sometimes it has some textures from things around it.
SirKnight: Now that I look at BSPs the textures are upside down. Changing my code to
glTexCoord2f(meshes[i].texcoords[index].texturecoord, 1 - meshes[i].texcoords[index].texturecoord);
Seems to have fixed it for the MD3’s. Is that what your talking about? In my BSP code I do nothing to it and everything looks fine, did you add anything to your BSP texturing code?
[This message has been edited by nukem (edited 08-28-2003).]