Example #1
0
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;
}
Example #2
0
std::shared_ptr<Joint> Joints::create_joint(PhysicsWorld &phys_world, Body &bodyA, Body &bodyB, int type)
{
	//Get the Physics Context
	PhysicsContext pc = phys_world.get_pc();

	switch(type)
	{
	default:
	case 0: // Distance joint
		{
			DistanceJointDescription joint_desc(phys_world);

			joint_desc.set_bodies(bodyA, bodyB, bodyA.get_position(), bodyB.get_position());
			joint_desc.set_damping_ratio(1.0f);
			joint_desc.set_length(100.0f);

			std::shared_ptr<Joint> joint( static_cast<Joint *> (new DistanceJoint(pc, joint_desc)));
			return joint;
		}
	case 1: // Revolute joint
		{
			RevoluteJointDescription joint_desc(phys_world);
			joint_desc.set_bodies(bodyA, bodyB, bodyA.get_position());
			joint_desc.set_as_motor();
			joint_desc.set_motor_speed(Angle(60,angle_degrees));
			joint_desc.set_max_motor_torque(1000);
		
			std::shared_ptr<Joint> joint( static_cast<Joint *> (new RevoluteJoint(pc, joint_desc)));
			return joint;
		}
	case 2: // Prismatic joint
		{
			PrismaticJointDescription joint_desc(phys_world);
			joint_desc.set_bodies(bodyA, bodyB, bodyA.get_position(), bodyB.get_position());
			joint_desc.set_as_motor();
			joint_desc.enable_limit();
			joint_desc.set_axis_a(Vec2f(0.0f,1.0f));
			joint_desc.set_motor_speed(Angle(20,angle_degrees));
			joint_desc.set_translation_limits(10.0f,100.0f);
			joint_desc.set_max_motor_force(1000);
		
			std::shared_ptr<Joint> joint( static_cast<Joint *> (new PrismaticJoint(pc, joint_desc)));
			return joint;
		}
	}
}
Example #3
0
Body Collision::create_ground_body(PhysicsWorld &phys_world)
{
	PhysicsContext pc = phys_world.get_pc();
	BodyDescription ground_desc(phys_world);
	ground_desc.set_position(Vec2f((float)window_x_size/2.0f,(float)window_y_size));
	ground_desc.set_type(body_static);

	Body ground(pc, ground_desc);

	//Setup ground fixture
	PolygonShape ground_shape(phys_world);
	ground_shape.set_as_box((float)window_x_size/2,20.0f);

	FixtureDescription fixture_desc(phys_world);
	fixture_desc.set_shape(ground_shape);
	fixture_desc.set_friction(1.0f);
	fixture_desc.set_density(1000.0f);

	Fixture ground_fixture(pc, ground, fixture_desc);
	return ground;
}
Example #4
0
Body Joints::create_box_body(PhysicsWorld &phys_world)
{
	//Get the Physics Context
	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
	PolygonShape box_shape(phys_world);
	box_shape.set_as_box(20.0f,20.0f);

	FixtureDescription fixture_desc2(phys_world);
	fixture_desc2.set_shape(box_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;
}