# Position of an Object

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

## Recommended Posts

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.pos.x, vertex.pos.y, vertex.pos.z) and then glPop(); or should i use something like glVertex3f(pos.x + vertex.pos.x, pos.y + vertex.pos.y, pos.z + vertex.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 on other sites
Sorry the last sentence sould be "Am i right and sould i change my code into glPop, glTranslate, glPop???"

##### Share on other sites
Hi Songoku,

Every call to glVertex*() implicity multiplies the vertex coordinates by the world and projection matrices. When you call glVertex3f(pos.x + vertex.pos.x, pos.y + vertex.pos.y, pos.z + vertex.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!

• 32
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631350
• Total Posts
2999478
×