#include #include #include #include #include #include #include void CompareAABB(const Nz::Rectf& aabb, const Nz::Boxf& box); SCENARIO("RenderSystem", "[NDK][RenderSystem]") { GIVEN("A world with a camera, a drawable, a light and some particles") { Ndk::World world; const Ndk::EntityHandle& cameraEntity = world.CreateEntity(); Ndk::CameraComponent& cameraComponentCamera = cameraEntity->AddComponent(); Ndk::NodeComponent& nodeComponentCamera = cameraEntity->AddComponent(); const Ndk::EntityHandle& drawableEntity = world.CreateEntity(); Ndk::GraphicsComponent& graphicsComponentDrawable = drawableEntity->AddComponent(); Nz::SpriteRef sprite = Nz::Sprite::New(); graphicsComponentDrawable.Attach(sprite); Ndk::NodeComponent& nodeComponentDrawable = drawableEntity->AddComponent(); const Ndk::EntityHandle& lightEntity = world.CreateEntity(); Ndk::LightComponent& lightComponentLight = lightEntity->AddComponent(); Ndk::NodeComponent& nodeComponentLight = lightEntity->AddComponent(); const Ndk::EntityHandle& particlesEntity = world.CreateEntity(); Ndk::ParticleGroupComponent& particleGroupComponentParticles = particlesEntity->AddComponent(1, Nz::ParticleLayout_Sprite); WHEN("We change the render technique to ForwardRenderTechnique") { Ndk::RenderSystem& renderSystem = world.GetSystem(); renderSystem.ChangeRenderTechnique(); THEN("The render system should be ForwardRenderTechnique") { REQUIRE(renderSystem.GetRenderTechnique().GetType() == Nz::RenderTechniqueType_BasicForward); } } } GIVEN("A world with 2D coordinates (upper-left) and an entity with graphics and physics") { Ndk::World world; world.GetSystem().SetGlobalUp(Nz::Vector3f::Down()); const Ndk::EntityHandle& entity = world.CreateEntity(); Nz::Vector2f position(3.f, 4.f); Ndk::NodeComponent& nodeComponent = entity->AddComponent(); nodeComponent.SetPosition(position); Nz::Vector2f dimensions(1.f, 2.f); Ndk::GraphicsComponent& graphicsComponent = entity->AddComponent(); Nz::SpriteRef sprite = Nz::Sprite::New(); sprite->SetSize(dimensions); graphicsComponent.Attach(sprite); Nz::Rectf aabb(Nz::Vector2f::Zero(), dimensions); Nz::BoxCollider2DRef boxCollider2D = Nz::BoxCollider2D::New(aabb); entity->AddComponent(boxCollider2D); Ndk::PhysicsComponent2D& physicsComponent2D = entity->AddComponent(); world.GetSystem().SetFixedUpdateRate(30.f); world.Update(1.f); WHEN("We move it") { Nz::Vector2f velocity = Nz::Vector2f::UnitY(); physicsComponent2D.SetVelocity(velocity); world.Update(1.f); THEN("Graphics and physics should be synchronised") { CHECK(nodeComponent.GetPosition() == position + velocity); CHECK(physicsComponent2D.GetAABB() == aabb.Translate(position + velocity)); CompareAABB(physicsComponent2D.GetAABB(), graphicsComponent.GetAABB()); } } WHEN("We set an angular velocity") { Nz::RadianAnglef angularSpeed = Nz::RadianAnglef::FromDegrees(90.f); physicsComponent2D.SetAngularVelocity(angularSpeed); world.Update(1.f); THEN("We expect those to be true") { CHECK(physicsComponent2D.GetAngularVelocity() == angularSpeed); CHECK(physicsComponent2D.GetRotation() == angularSpeed); CHECK(physicsComponent2D.GetAABB() == Nz::Rectf(2.5f, 4.5f, 2.f, 1.f)); CompareAABB(physicsComponent2D.GetAABB(), graphicsComponent.GetAABB()); world.Update(1.f); CHECK(physicsComponent2D.GetRotation() == 2.f * angularSpeed); CHECK(physicsComponent2D.GetAABB() == Nz::Rectf(3.f, 4.0f, 1.f, 2.f)); CompareAABB(physicsComponent2D.GetAABB(), graphicsComponent.GetAABB()); world.Update(1.f); CHECK(physicsComponent2D.GetRotation() == 3.f * angularSpeed); CHECK(physicsComponent2D.GetAABB() == Nz::Rectf(2.5f, 4.5f, 2.f, 1.f)); CompareAABB(physicsComponent2D.GetAABB(), graphicsComponent.GetAABB()); world.Update(1.f); CHECK(physicsComponent2D.GetRotation() == 4.f * angularSpeed); } } } } void CompareAABB(const Nz::Rectf& aabb, const Nz::Boxf& box) { CHECK(aabb.x == Approx(box.x)); CHECK(aabb.y == Approx(box.y)); CHECK(aabb.width == Approx(box.width)); CHECK(aabb.height == Approx(box.height)); }