I'm really new to using Box2D. I've setup a small thing with a Dynamic body that falls onto a static one. When the box hits the body, it begins "vibrating" for a bit and shaking, then suddenly stops. If anyone has used it or might know what is happening I'd appreciate it,
That's the setup of the boxes.
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(100.0f, 400.0f);
b2Body* groundBody = world.CreateBody(&groundBodyDef);
b2PolygonShape groundBox;
groundBox.SetAsBox(240, 20);
groundBody->CreateFixture(&groundBox, 0.0f);
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(100.0f, 0.0f);
b2Body* body = world.CreateBody(&bodyDef);
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(32.0f, 32.0f);
b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.3f;
body->CreateFixture(&fixtureDef);
body->SetAngularVelocity(20);
int32 velocityIterations = 8;
int32 positionIterations = 4;
world.Step(ticks_per_frame, velocityIterations, positionIterations);
b2Vec2 position = body->GetPosition();
float32 angle = body->GetAngle();
std::cout << angle<< "\n";
SDL_Rect rect = {position.x, position.y, 32, 32};
//SDL_Point point = {32, 0};
SDL_RenderCopyEx(mainren, textures[0], NULL, &rect, angle, NULL, SDL_FLIP_NONE);
↧