To glTranslate, or not to glTranslate

Sage
Posts: 1,066
Joined: 2004.07
Post: #1
Looking back on tutorials, many use the glTranslate command to move the imaginary center so that they used vertices that are more size oriented (they never change unless the object gets larger or smaller) whereas I'm just using glVertex and using the absolute values of my object.

Which way do you use/Which way is better for efficiency and uses?
Quote this message in a reply
Member
Posts: 184
Joined: 2004.07
Post: #2
Every single vertex is always transformed with both the modelview and projection matrix (even if they are the identity matrices) regardless of the vertex's position, so there is no difference in efficiency. You should use whatever is more convenient for you to think about.
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #3
Suppose I wanted to be able to rotate my objects. How complicated would it be to simply use the absolute coordinates to do such? I suppose it would be much easier doing glTranslate and glRotate for that but I'm rather partial to absolute coordinates.
Quote this message in a reply
Member
Posts: 184
Joined: 2004.07
Post: #4
If you wanted to rotate your objects ahead of time, you would just figure out the rotation matrix you wanted to use and then just multiply each vertex by the matrix yourself instead of having OpenGL do it. Of course, if you did this every frame yourself, it would be less efficient than if OpenGL had done it for you.
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #5
Having all your vertices in absolute world coords can make things like shadows easier in some cases.

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
Member
Posts: 277
Joined: 2004.10
Post: #6
Rotating your vertexes manualy takes 3D vector math...
(but you probebly knew that)


Nick Wrote:I'm rather partial to absolute coordinates

Me too... Smile
I hate having to use the glRotatef function... Smile
I mostly just use it those for camera functions.

I very rarely use glTranslatef (only if I need to rotate objects around there center)...


Quote:Which way do you use/Which way is better for efficiency and uses?

Just a thought, but wouldn't each and every video card have different efficiency.

Like I said I don't try to use the translation calls except glRotatef with
camera functions.

Global warming is caused by hobos and mooses
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #7
BinarySpike Wrote:Just a thought, but wouldn't each and every video card have different efficiency.

No. Unless I'm greatly mistaken, OpenGL's vertex transformations happen on the CPU.

- Alex Diener
Quote this message in a reply
Apprentice
Posts: 17
Joined: 2005.05
Post: #8
I thought it happened on the GPU, since most new games require HT&L support, or Hardware Transform and Lighting. I presume that means that the coordinates are transformed on the GPU :/

—
BearIsCoding
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #9
perhaps I'm misunderstanding, or perhaps you're greatly mistaken Wink

hardware transform and lighting cards (geforces, radeons) do the vertex transformations in hardware.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #10
*except Radeon 7000.
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #11
You learn something new every day, I guess. My mistake.

- Alex Diener.
Quote this message in a reply
tigakub
Unregistered
 
Post: #12
Nick Wrote:Suppose I wanted to be able to rotate my objects. How complicated would it be to simply use the absolute coordinates to do such? I suppose it would be much easier doing glTranslate and glRotate for that but I'm rather partial to absolute coordinates.

Unless you were doing some wierd vertex level stuff -- like morphing -- it would actually be quite a waste of OpenGL to use anything other than glTranslate, glRotate and glScale.

1. All vertices are passed through the projection matrix and the model view matrix, whether you use glTranslate, glRotate, or glScale or not. glTranslate, glRotate, and glScale merely allow you to set up the model view matrix. Just because you don't use them, doesn't actually mean you're bypassing OpenGL's matrix operations. Think of the model view matrix as an accumulator. Each time you use glTranslate, glRotate, or glScale, you're accumulating transformations. Let's say you start out with the identity matrix, I, and you apply a scaling, S, a rotation, R, and a translation, T. To get the final result, you get a model view matrix which is the matrix product M = TRSI. All these transformations are "accumulated" into the model view matrix, M, and it is this transformation matrix that is applied to each vertex, not the 4 individual I, S, R, and T matrices.

2. If you just use glVertex, and do all the matrix math yourself, you will have to maintain two copies of your geometry -- one to keep the original geometry, and one to hold the transformed geometry. Otherwise, due to finite precision, your geometry will deform after iterative transformations, as you seem to have observed in another post. And even then, the transformed vertices will still each go through the model view matrix. This means that you are performing a lot of extra work for nothing. As an exercise in linear algebra, it may be interesting, but unless you were writing the rendering engine from the bit up, it's really not the way to go.

3. OpenGL's matrix operations are optimized and probably leverage fast vector operations on the PowerPC and graphics cards.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  glRotate,glTranslate problems PowerMacX 4 3,720 Jan 19, 2004 12:03 AM
Last Post: kelvin
  glRotate and glTranslate are messing up my lighting?!? Jake 5 4,124 Oct 17, 2003 01:08 PM
Last Post: MacFiend