Using the global vertex cache and still use glRotate?

I have a simple Android OpenGL-ES application, and since all the models are very simple (<10 vertices!), I implemented a global “world” class that tracks all vertices and executes one pair of GL frames rendering commands.

Each model object adds vertices to the global buffers, and they are sent to GL in one operation:

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

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

My base objects just define a bunch of vertices that are added to the cache, such as a triangle, square, pentagram, etc. The My World object then takes a large array of vertices and uploads them to GL. If I want to rotate all this, do I think that I need to execute my own vertex coordinates (trigonometry!)?

I think it’s not the end of the world to create some utility functions to rotate all the vertices in my models, but I would prefer it not to be necessary.

+3
source share
2 answers

Yes, unfortunately, this is the price for making a single call for several models. The calculations are really very simple if you use the standard scale-rotate-translation order. For each vertex:

  • : Xrel = X-Xcenter Yrel = Y-Ycenter
  • x y. Xscaled = scalex*Xrel Yscaled = scalex*Yrel.
  • : Xrot = Xscaled*cos(d)-Yscaled*sin(d) Ynew = Xscaled*sin(d)+Yscaled*cos(d).
  • : Xnew = Xrot + translatex Ynew = Yrot+translatey.

! Cheers, Aert.

0

, glRotate .

0

Source: https://habr.com/ru/post/1764934/


All Articles