Jump to content
  • Advertisement
Sign in to follow this  
Songoku

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.

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

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 this post


Link to post
Share on other sites
Advertisement
Sorry the last sentence sould be "Am i right and sould i change my code into glPop, glTranslate, glPop???"

Share this post


Link to post
Share on other sites
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.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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!