title: c++ opengl converting model coordinates to world coordinates for collision detection
body: <p>(This is all in ortho mode, origin is in the top left corner, x is positive to the right, y is positive down the y axis)</p>
  
  <p>I have a rectangle in world space, which can have a rotation m_rotation (in degrees).</p>
  
  <p>I can work with the rectangle fine, it rotates, scales, everything you could want it to do.</p>
  
  <p>The part that I am getting really confused on is calculating the rectangles world coordinates from its local coordinates.</p>
  
  <p>I've been trying to use the formula: </p>
  
  <pre><code>x' = x*cos(t) - y*sin(t) 
  y' = x*sin(t) + y*cos(t)
  
  where (x, y) are the original points,
  (x', y') are the rotated coordinates,
  and t is the angle measured in radians
  
  from the x-axis. The rotation is
  counter-clockwise as written. 
  -credits duffymo
  </code></pre>
  
  <p>I tried implementing the formula like this:</p>
  
  <pre><code>//GLfloat Ax = getLocalVertices()[BOTTOM_LEFT].x * cosf(DEG_TO_RAD( m_orientation )) - getLocalVertices()[BOTTOM_LEFT].y * sinf(DEG_TO_RAD( m_orientation ));
  //GLfloat Ay = getLocalVertices()[BOTTOM_LEFT].x * sinf(DEG_TO_RAD( m_orientation )) + getLocalVertices()[BOTTOM_LEFT].y * cosf(DEG_TO_RAD( m_orientation ));
  
  //Vector3D BL = Vector3D(Ax,Ay,0);
  </code></pre>
  
  <p>I create a vector to the translated point, store it in the rectangles world_vertice member variable. That's fine. However, in my main draw loop, I draw a line from (0,0,0) to the vector BL, and it seems as if the line is going in a circle from the point on the rectangle (the rectangles bottom left corner) around the origin of the world coordinates.</p>
  
  <p>Basically, as m_orientation gets bigger it draws a huge circle around the (0,0,0) world coordinate system origin. edit: when m_orientation = 360, it gets set back to 0.</p>
  
  <p>I feel like I am doing this part wrong:</p>
  
  <blockquote>
    <p>and t is the angle measured in radians
    from the x-axis.</p>
  </blockquote>
  
  <p>Possibly I am not supposed to use m_orientation (the rectangles rotation angle) in this formula?</p>
  
  <p>Thanks!</p>
  
  <p>edit: the reason I am doing this is for collision detection. I need to know where the coordinates of the rectangles (soon to be rigid bodies) lie in the world coordinate place for collision detection.</p>