title: Points rotate oddly, what's wrong with my calculations?
body: <p>This is what I want to get:
  <a href="https://i.stack.imgur.com/wochI.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wochI.gif" alt="rotating square"></a></p>
  
  <p>And this is what I get:</p>
  
  <p><a href="https://i.stack.imgur.com/zrySV.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zrySV.gif" alt="Wrongly rotating triangle"></a></p>
  
  <p>When I'm using this formulae:</p>
  
  <p><a href="https://i.stack.imgur.com/Wc711.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Wc711.png" alt="formualae"></a></p>
  
  <p>Or, more precisely, this GLSL vertex shader code:</p>
  
  <pre><code>#version 330
  layout (location = 0) in vec2 pos;
  layout (location = 1) in vec3 clr;
  uniform float sinr, cosr;
  float x, y;
  out vec3 color;
  void main() {
      color = clr;
      x = pos.x * cosr - pos.y * sinr;
      y = pos.x * sinr + pos.y * cosr;
      gl_Position = vec4(x, y, 0.0, 1.0); }
  </code></pre>
  
  <p>I'm out of ideas. I did my math and my code should rotate correctly but obviously it doesn't. Could anyone tell me why and how to fix it?</p>
  
  <p>Edit: set/update routines:</p>
  
  <pre><code>void tgle_rot(int i, float rad) {
      float *sin = &amp;global.objs[i].sinr, *cos = &amp;global.objs[i].cosr;
      *sin = *sin * cosf(rad) + *cos * sinf(rad);
      *cos = *cos * cosf(rad) - *sin * sinf(rad); }
  
  void callback(void) {
      tgle_rot(0, 0.01); }
  
  static void run_draw(void) {
      /* ... */
      for(int i = 0; i &lt; global.num_objs; ++i) {
          /* ... */
          glUniform1f(global.shader.sinr, global.objs[i].sinr);
          glUniform1f(global.shader.cosr, global.objs[i].cosr);
          /* ... */ }
      /* ... */
      glfwSwapBuffers(global.window); }
  </code></pre>
  
  <p>Edit 2: the problem doesn't lie within <code>tgle_rot</code>! I've changed it to</p>
  
  <pre><code>void tgle_rot(int i, float rad) {
      float *sin = &amp;global.objs[i].sinr, *cos = &amp;global.objs[i].cosr;
      static float rotation = 0;
      rotation += 0.01;
      *sin = sinf(rotation);
      *cos = cosf(rotation); }
  </code></pre>
  
  <p>and the program behavior didn't change!</p>
  
  <p>Edit 3: here's the rotation with single line:</p>
  
  <p><a href="https://i.stack.imgur.com/JUnp0.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JUnp0.gif" alt="line rot"></a></p>
  
  <p>Solution: it turns out the problem was the order of transformations. I was scaling first and THEN rotating. Swapping scaling and rotation fixed the problem. I didn't add the scaling part because I thought it wasn't important to the question. It turns out I was mistaken. Now I'm figuring out why. Thank you for your time, I will change my <code>tgle_rot</code> function according to your suggestions.</p>
  
  <p>ACTUALLY, NO. THE PROBLEM WAS IT THE <strong>SHADER</strong>.</p>
  
  <pre><code>void main() {
          color = clr;
          x = x * cosr - y * sinr;
          y = x * sinr + y * cosr; // using modified x!!!
          gl_Position = vec4(x, y, 0.0, 1.0);
  </code></pre>