Last active
September 19, 2017 20:24
-
-
Save WinXaito/e89f7b3c7abca6a25b0a3b9111f66a85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Nazara/Audio.hpp> | |
#include <Nazara/Core.hpp> | |
#include <Nazara/Graphics.hpp> | |
#include <Nazara/Lua.hpp> | |
#include <Nazara/Network.hpp> | |
#include <Nazara/Noise.hpp> | |
#include <Nazara/Physics2D.hpp> | |
#include <Nazara/Physics3D.hpp> | |
#include <Nazara/Renderer.hpp> | |
#include <Nazara/Utility.hpp> | |
#include <NDK/Application.hpp> | |
#include <NDK/Components.hpp> | |
#include <NDK/World.hpp> | |
#include <NDK/Systems.hpp> | |
#include <iostream> | |
int main(int argc, char* argv[]) | |
{ | |
//Initialisation de l'application | |
Ndk::Application application(argc, argv); | |
//Création de la fenêtre | |
Nz::RenderWindow& mainWindow = application.AddWindow<Nz::RenderWindow>(); | |
mainWindow.Create(Nz::VideoMode(800, 600, 32), "Test"); | |
//Création du monde | Inversion de l'axe Y | Créer un background orange | |
Ndk::World& world = application.AddWorld(); | |
//world.GetSystem<Ndk::RenderSystem>().SetGlobalUp(Nz::Vector3f::Down()); | |
world.GetSystem<Ndk::RenderSystem>().SetDefaultBackground(Nz::ColorBackground::New(Nz::Color(Nz::Color::Orange))); | |
//Créer une nouvelle entité (Caméra) | |
Ndk::EntityHandle cameraEntity = world.CreateEntity(); | |
cameraEntity->AddComponent<Ndk::NodeComponent>(); | |
//Création du viewer de la caméra et paramétrage de celle-ci | |
Ndk::CameraComponent& cameraViewer = cameraEntity->AddComponent<Ndk::CameraComponent>(); | |
cameraViewer.SetTarget(&mainWindow); | |
cameraViewer.SetProjectionType(Nz::ProjectionType_Perspective); | |
//cameraViewer.SetProjectionType(Nz::ProjectionType_Orthogonal); | |
//Création d'un nouveau textSprite, et on écrit dedans notre text | |
Nz::TextSpriteRef textSprite = Nz::TextSprite::New(); | |
textSprite->Update(Nz::SimpleTextDrawer::Draw("Hello world !", 72)); | |
//Création du cube central | |
Nz::MeshRef mesh = Nz::Mesh::New(); | |
mesh->CreateStatic(); | |
Nz::SubMeshRef subMesh = mesh->BuildSubMesh(Nz::Primitive::Box(Nz::Vector3f(1.f, 1.f, 1.f))); | |
Ndk::EntityHandle cube = world.CreateEntity(); | |
Ndk::NodeComponent& cubeComponent = cube->AddComponent<Ndk::NodeComponent>(); | |
auto lightModel = Nz::Model::New(); | |
lightModel->SetMesh(mesh); | |
Ndk::GraphicsComponent& cubeGraphics = cube->AddComponent<Ndk::GraphicsComponent>(); | |
cubeGraphics.Attach(lightModel); | |
//On créer notre nouvelle entité text, et on défini le nodeComponent | |
Ndk::EntityHandle text = world.CreateEntity(); | |
Ndk::NodeComponent& nodeComponent = text->AddComponent<Ndk::NodeComponent>(); | |
//nodeComponent.SetPosition(0, 0, 2); | |
//Création du graphicsComponent | |
Ndk::GraphicsComponent& graphicsComponent = text->AddComponent<Ndk::GraphicsComponent>(); | |
graphicsComponent.Attach(textSprite); | |
//On récupère le textBox et on déplace le text | |
Nz::Boxf textBox = graphicsComponent.GetBoundingVolume().aabb; | |
//nodeComponent.SetPosition(mainWindow.GetWidth() / 2 - textBox.width / 2, mainWindow.GetHeight() / 2 - textBox.height / 2); | |
//Récupération des événements de la fenêtre | |
Nz::EventHandler& eventHandler = mainWindow.GetEventHandler(); | |
eventHandler.OnKeyPressed.Connect([](const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& e) { | |
//Si la touche Escape est cliqué, on qui le jeu | |
if (e.code == Nz::Keyboard::Escape) | |
Ndk::Application::Instance()->Quit(); | |
}); | |
//Boucle du jeu | |
while (application.Run()) { | |
mainWindow.Display(); | |
Ndk::NodeComponent& comp = cameraEntity->GetComponent<Ndk::NodeComponent>(); | |
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::W)) { | |
//Ndk::NodeComponent& comp = cameraEntity->GetComponent<Ndk::NodeComponent>(); | |
comp.Move(0.f, 0.f, 100.f * application.GetUpdateTime()); | |
} | |
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::S)) { | |
//Ndk::NodeComponent& comp = cameraEntity->GetComponent<Ndk::NodeComponent>(); | |
comp.Move(0.f, 0.f, -100.f * application.GetUpdateTime()); | |
} | |
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::A)) { | |
//Ndk::NodeComponent& comp = cameraEntity->GetComponent<Ndk::NodeComponent>(); | |
comp.Move(-100.f * application.GetUpdateTime(), 0.f, 0.f); | |
} | |
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::D)) { | |
//Ndk::NodeComponent& comp = cameraEntity->GetComponent<Ndk::NodeComponent>(); | |
comp.Move(100.f * application.GetUpdateTime(), 0.f, 0.f); | |
} | |
if (Nz::Keyboard::Right) { | |
comp.Rotate(Nz::EulerAnglesf{ 1.f, 0.f, 0.f }); | |
} | |
if (Nz::Keyboard::Left) { | |
comp.Rotate(Nz::EulerAnglesf{ -1.f, 0.f, 0.f }); | |
} | |
if (Nz::Keyboard::Up) { | |
comp.Rotate(Nz::EulerAnglesf{ 0.f, 1.f, 0.f }); | |
} | |
if (Nz::Keyboard::Down) { | |
comp.Rotate(Nz::EulerAnglesf{ 0.f, -1.f, 0.f }); | |
} | |
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Space)) { | |
Ndk::NodeComponent& compHw = text->GetComponent<Ndk::NodeComponent>(); | |
std::cout << "Helloworld pos: X" << compHw.GetPosition().x << " Y" << compHw.GetPosition().y << " Z" << compHw.GetPosition().z << std::endl; | |
} | |
else { | |
std::cout << "Camera pos: X" << comp.GetPosition().x << " Y" << comp.GetPosition().y << " Z" << comp.GetPosition().z << std::endl; | |
} | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment