TEST(TransferParticlesToPointCloudBehaviorTests, UpdateTest)
{
	auto runtime = std::make_shared<Framework::Runtime>();
	runtime->addManager(std::make_shared<Framework::BehaviorManager>());
	runtime->addManager(std::make_shared<Physics::PhysicsManager>());

	auto sceneElement = std::make_shared<Framework::BasicSceneElement>("Element");

	auto particles = std::make_shared<Particles::SphRepresentation>("Particles");
	particles->setMaxParticles(10);
	particles->setMassPerParticle(1.0);
	particles->setDensity(1.0);
	particles->setGasStiffness(1.0);
	particles->setKernelSupport(1.0);
	for (size_t particleId = 0; particleId < 10; particleId++)
	{
		particles->addParticle(Vector3d(static_cast<double>(particleId), 0.0, 0.0), Vector3d::Zero(), 100000);
	}
	sceneElement->addComponent(particles);

	auto pointCloud = std::make_shared<Graphics::OsgPointCloudRepresentation>("Graphics");
	sceneElement->addComponent(pointCloud);

	auto behavior = std::make_shared<TransferParticlesToPointCloudBehavior>("Behavior");
	behavior->setSource(particles);
	behavior->setTarget(pointCloud);
	sceneElement->addComponent(behavior);

	auto scene = runtime->getScene();
	scene->addSceneElement(sceneElement);

	particles->update(0.1);
	behavior->update(0.1);
	auto sourceVertices = particles->getParticles().safeGet()->getVertices();
	auto targetVertices = pointCloud->getVertices()->getVertices();
	ASSERT_EQ(sourceVertices.size(), targetVertices.size());

	auto sourceVertex = sourceVertices.begin();
	auto targetVertex = targetVertices.begin();
	for (; sourceVertex != sourceVertices.end(); ++sourceVertex, ++targetVertex)
	{
		EXPECT_TRUE(sourceVertex->position.isApprox(targetVertex->position));
	}

	particles->removeParticle(0);
	particles->removeParticle(1);
	particles->update(0.1);
	behavior->update(0.1);

	sourceVertices = particles->getParticles().safeGet()->getVertices();
	targetVertices = pointCloud->getVertices()->getVertices();
	ASSERT_EQ(sourceVertices.size(), targetVertices.size());

	sourceVertex = sourceVertices.begin();
	targetVertex = targetVertices.begin();
	for (; sourceVertex != sourceVertices.end(); ++sourceVertex, ++targetVertex)
	{
		EXPECT_TRUE(sourceVertex->position.isApprox(targetVertex->position));
	}
}
void BaseGameFeatureUnit::SetupManangers()
{
	FeatureUnit::SetupManangers();
	addManager(FactoryManager::create());
	addManager(GameStateManager::create());
	addManager(DataTableManager::create());
}
TEST(DcdCollisionTest, Deactivate)
{
	auto runtime = std::make_shared<Framework::Runtime>();
	auto physicsManager = std::make_shared<PhysicsManager>();
	runtime->addManager(physicsManager);

	auto sphere1 = std::make_shared<Collision::ShapeCollisionRepresentation>("Sphere1");
	sphere1->setShape(std::make_shared<Math::SphereShape>(1.0));

	auto sphere2 = std::make_shared<Collision::ShapeCollisionRepresentation>("Sphere2");
	sphere2->setShape(std::make_shared<Math::SphereShape>(1.0));
	sphere2->setLocalPose(Math::makeRigidTransform(Math::Quaterniond::Identity(), Vector3d(0.0, 0.0, 0.5)));

	auto scene = runtime->getScene();
	auto element = std::make_shared<Framework::BasicSceneElement>("Element");
	element->addComponent(sphere2);
	element->addComponent(sphere1);
	scene->addSceneElement(element);

	runtime->start(true);
	runtime->step();
	runtime->step();
	EXPECT_TRUE(sphere1->collidedWith(sphere2));
	EXPECT_TRUE(sphere2->collidedWith(sphere1));

	sphere1->setLocalActive(false);
	runtime->step();
	runtime->step();
	EXPECT_FALSE(sphere1->collidedWith(sphere2));
	EXPECT_FALSE(sphere2->collidedWith(sphere1));

	boost::this_thread::sleep(boost::posix_time::milliseconds(100));
	runtime->stop();
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    qApp->setOrganizationName("Hallo");
    qApp->setApplicationName("Welt");



    QSettings s;
    s.beginGroup("UI");
    restoreGeometry(s.value("geo").toByteArray());
    restoreState(s.value("status").toByteArray());
    s.endGroup();

    installEventFilter(this);
    _pc = 0;
    load(true);

    ObjectManager* t = new ObjectManager(this);
    addManager(t);
    ViewportManager* v = new ViewportManager(this);
    addManager(v);
    PropertyManager* propManager = new PropertyManager(this);
    addManager(propManager);


    ui->objectTreeWidget->setWidget(t);
    ui->attributeWidget->setWidget(propManager);
    setCentralWidget(v);

    connect(ui->actionLoad, SIGNAL(triggered()), this, SLOT(load()));
    connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(save()));
    connect(ui->actionNew, &QAction::triggered, [this]() { load(true); });
    setUpObjectsMenu();
    _renderManager = new RenderManager(this);
    connect(ui->actionRender, SIGNAL(triggered()), this, SLOT(render()));


}