PDA

View Full Version : MD3 Rendering Problems



nukem
08-24-2003, 08:31 PM
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 (http://zonkbonk.virtualave.net/NuclearBSP.png) .

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?




glPushMatrix();
//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);
//render it
entities[i].model.Render(0);
glPopMatrix();


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);
}

for(int i=0;i<header.meshcount;i++)
{
//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(meshes[i].settexture)
{
glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, meshes[i].texture);
}else{
//if we dont have a texture turn texture mapping off
glDisable(GL_TEXTURE_2D);
}

//if there are default textures render them
if(meshes[i].skins)
{
glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, meshes[i].skins[0]);
}

glBegin(GL_TRIANGLES);

for(int j=0;j<meshes[i].meshheader.trianglecount;j++)
{
for(int k=0;k<3;k++)
{
//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
if(meshes[i].texcoords)
{
glTexCoord2f(meshes[i].texcoords[index].texturecoord[0], meshes[i].texcoords[index].texturecoord[1]);
}

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));
}
}
glEnd();
}
}


Thanks
Nuke

timfoleysama
08-25-2003, 09:55 AM
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.

nukem
08-25-2003, 11:54 AM
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?

Thanks
nuke

[This message has been edited by nukem (edited 08-25-2003).]

SirKnight
08-25-2003, 02:16 PM
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.

-SirKnight

nukem
08-25-2003, 05:42 PM
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[1];
//copy z into y
temp[1] = temp[2];
//copy the oposite of y into z
temp[2] = -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.

3DG
08-26-2003, 01:17 PM
if your coord sys is gl this should work, probably

glRotatef ( -90, 1, 0, 0 );
glRotatef ( -90, 0, 0, 1 );

g

bozland
08-26-2003, 01:28 PM
Try center object. Take MD3 Object BBox

Vector3D center=BBox.Center();
float half_height=(BBox.maxY-BBox.minY)/2;

glPushMatrix();
glTranslate(x_org,y_org,z_org);
glTranslate(x_org,y-half_height,z_org);
// and now rotate
glRotate(?,?,?,?);
glPopMatrix();


May be help http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by bozland (edited 08-26-2003).]

nukem
08-26-2003, 09:39 PM
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.

SirKnight
08-27-2003, 05:26 AM
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.


-SirKnight

nukem
08-27-2003, 02:09 PM
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.

nukem
08-27-2003, 08:25 PM
SirKnight: Now that I look at BSPs the textures are upside down. Changing my code to




glTexCoord2f(meshes[i].texcoords[index].texturecoord[0], 1 - meshes[i].texcoords[index].texturecoord[1]);


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?

thanks
nuke

[This message has been edited by nukem (edited 08-28-2003).]