So I have a simple OpenGL program up and running that draws a square using the programmable pipeline. How do I actually tell the vertices to change their location? Do I edit the vertices in the VBO? If so, how exactly would I do this?
It would help to know what the cause of the location change was to advise you best.
Some of your choices include: modify the input OBJECT-SPACE vertex position attributes in the VBO, or analytically modify the vertex positions in a shader. The latter might be accomplished by changing your MODELVIEW transform (MODELING and/or VIEWING transform) and/or your PROJECTION transform, or performing some kind of analytical OBJECT-SPACE movement, animation, or instancing on your object vertices in the shaders such as particle system behavior, geometry instancing, extrusion, decaling, morphing, skinning, etc.
So, I did a little research, and I guess I should be using a translation Matrix. The issue I have is that I don’t want to move a set amount, I want to be able to hand OpenGL it’s new coordinates. So instead of telling it to move 10 units on the X axis, I want to tell it to move a specific point. Essentially, I am getting the final location from my physics engine. I suppose I could compute the necessary units to move by doing something like (finalPosition = oldPosition - newPosition), but it seems like there would be a simpler way than to do that.
If all the vertices are to be translated by a fixed amount a translation matrix is a good option. If each vertex is to change a different amount, modifying or re-creating the VBO will be better. If the vertex has a lot of other information you can save bus time by having a separate buffer that has the offsets.
Basically, I have a aphysics engine (Box2D) that does my physics calculations. Any time an object moves in Box2D, I want to translate the corresponding square in OpenGL. I realize that a translation is the way to go, but for a translation you essentially move an object a certain distance in a certain direction IE using a vector. Is there an efficient way to force a new location?
Doesn’t your physics engine give you a matrix so that you can pass it along to GL? That’s what other physics engines do such as Newton Dynamics and ODE. I though it was a pretty common thing for all physics engines.
Anyway, if you want to update vertices in your VBO, here are some tips