views:

30

answers:

2

I have a simple Android OpenGL-ES app, and as all the models are very simple (<10 vertices!) I have implemented a global "world" class that tracks all the vertices, and performs a single pair of GL commands on the frame rendering.

Each model object adds it's vertices to the global buffers, and these these are 'sent' to GL in one operation:

gl.glVertexBuffer(...);
gl.glDrawElements(...);

My question (perhaps an obvious answer, but I want to be sure) is, does this mean I have to do all my own rotations manually?

My base objects just define a bunch of vertices that get added to the cache, for example a triangle, a square, a pentagram, etc. My World object then takes the big array of vertices, and dumps them out to GL. If I want to rotate all those, am I correct in thinking I have to perform my own vertex coordinate manipulations (trigonometry!)?

I guess it's not the end of the world to have to create some utility functions to rotate all the vertices in my models, but I'd rather not if it's not necessary.

A: 

No, using glRotate will work fine with vertex arrays.

Matias Valdenegro
I think he wants to know whether he can control the rotation of _parts_ of that array (the individual models) with glrotatef.
Aert
A: 

Hi,

Yes, unfortunately that is the price to pay for performing a single draw callfor multiple models. The calculations are really quite simple, if you use the standard Scale-Rotate-Translate order. For every vertex:

  • Determine the distance to the center: Xrel = X-Xcenter and Yrel = Y-Ycenter
  • Multiply that by the scale for x and y. Xscaled = scalex*Xrel and Yscaled = scalex*Yrel.
  • Determine the new positions relative to the center after rotation: Xrot = Xscaled*cos(d)-Yscaled*sin(d) and Ynew = Xscaled*sin(d)+Yscaled*cos(d).
  • Move the vertices with the translation: Xnew = Xrot + translatex and Ynew = Yrot+translatey.

Easy! Cheers, Aert.

Aert
Thanks, it shouldn't be too difficult - it's fairly simple geometry. :)
Cylindric