From 7efbd44a641b32285499b07dc4f5461fec8dc8d5 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Mon, 7 Dec 2020 21:20:39 -0500 Subject: rotating platforms --- sim.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sim.cpp b/sim.cpp index a1b3f49..a2bdaf1 100644 --- a/sim.cpp +++ b/sim.cpp @@ -247,12 +247,14 @@ static b2Body *platform_to_body(State *state, Platform *platform) { b2BodyDef body_def; body_def.type = b2_kinematicBody; body_def.position.Set(center.x, center.y); + body_def.angle = platform->angle; b2Body *body = world->CreateBody(&body_def); b2PolygonShape shape; - shape.SetAsBox(half_size, state->platform_thickness, b2Vec2(0, 0), platform->angle); + shape.SetAsBox(half_size, state->platform_thickness); body->CreateFixture(&shape, 0.0f); - body->SetLinearVelocity(b2Vec2(0, 10.0f)); + body->SetLinearVelocity(b2Vec2(0, 3.0f)); + body->SetAngularVelocity(2.0f); return body; } @@ -420,6 +422,7 @@ void sim_frame(Frame *frame) { b2Vec2 platform_pos = platform->body->GetPosition(); platform->center.x = platform_pos.x * B2_INV_SCALE; platform->center.y = platform_pos.y * B2_INV_SCALE; + platform->angle = platform->body->GetAngle(); } } -- cgit v1.2.3