Sign in to follow this  
Songoku

Position of an Object

Recommended Posts

Songoku    100
Hi there, my problem is very simple, there is only one decision to take but i do not know which is best. So here is the question: When i have an object to draw at a given position(the position is stored in the object) should i use glPush(); then glTranslate(pos.x, pos.y, pos.z); glVertex3f(vertex[i].pos.x, vertex[i].pos.y, vertex[i].pos.z) and then glPop(); or should i use something like glVertex3f(pos.x + vertex[i].pos.x, pos.y + vertex[i].pos.y, pos.z + vertex[i].pos.z) for every point of the object. I am asking because when i move the object i could calculate the new position (and then add the vertex-positions) of the object or use glTranslate with glPush and glPop. But i do not know which way is faster. Until now i am using the addition inside glVertex3f but i think using glTranslate is faster because it is done in hardware. I am right and should i change the code????

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Hi Songoku,

Every call to glVertex*() implicity multiplies the vertex coordinates by the world and projection matrices. When you call glVertex3f(pos.x + vertex[i].pos.x, pos.y + vertex[i].pos.y, pos.z + vertex[i].pos.z), you are calculating extra additions without avoiding the matrix multiplication.

If you use glTranslate(pos.x, pos.y, pos.z) then the additions are inside the matrix multiplication, but the calls to glPush(), glTranslate() and glPop() could be a considerable overhead when the number of vertices is low.

So, answer: Use glTranslate() if you have many vertices. I don't know how many would be the minimun, but I guess above ten (which saves 30 additions).

Hope it helped!

Share this post


Link to post
Share on other sites

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