Sign in to follow this  

"modifications" in 3D space

This topic is 3861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there. I'm developing a simple .obj loader, which, well, is finished on the "loading" part, but the rotating with mouse feature is quite slow..., my question is, do you always need to redraw the WHOLE model, as in all vertices to do something as simple as rotate an object ?

Share this post


Link to post
Share on other sites
You only need to draw those parts that are visible on the screen. The process of discarding parts that aren't visible is called culling.

The visible parts you obviously have to redraw every time the view changes - it's a different picture every time! The perceived slowness may result from numerous things - you have to tell us a bit more about your program, the way you draw the model, how complex the model is, etc.

Share this post


Link to post
Share on other sites
Ok, this is the function that produces the call lists:

int display_model(struct model *model){
int i,j;
glNewList(whoa,GL_COMPILE);
for(i=0;i<model->faces_count;i++){
glMaterialfv(GL_FRONT, GL_AMBIENT,model->materials[model->faces[i].mat].Ka);
//TEH diffuse render
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
if(model->dtextures[model->faces[i].mat]) glBindTexture(GL_TEXTURE_2D, model->dtextures[model->faces[i].mat]);
else glMaterialfv(GL_FRONT, GL_DIFFUSE,model->materials[model->faces[i].mat].Kd);
glBegin(GL_POLYGON);
for(j=0;j<model->faces[i].count;j++){
glNormal3f(model->vertex_normals[model->faces[i].vertice_normal[j]-1].x,model->vertex_normals[model->faces[i].vertice_normal[j]-1].y,model->vertex_normals[model->faces[i].vertice_normal[j]-1].z);
glTexCoord2f(model->texture_vertexes[model->faces[i].texture_vertice[j]-1].x, model->texture_vertexes[model->faces[i].texture_vertice[j]-1].y);
glVertex3f(model->vertexes[model->faces[i].vertice[j]-1].x,model->vertexes[model->faces[i].vertice[j]-1].y,model->vertexes[model->faces[i].vertice[j]-1].z);
}
glEnd();
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
//TEH specular render
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
if(model->stextures[model->faces[i].mat]) glBindTexture(GL_TEXTURE_2D, model->stextures[model->faces[i].mat]);
else glMaterialfv(GL_FRONT, GL_SPECULAR,model->materials[model->faces[i].mat].Ks);
glBegin(GL_POLYGON);
for(j=0;j<model->faces[i].count;j++){
glNormal3f(model->vertex_normals[model->faces[i].vertice_normal[j]-1].x,model->vertex_normals[model->faces[i].vertice_normal[j]-1].y,model->vertex_normals[model->faces[i].vertice_normal[j]-1].z);
glTexCoord2f(model->texture_vertexes[model->faces[i].texture_vertice[j]-1].x, model->texture_vertexes[model->faces[i].texture_vertice[j]-1].y);
glVertex3f(model->vertexes[model->faces[i].vertice[j]-1].x,model->vertexes[model->faces[i].vertice[j]-1].y,model->vertexes[model->faces[i].vertice[j]-1].z);
}
glEnd();
glDisable(GL_BLEND);
}
glEndList();
}






and it's being used like this:

while(1){
if(oldy<mouse_y) angley+=10;
if(oldx<mouse_x) anglex+=10;
if(oldy>mouse_y) angley-=10;
if(oldx>mouse_x) anglex-=10;
if(oldx!=mouse_x || oldy!=mouse_y){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-20.0f);
glRotatef(anglex,0.0f,1.0f,0.0f);
glRotatef(angley,1.0f,0.0f,0.0f);
glCallList(whoa);
allegro_gl_flip();
}






Actually there are 5 models, each moved a little bit, but I posted the code for only one model to make it simple, and it looks like this http://img442.imageshack.us/img442/9880/dopeyxt0.png
If that's important, I use allegrogl library to simplify the GL stuff :)

Share this post


Link to post
Share on other sites
hmm... a vertex array, as in I'd load a vertex array, and then use some opengl function (which actually?) to draw that aray, which would remove those time consuming 'for' loops? What I wonder is, in big games, lets say GTA just for an example, when I move the mouse, the whole world rotates, so the application redraws EVERYTHING that can be seen ? The city, cars, ppl and the main character? Or is there some trick involved ?

Share this post


Link to post
Share on other sites
yeah, I know how it'll look like, so I need to find the best way to do a really fast redraw, I guess I'll go with those vertex lists, thank You for your help :)

Share this post


Link to post
Share on other sites
Possibly there is a trick, maybe they use gluLookat that speeds up thing but even it needs some maths to rotate. (you can use sin cos or mayby getting the dot product of vectors.

Share this post


Link to post
Share on other sites
well, the slowness is related to those two 'for' loops that need to be executed each model movement, although that gluLookat seems to be a nice idea, as I just 'rotate' the camera, without redrawing the model, which in theory should be fast :D

Share this post


Link to post
Share on other sites

This topic is 3861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this