Reputation: 8587
I have a rect class with various information stored in it. I use it to do collision detection in 2D.
If I am rendering with openGL 3 and up how can I make the Rect follow the quad. At first I thought I could grab the position of each vertex and feed them into the Rect's four positions (for each corner). But after applying the model matrix how can I get the positions of the vertices?
Is there another way to get the information to create a Rect from a quad?
Upvotes: 0
Views: 314
Reputation: 35923
But after applying the model matrix how can I get the positions of the vertices?
If your Rect has four vertices (v1, v2, v3, and v4) in model space, and you have a model matrix M, then if you want to follow your Rect to follow the quad, you just multiply your vertices by the model matrix (do the same thing that OpenGL does).
You just apply the model matrix to your rect's coordinates like so, to get the four transformed rect coordinates (vt1, vt2, vt3, vt4):
vt1 = M * v1;
vt2 = M * v2;
vt3 = M * v3;
vt4 = M * v4;
Upvotes: 1
Reputation: 1753
With OpenGL 3 you have to program this by hand, because of the programmable pipeling, there was a call for GL_QUADS
with the old fixed pipeline but it's deprecated in 3.0 and removed in 3.1 and newer.
Since you have to do this by yourself, there are several solutions for your problems, one is discussed here on SO .
Upvotes: 0