I’ve repurposed a bunch of sample code for a simple 2D game project. I need to be able to see the physics collision box of my objects for debugging purposes. However, I’ve copied all of the debug drawing code as best I can find from the samples into my own project and it doesn’t work. The sprite is drawn, as expected, but nothing else.
In CreateScene() I do the following:
// Create 2D physics world component and debug renderer
PhysicsWorld2D* physicsWorld = scene_->CreateComponent<PhysicsWorld2D>();
debug = scene_->CreateComponent<DebugRenderer>();
physicsWorld->SetDrawAabb(true);
physicsWorld->SetDrawCenterOfMass(true);
physicsWorld->SetDrawJoint(true);
physicsWorld->SetDrawPair(true);
physicsWorld->SetDrawShape(true);
And then I have an event handler for E_POSTRENDERUPDATE that calls a draw debug function:
// Draw 2D physics debug geometry
PhysicsWorld2D* physicsWorld = scene_->CreateComponent<PhysicsWorld2D>();
physicsWorld->DrawDebugGeometry(debug, true);
Now if I understand correctly, it should draw any CollisionEdge2D, CollisionCircle2D, CollisionBox2D, etc. according to this document.
I have only one physics object, and it looks like this:
// create sun
Node* sun_node = scene_->CreateChild("sun");
sun_node->SetPosition(Vector3(0.0f, 0.0f, 0.0f));
sun_node->SetScale(Vector3(1.0f, 1.0f, 0.0f));
CollisionCircle2D* sun_collider = sun_node->CreateComponent<CollisionCircle2D>();
StaticSprite2D* sun_sprite_ptr = sun_node->CreateComponent<StaticSprite2D>();
RigidBody2D* sun_body = sun_node->CreateComponent<RigidBody2D>();
sun_sprite_ptr->SetSprite(sun_sprite);
sun_collider->SetRadius(0.32f);
sun_collider->SetDensity(1.0f);
sun_collider->SetFriction(0.5f);
sun_collider->SetRestitution(0.1f);
sun_body->SetGravityScale(0.0);
sun_body->SetBodyType(BT_DYNAMIC);
Have I setup my debug rendering wrong? Or has the collision box been made incorrectly? I did try making some other shapes, but I can’t see them either. For the record, the sample I took this from - 32_Urho2DConstraints - compiles, runs, and debugs just fine.
Can anyone help?