Body Collision::create_outline_body(PhysicsWorld &phys_world) { PhysicsContext pc = phys_world.get_pc(); BodyDescription box_desc(phys_world); box_desc.set_type(body_dynamic); Body box(pc, box_desc); //Setup box fixture description. // //Outlines shouldn't be too complex. Keep it Under 100 points. //If it has more, think about splitting it into couple smaller groups. //Then create separate fixtures for the same body. CollisionOutline outline("test_outline.out"); ChainShape outline_shape(phys_world); outline_shape.create_loop(outline); FixtureDescription fixture_desc2(phys_world); fixture_desc2.set_shape(outline_shape); fixture_desc2.set_restitution(0.6f); fixture_desc2.set_friction(0.001f); fixture_desc2.set_density(50.0f); Fixture box_fixture(pc, box,fixture_desc2); return box; }
void Player::setup_physics() { clan::PhysicsContext pc = m_physicsWorld.get_pc(); clan::BodyDescription body_desc(m_physicsWorld); body_desc.set_type(clan::BodyType::body_dynamic); body_desc.set_angular_damping(5.0f); m_physicsBody = clan::Body(pc, body_desc); //clan::ChainShape outline_shape(m_physicsWorld); //outline_shape.create_loop(m_collisionOutline); /* clan::Vec2f vertices[] = { clan::Vec2f(m_sprite.get_width()/4.0f, 0), clan::Vec2f(m_sprite.get_width()/2.0f, m_sprite.get_height()/2.0f), clan::Vec2f(0, m_sprite.get_height()/2.0f) }; clan::Vec2f vertices[] = { clan::Vec2f(-0.001f, 0), clan::Vec2f(0.001f, 0.002f), clan::Vec2f(0.001f, 0), clan::Vec2f(0, 0) }; outline_shape.create_loop(vertices, 4); */ clan::PolygonShape outline_shape(m_physicsWorld); outline_shape.set_as_box(m_sprite.get_width()/2.0f, m_sprite.get_height()/2.0f); clan::FixtureDescription fix_desc(m_physicsWorld); fix_desc.set_shape(outline_shape); fix_desc.set_restitution(0.0f); fix_desc.set_friction(1.0f); fix_desc.set_density(m_mass); m_physicsBodyFixture = clan::Fixture(pc, m_physicsBody, fix_desc); }