Documentation for module 'NDK'
Former-commit-id: 63e1cac538c577a1f1aafa71fa7eef69a6d4daab [formerly b2d8769fd02a0e7d9c476d4ad7be1988a1fd6789] [formerly 636b5cb79bcb8da44d9aa45ba1023565bcf29f0d [formerly a2361ec2b8679d4d4ba096e543b5d4b91825dd62]] Former-commit-id: d402d35477f9db0135c553d55c401939426bf62d [formerly 607336ea0f42731e4604f3a8c2df06f3aecfc401] Former-commit-id: 69e23cd6c06723486de5e4641ce810012dac66da
This commit is contained in:
43
tests/SDK/NDK/Systems/ListenerSystem.cpp
Normal file
43
tests/SDK/NDK/Systems/ListenerSystem.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <NDK/Components/ListenerComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/VelocityComponent.hpp>
|
||||
#include <Nazara/Audio/Audio.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
SCENARIO("ListenerSystem", "[NDK][LISTENERSYSTEM]")
|
||||
{
|
||||
GIVEN("A world and an entity with listener & node components")
|
||||
{
|
||||
Ndk::World world;
|
||||
const Ndk::EntityHandle& entity = world.CreateEntity();
|
||||
Ndk::ListenerComponent& listenerComponent = entity->AddComponent<Ndk::ListenerComponent>();
|
||||
Ndk::NodeComponent& nodeComponent = entity->AddComponent<Ndk::NodeComponent>();
|
||||
|
||||
WHEN("We move our entity")
|
||||
{
|
||||
Nz::Vector3f position = Nz::Vector3f::Unit() * 3.f;
|
||||
nodeComponent.SetPosition(position);
|
||||
Nz::Quaternionf rotation = Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), Nz::Vector3f::Up());
|
||||
nodeComponent.SetRotation(rotation);
|
||||
world.Update(1.f);
|
||||
|
||||
THEN("Our listener should have moved")
|
||||
{
|
||||
REQUIRE(Nz::Audio::GetListenerPosition() == position);
|
||||
REQUIRE(Nz::Audio::GetListenerRotation() == rotation);
|
||||
}
|
||||
|
||||
THEN("With a component of velocity")
|
||||
{
|
||||
Ndk::VelocityComponent& velocityComponent = entity->AddComponent<Ndk::VelocityComponent>();
|
||||
Nz::Vector3f velocity = Nz::Vector3f::Unit() * 2.f;
|
||||
velocityComponent.linearVelocity = velocity;
|
||||
|
||||
world.Update(1.f);
|
||||
REQUIRE(Nz::Audio::GetListenerVelocity() == velocity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
tests/SDK/NDK/Systems/PhysicsSystem.cpp
Normal file
34
tests/SDK/NDK/Systems/PhysicsSystem.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <NDK/Systems/PhysicsSystem.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <NDK/Components/CollisionComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/PhysicsComponent.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
SCENARIO("PhysicsSystem", "[NDK][PHYSICSSYSTEM]")
|
||||
{
|
||||
GIVEN("A world and a static entity & a dynamic entity")
|
||||
{
|
||||
Ndk::World world;
|
||||
const Ndk::EntityHandle& staticEntity = world.CreateEntity();
|
||||
Ndk::CollisionComponent& collisionComponentStatic = staticEntity->AddComponent<Ndk::CollisionComponent>();
|
||||
Ndk::NodeComponent& nodeComponentStatic = staticEntity->AddComponent<Ndk::NodeComponent>();
|
||||
|
||||
const Ndk::EntityHandle& dynamicEntity = world.CreateEntity();
|
||||
Ndk::NodeComponent& nodeComponentDynamic = dynamicEntity->AddComponent<Ndk::NodeComponent>();
|
||||
Ndk::PhysicsComponent& physicsComponentDynamic = dynamicEntity->AddComponent<Ndk::PhysicsComponent>();
|
||||
|
||||
WHEN("We make collide these two entities")
|
||||
{
|
||||
nodeComponentDynamic.SetPosition(-Nz::Vector3f::UnitZ());
|
||||
physicsComponentDynamic.AddForce(Nz::Vector3f::UnitZ());
|
||||
|
||||
THEN("The dynamic entity should have hit the static one")
|
||||
{
|
||||
world.Update(1.f); // On origin
|
||||
world.Update(1.f); // On origin due to collision
|
||||
REQUIRE(nodeComponentStatic.GetPosition().SquaredDistance(nodeComponentDynamic.GetPosition()) < 0.2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
44
tests/SDK/NDK/Systems/RenderSystem.cpp
Normal file
44
tests/SDK/NDK/Systems/RenderSystem.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <NDK/Components/CameraComponent.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/LightComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/ParticleGroupComponent.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
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::CameraComponent>();
|
||||
Ndk::NodeComponent& nodeComponentCamera = cameraEntity->AddComponent<Ndk::NodeComponent>();
|
||||
|
||||
const Ndk::EntityHandle& drawableEntity = world.CreateEntity();
|
||||
Ndk::GraphicsComponent& graphicsComponentDrawable = drawableEntity->AddComponent<Ndk::GraphicsComponent>();
|
||||
Nz::SpriteRef sprite = Nz::Sprite::New();
|
||||
graphicsComponentDrawable.Attach(sprite);
|
||||
Ndk::NodeComponent& nodeComponentDrawable = drawableEntity->AddComponent<Ndk::NodeComponent>();
|
||||
|
||||
const Ndk::EntityHandle& lightEntity = world.CreateEntity();
|
||||
Ndk::LightComponent& lightComponentLight = lightEntity->AddComponent<Ndk::LightComponent>();
|
||||
Ndk::NodeComponent& nodeComponentLight = lightEntity->AddComponent<Ndk::NodeComponent>();
|
||||
|
||||
const Ndk::EntityHandle& particlesEntity = world.CreateEntity();
|
||||
Ndk::ParticleGroupComponent& particleGroupComponentParticles = particlesEntity->AddComponent<Ndk::ParticleGroupComponent>(1, Nz::ParticleLayout_Sprite);
|
||||
|
||||
WHEN("We change the render technique to ForwardRenderTechnique")
|
||||
{
|
||||
Ndk::RenderSystem& renderSystem = world.GetSystem<Ndk::RenderSystem>();
|
||||
renderSystem.ChangeRenderTechnique<Nz::ForwardRenderTechnique>();
|
||||
|
||||
THEN("The render system should be ForwardRenderTechnique")
|
||||
{
|
||||
REQUIRE(renderSystem.GetRenderTechnique().GetType() == Nz::RenderTechniqueType_BasicForward);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
28
tests/SDK/NDK/Systems/VelocitySystem.cpp
Normal file
28
tests/SDK/NDK/Systems/VelocitySystem.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <NDK/Systems/VelocitySystem.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/VelocityComponent.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
SCENARIO("VelocitySystem", "[NDK][VELOCITYSYSTEM]")
|
||||
{
|
||||
GIVEN("A world and an entity with velocity & node components")
|
||||
{
|
||||
Ndk::World world;
|
||||
const Ndk::EntityHandle& entity = world.CreateEntity();
|
||||
Ndk::VelocityComponent& velocityComponent = entity->AddComponent<Ndk::VelocityComponent>();
|
||||
Ndk::NodeComponent& nodeComponent = entity->AddComponent<Ndk::NodeComponent>();
|
||||
|
||||
WHEN("We give a speed to our entity")
|
||||
{
|
||||
Nz::Vector3f velocity = Nz::Vector3f::Unit() * 2.f;
|
||||
velocityComponent.linearVelocity = velocity;
|
||||
world.Update(1.f);
|
||||
|
||||
THEN("Our entity should have moved")
|
||||
{
|
||||
REQUIRE(nodeComponent.GetPosition().SquaredDistance(velocity) < 0.2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user