# "modifications" in 3D space

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

## 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 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 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.mat].Ka);//TEH diffuse renderglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);if(model->dtextures[model->faces.mat]) glBindTexture(GL_TEXTURE_2D, model->dtextures[model->faces.mat]);else glMaterialfv(GL_FRONT, GL_DIFFUSE,model->materials[model->faces.mat].Kd);glBegin(GL_POLYGON);for(j=0;j<model->faces.count;j++){glNormal3f(model->vertex_normals[model->faces.vertice_normal[j]-1].x,model->vertex_normals[model->faces.vertice_normal[j]-1].y,model->vertex_normals[model->faces.vertice_normal[j]-1].z);glTexCoord2f(model->texture_vertexes[model->faces.texture_vertice[j]-1].x, model->texture_vertexes[model->faces.texture_vertice[j]-1].y);glVertex3f(model->vertexes[model->faces.vertice[j]-1].x,model->vertexes[model->faces.vertice[j]-1].y,model->vertexes[model->faces.vertice[j]-1].z);}glEnd();glEnable(GL_BLEND);glBlendFunc(GL_ONE, GL_ONE);//TEH specular renderglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);if(model->stextures[model->faces.mat]) glBindTexture(GL_TEXTURE_2D, model->stextures[model->faces.mat]);else glMaterialfv(GL_FRONT, GL_SPECULAR,model->materials[model->faces.mat].Ks);glBegin(GL_POLYGON);for(j=0;j<model->faces.count;j++){glNormal3f(model->vertex_normals[model->faces.vertice_normal[j]-1].x,model->vertex_normals[model->faces.vertice_normal[j]-1].y,model->vertex_normals[model->faces.vertice_normal[j]-1].z);glTexCoord2f(model->texture_vertexes[model->faces.texture_vertice[j]-1].x, model->texture_vertexes[model->faces.texture_vertice[j]-1].y);glVertex3f(model->vertexes[model->faces.vertice[j]-1].x,model->vertexes[model->faces.vertice[j]-1].y,model->vertexes[model->faces.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 on other sites
Perhaps you should use Vertex Arrays, Vertex Buffer Objects, or Display Lists to speed things up a bit?

##### 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 on other sites
Everything must be redrawn. If you want to see what it will look like if you don't redraw it, don't clear the colour buffer.

##### 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 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 on other sites
All this also depends on what your computer is. What video card, drivers, etc.

##### 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

1. 1
2. 2
Rutin
25
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 22
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631764
• Total Posts
3002210
×