How to scale and rotate squares to fit inside each other in OpenGl

Im trying to scale and rotate 10 squares to fit inside each other recursively at a rotation angle of 45 in OpenGl. my output should look like this. enter image description here

my current code is this

void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT);

    glBindVertexArray(vao);

    

    scale = 1.0f;
    angle = 45.0f;
    for (int  i = 0; i < 10; i++)
    {
        transformObject(scale -=0.156f, Z_AXIS, angle -= 45.0f, glm::vec3(0.0f, 0.0f, 0.0f));
        glDrawArrays(GL_LINE_LOOP, 0, 4);
        
        
        
        
    }

1 answer

  • answered 2021-09-27 05:38 Rabbid76

    The size of the square gets smaller by the scale 1/sqrt(2) with each iteration of the loop. The outer rectangle is not transformed. The outer rectangle is not transformed. Change the scale and angle at the end of the loop:

    scale = 1.0f;
    angle = 0.0f;
    for (int  i = 0; i < 10; i++)
    {
        transformObject(scale, Z_AXIS, angle, glm::vec3(0.0f));
        glDrawArrays(GL_LINE_LOOP, 0, 4);
            
        scale = 1.0f/sqrt(2.0f);
        angle -= 45.0f;
    }
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum