Archived

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

4GR3V_-_NoD

NEED HELP wih a MD2 loader

Recommended Posts

hi guys, im doing a md2 loader, based mostly in the sample of opengl game programming book, basically, i just changed the variables, and some other little things, the problems is that it loads the model well, but im having troubles with the display method. here is the code:
void DisplayMD2(model_data_s *model, int num_frame){
		
	CVector3 *frame_vertices;
	CVector3 temp;

	int i;

	frame_vertices = &model->vertex_list[model->num_vertices*num_frame];

	
	glBegin(GL_TRIANGLES);

	for(i=0;i<model->num_triangles;i++){
			
		glVertex3f(frame_vertices[model->triangle_list[i].vertex_indices[0]].x,
					frame_vertices[model->triangle_list[i].vertex_indices[0]].y,
					frame_vertices[model->triangle_list[i].vertex_indices[0]].z);

		glVertex3f(frame_vertices[model->triangle_list[i].vertex_indices[2]].x,
					frame_vertices[model->triangle_list[i].vertex_indices[2]].y,
					frame_vertices[model->triangle_list[i].vertex_indices[2]].z);

		glVertex3f(frame_vertices[model->triangle_list[i].vertex_indices[1]].x,
					frame_vertices[model->triangle_list[i].vertex_indices[1]].y,
					frame_vertices[model->triangle_list[i].vertex_indices[1]].z);
	}
	

	glEnd();
}
 
frame_vertices is an array of objects of the class CVector3, this class has a x, y and z float member values. the debugger tells me that this (x, y and z) expressions cant be evaluated: CXX0030: Error: expression cannot be evaluated any ideas?? Thanks.

Share this post


Link to post
Share on other sites
the problems isnt the loop code, is just i dont know why that part of the fort doesnt display well here.

the problem is with the i pass to glVertex3f, the compiler cant evaluate them, dont know what im doing bad.

Share this post


Link to post
Share on other sites
if frame_vertices is a pointer of type CVector3 you can''t access its elements like you have

you need to write
frame_vertices[0]->x; 

not
frame_vertices[0].x; 


-----------------------
"Without a sense of humour we couldn''t react to a lot of things"

Share this post


Link to post
Share on other sites
quote:
Original post by jhavna
if frame_vertices is a pointer of type CVector3 you can''t access its elements like you have

you need to write
frame_vertices[0]->x;  

not
frame_vertices[0].x;  


-----------------------
"Without a sense of humour we couldn''t react to a lot of things"



Incorrect, the [] dereferences the pointer.

As for the "cannot evaluate expression", that means that the variable is either out of scope, or has no valid value at that point in the code. Make sure that you aren''t overstepping the bounds of the arrays that you''re using, the pointers are all valid, etc...


Death of one is a tragedy, death of a million is just a statistic.

Share this post


Link to post
Share on other sites
whoops.. i missed that.. thought it was an array of pointers.. apologies

-----------------------
"Without a sense of humour we couldn't react to a lot of things"

[edited by - jhavna on August 8, 2003 11:45:27 AM]

Share this post


Link to post
Share on other sites
I don't see anything wrong with your code, so it could be that you load the model incorrectly. Anyway, the display code for the md2 'should' be something like:


void DrawModel(const MD2Modeli* modeli, int frame_num)
{
int vertex_num; // How many vertices of the type

const int* glCommand; // Pointer to the GL Commands

const Vector3f* vertex; // Pointer to the models vertices

const Vector3f* normal; // Pointer to the normals vertices

int index; // Index of the vertices


// Get vertices and GL commands

glCommand = modeli->model->glCommands;
vertex = &modeli->model->vertices[modeli->model->numVertices * frame_num];
normal = &modeli->model->normals [modeli->model->numVertices * frame_num];

// Bind skin texture

glBindTexture(GL_TEXTURE_2D, modeli->textureID);

// Loop til end of GL Commands

while(*glCommand != 0)
{
// Check what type to draw

if(*glCommand > 0)
{
// Strip

vertex_num = *glCommand++;
glBegin(GL_TRIANGLE_STRIP);
}
else
{
// Fan

vertex_num = -*glCommand++;
glBegin(GL_TRIANGLE_FAN);
}

// Draw a number of vertices in the specified way

while(vertex_num--)
{
float u = *(float*)glCommand++; // Read as float

float v = 1 - *(float*)glCommand++; // Beacuse of Z->Y switch

index = *glCommand++;

glTexCoord2f(u, v);
glNormal3fv((float*)&normal[index]);
glVertex3fv((float*)&vertex[index]);
}

// End this type

glEnd();
}

return;
}


Vector3f is the same as your vector class.
glCommands are laoded from the model. The GL Game Programming book loads the commands but doesn't use them.

(This is not the best way to draw the model, but it works if you've loaded the model correctly. A better way is to put it in some sort of Vertex Array.)

Actually, I don't think this will help you much

[edited by - dta1 on August 8, 2003 3:40:39 PM]

Share this post


Link to post
Share on other sites