"modifications" in 3D space

Started by
9 comments, last by V-man 16 years, 11 months ago
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 ?
Advertisement
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.
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 :)
Perhaps you should use Vertex Arrays, Vertex Buffer Objects, or Display Lists to speed things up a bit?
Johnny was a chemist's son by Johnny is no more, for what Johnny thought was H2O was HO4
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 ?
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.
Johnny was a chemist's son by Johnny is no more, for what Johnny thought was H2O was HO4
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 :)
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.
All this also depends on what your computer is. What video card, drivers, etc.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
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

This topic is closed to new replies.

Advertisement