0

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?

genpfault
  • 51,148
  • 11
  • 85
  • 139
DavidColson
  • 8,387
  • 9
  • 37
  • 50

2 Answers2

1

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;
Tim
  • 35,413
  • 11
  • 95
  • 121
0

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 .

Community
  • 1
  • 1
user827992
  • 1,743
  • 13
  • 25
  • Im not sure I explained myself enough. Every frame I want to get the position of each vertex and use it to make a Rect. – DavidColson Aug 19 '12 at 20:51
  • you explain yourself right, the only problem is that before OpenGL 3.0 there was this call that was supposed to simplify this kind of primitives, now it's simply not available as you can read here http://www.opengl.org/wiki/Primitives . With modern hardware and more recent versions of OpenGL you have to design and write your own shader for your operations, that's it, you don't simply call a function but you are supposed to write a function that does what you want in order to do what you want to do. – user827992 Aug 19 '12 at 20:58