TEST(Physics, collideEntityWithEntity) { PhysicsEngine phyEg; Vector2 initialPos(3.0f, 3.0f); Vector2 newPos(3.0f, 5.0f); Rectangle2 box(0.5f, 0.5f); auto ent = std::unique_ptr < TestEntity > (new TestEntity(initialPos, box)); ent->setCollisionGroup(2); // collide with the floor and other from our collision group ent->setCollisionMask(CollisionGroups::Ground | 2); ent->setCollisionType(CollisionType::CircleDynamic); phyEg.registerEntity(ent.get()); ent->setMoveIntent(newPos); // circle in between Rectangle2 circleCollide(1.0f, 1.0f); Vector2 wallPos(3.0f, 4.0f); auto entWall = std::unique_ptr < TestEntity > (new TestEntity(wallPos, circleCollide)); entWall->setCollisionGroup(2); // collide with the floor and other from our collision group entWall->setCollisionMask(CollisionGroups::Ground | 2); entWall->setCollisionType(CollisionType::CircleDynamic); phyEg.registerEntity(entWall.get()); //entWall->setMoveIntent(newPos); // run for one second // dont make this time to big, as bullet can only subdivide in a certain part of substeps phyEg.step(0.1f); std::cout << "is at " << ent->getMoveIntent() << std::endl; ASSERT_TRUE(ent->getMoveIntent().y() < newPos.y()); }
TEST(Physics, moveEntity) { PhysicsEngine phyEg; Vector2 initialPos(3.0f, 3.0f); Vector2 newPos(5.0f, 3.0f); Rectangle2 box(0.5f, 0.5f); auto ent = std::unique_ptr < TestEntity > (new TestEntity(initialPos, box)); ent->setCollisionGroup(2); // collide with the floor and other from our collision group ent->setCollisionMask(CollisionGroups::Ground | 2); ent->setCollisionType(CollisionType::CircleDynamic); phyEg.registerEntity(ent.get()); ent->setMoveIntent(newPos); // run for one second // dont make this time to big, as bullet can only subdivide in a certain part of substeps phyEg.step(0.1f); ASSERT_FLOAT_EQ(ent->getMoveIntent().x(), newPos.x()); ASSERT_FLOAT_EQ(ent->getMoveIntent().y(), newPos.y()); ASSERT_EQ(phyEg.getRegisteredEntitiesCount(), size_t(1)); }
//////////////////////////////////////////////////////// // Unit //////////////////////////////////////////////////////// Unit::Unit(UnitDef *def) :definition(def) ,useAI(true) ,GameObject(def->manager,def) ,controller(new Controller(this)) { // LogFunction(*g_logger); health=definition->health; setCollisionGroup(cgUnit); if(def->fxIdle) { effects->attach(def->fxIdle->clone()); effects->start(); } // install all the devices from the definition for_each(definition->mounts.begin(),definition->mounts.end(),[this](MountDef & mount) { Device * device = mount.device->create(); if(device) { devices.push_back(device); device->onInstall(this, devices.size()-1, mount.pose); } }); controller->initDevices(); }
TEST(Physics, changeCollisionGroup) { PhysicsEngine phyEg; const Vector2 initialPos(3.0f, 3.0f); const Vector2 newPos(3.0f, 5.0f); Rectangle2 box(0.5f, 0.5f); auto ent = std::unique_ptr < TestEntity > (new TestEntity(initialPos, box)); ent->setCollisionGroup(2); // collide with the floor and other from our collision group ent->setCollisionMask(CollisionGroups::Ground | 2); ent->setCollisionType(CollisionType::CircleDynamic); phyEg.registerEntity(ent.get()); ent->setMoveIntent(newPos); // change collision settings after registering ent->setCollisionMask(0); // box in between Rectangle2 boxCollide(5.0f, 0.5f); Vector2 wallPos(3.0f, 4.0f); auto entWall = std::unique_ptr < TestEntity > (new TestEntity(wallPos, boxCollide)); entWall->setCollisionGroup(2); // collide with the floor and other from our collision group entWall->setCollisionMask(CollisionGroups::Ground | 2); entWall->setCollisionType(CollisionType::BoxStatic); phyEg.registerEntity(entWall.get()); phyEg.step(0.1f); std::cout << "is at " << ent->getMoveIntent() << std::endl; EXPECT_NEAR(ent->getMoveIntent().x(), newPos.x(), 0.001); EXPECT_NEAR(ent->getMoveIntent().y(), newPos.y(), 0.001); }