Exemplo n.º 1
0
Action::ResultE PhysicsAttachmentsFinder::check(Node*& node)
{
    AttachmentUnrecPtr Att;
    //Loop through all of the attachments on this node
    for(AttachmentMap::const_iterator MapItor(node->getSFAttachments()->getValue().begin())
            ; MapItor != node->getSFAttachments()->getValue().end()
            ; ++MapItor)
    {
        //Check for Physics Handlers
        if(MapItor->second->getType().isDerivedFrom(PhysicsHandler::getClassType()))
        {
            _FoundHandlers.push_back(dynamic_cast<const PhysicsHandler*>(MapItor->second));
        }

        //Check for Physics Worlds
        if(MapItor->second->getType().isDerivedFrom(PhysicsWorld::getClassType()))
        {
            _FoundWorlds.push_back(dynamic_cast<const PhysicsWorld*>(MapItor->second));
        }

        //Check for Physics Geoms
        if(MapItor->second->getType().isDerivedFrom(PhysicsGeom::getClassType()))
        {
            _FoundGeoms.push_back(dynamic_cast<const PhysicsGeom*>(MapItor->second));
        }

        //Check for Physics Spaces
        if(MapItor->second->getType().isDerivedFrom(PhysicsSpace::getClassType()))
        {
            _FoundSpaces.push_back(dynamic_cast<const PhysicsSpace*>(MapItor->second));
        }

        //Check for Physics Bodies
        if(MapItor->second->getType().isDerivedFrom(PhysicsBody::getClassType()))
        {
            _FoundBodies.push_back(dynamic_cast<const PhysicsBody*>(MapItor->second));

            //Get the Physics Joints
            std::vector<PhysicsJointUnrecPtr> Joints(dynamic_cast<PhysicsBody*>(MapItor->second)->getJoints());
            for(UInt32 i(0) ; i<Joints.size() ; ++i)
            {
                _FoundJoints.push_back(Joints[i].get());
            }
        }
    }

    return Action::Continue;        
}
Exemplo n.º 2
0
// The start of the Application
int Joints::start(const std::vector<std::string> &args)
{
	//Remove the need to send physic world to every object. Instead send just the description.

	//Fix having two fixtures working weirdly.
	quit = false;

	// Set the window
	DisplayWindowDescription desc;
	desc.set_title("ClanLib Joints Example");
	desc.set_size(Size(window_x_size, window_y_size), true);
	desc.set_allow_resize(false);

	DisplayWindow window(desc);
	
	// Connect the Window close event
	Slot slot_quit = window.sig_window_close().connect(this, &Joints::on_window_close);

	// Connect a keyboard handler to on_key_up()
	Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &Joints::on_input_up);

	// Create the canvas
	Canvas canvas(window);

	//Setup physic world
	PhysicsWorldDescription phys_desc;
	phys_desc.set_gravity(0.0f,10.0f);
	phys_desc.set_sleep(true);
	phys_desc.set_physic_scale(100);

	PhysicsWorld phys_world(phys_desc);

	//Setup ground body
	Body ground = create_ground_body(phys_world);

	unsigned int last_time = System::get_time();

	//Setup debug draw.
	PhysicsDebugDraw debug_draw(phys_world);
	debug_draw.set_flags(f_shape|f_aabb|f_joint);

	GraphicContext gc = canvas.get_gc();
	//Setup joints

	const int number_of_joints = 3;
	std::vector<Body> bodies_A(number_of_joints);
	std::vector<Body> bodies_B(number_of_joints);
	std::vector<std::shared_ptr<Joint>> Joints(number_of_joints);
	

	for(int i=0; i<number_of_joints; i++)
	{
		bodies_A[i] = create_box_body(phys_world);
		bodies_A[i].set_position(Vec2f(80.0f+80.0f*i,280.0f));

		bodies_B[i] = create_box_body(phys_world);
		bodies_B[i].set_position(Vec2f(80.0f+80.0f*i,440.0f));

		Joints[i] = create_joint(phys_world, bodies_A[i], bodies_B[i], i);
	}

	// Run until someone presses escape
	while (!quit)
	{
		unsigned int current_time = System::get_time();
		float time_delta_ms = static_cast<float> (current_time - last_time);
		last_time = current_time;

		canvas.clear();
		
		phys_world.step();
		debug_draw.draw(canvas);

		canvas.flush();
		window.flip(1);

		// This call processes user input and other events
		KeepAlive::process(0);

		System::sleep(10);
	}

	return 0;
}