I am simulating a falling triangle but it does not rotate

Hello. I have just downloaded, compiled and run Box2D.

I have made a change to the "Hello World" project. Specifically, I changed the shape of the falling object from:
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(1.0f, 1.0f);


to

b2PolygonShape dynamicBox;
b2Vec2 vertices[3] = {b2Vec2(-1.0f, 1.0f), b2Vec2(0.0f, 0.0f), b2Vec2(1.0f, 1.0f)};
dynamicBox.Set(vertices, 3);


I expected to see some rotation when it hits the ground, but its angle remains 0.0f. What is going on here?

Thank you.
Which way should it tip over? 😉
Although highly unlikely in the real world, in physics simulations it's possible to create perfectly symmetrical bodies, and also place them perfectly level, so theoretically they can balance on a point.
irresistible force wrote:
Which way should it tip over? 😉
Although highly unlikely in the real world, in physics simulations it's possible to create perfectly symmetrical bodies, and also place them perfectly level, so theoretically they can balance on a point.


Hello irresistible force, thank you for your answer.

I am new to physics engines, so I was expecting it tip in a random maybe(?) direction. What you said really helped me understand. I changed the points of the seconds vertex from (0.0f, 0.0f) to (0.1f, 0.0f) and it rotates 🙂

Thank you again. 😀
I've got another two questions:

1) I want to get the positions of my triangles (of my dynamic body). However, it gives me the old values. Is there a way to make those positions update?

2) I want to use Box2D with a windowed application. Specifically I am using a simple C library GP142 to draw the triangle to see what's going on. This is the structure of my main loop. Is it correct? Should I put the box2d world update loop elsewere? Maybe finish the b2world update loop and then draw?

Code:
while( !quit )
   {   
      // update the world
      for(int32 i = 0; i < 60 && !quit; ++i)
      {
         world.Step(timeStep, velocityIterations, positionIterations);
         pos = body->GetPosition();
         angle = body->GetAngle();

         event = GP142_await_event(&mouseX, &mouseY, &keyPressed); // get event

         switch(event)
         {
         case GP142_QUIT:
            quit = true;
            break;

         case GP142_PERIODIC: // drawing code here
            GP142_rectangleXY(ICE_BLUE, -300, -250, 300, 250, 0);
         
            GP142_printfXY(BLUE, -100, 100, 20, "%f, %f", pos.x, pos.y);
            
            b2Fixture *l = body->GetFixtureList();
            b2PolygonShape *s = (b2PolygonShape*)l[0].GetShape();

            for(int i = 0; i < s->GetVertexCount(); ++i)
               vertices[i] = s->GetVertex(i);
            
            GP142_lineXY(RED, vertices[0].x * 10, vertices[0].y* 10, vertices[1].x*10, vertices[1].y*10, 3);
            GP142_lineXY(RED, vertices[1].x * 10, vertices[1].y* 10, vertices[2].x*10, vertices[2].y*10, 3);
            GP142_lineXY(RED, vertices[2].x * 10, vertices[2].y* 10, vertices[0].x*10, vertices[0].y*10, 3);
         
            break;
         }
      }
   }

Original thread: https://box2d.org/forum/viewtopic.php?t=7686