Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. int main()
  2. {
  3.     Ndk::Application application;
  4.  
  5.     Nz::RenderWindow& mainWindow = application.AddWindow<Nz::RenderWindow>();
  6.     mainWindow.Create(Nz::VideoMode(800, 600, 32), "Test");
  7.  
  8.     Ndk::World& world = application.AddWorld();
  9.     world.GetSystem<Ndk::RenderSystem>().SetGlobalUp(Nz::Vector3f::Up());
  10.  
  11.  
  12.     Ndk::EntityHandle viewEntity = world.CreateEntity();
  13.     viewEntity->AddComponent<Ndk::NodeComponent>();
  14.  
  15.     Ndk::CameraComponent& viewer = viewEntity->AddComponent<Ndk::CameraComponent>();
  16.     viewer.SetTarget(&mainWindow);
  17.     viewer.SetProjectionType(Nz::ProjectionType_Perspective);
  18.  
  19.     Nz::ModelRef model = Nz::Model::New();
  20.     Nz::MeshRef mesh = Nz::Mesh::New();
  21.     mesh->CreateStatic();
  22.     Nz::SubMeshRef subMesh = mesh->BuildSubMesh(Nz::Primitive::IcoSphere(2));
  23.     subMesh->SetMaterialIndex(0);
  24.     model->SetMesh(mesh);
  25.  
  26.     Nz::MaterialRef mat = Nz::Material::New();
  27.     mat->SetShader("PhongLighting");
  28.     mat->SetDiffuseColor(Nz::Color::Green);
  29.     mat->SetSpecularColor(Nz::Color::Black);
  30.     mat->SetFaceFilling(Nz::FaceFilling_Fill);
  31.     model->SetMaterial(0, mat);
  32.  
  33.     Ndk::EntityHandle cube = world.CreateEntity();
  34.     Ndk::NodeComponent& cubeNode = cube->AddComponent<Ndk::NodeComponent>();
  35.     Ndk::GraphicsComponent & cubeGraphics = cube->AddComponent<Ndk::GraphicsComponent>();
  36.     cubeGraphics.Attach(model);
  37.     Nz::Boxf cubeBox = cubeGraphics.GetBoundingVolume().aabb;
  38.     cubeNode.SetPosition(0, 0, -10);
  39.  
  40.     Ndk::EntityHandle light = world.CreateEntity();
  41.     Ndk::NodeComponent& lightNode = light->AddComponent<Ndk::NodeComponent>();
  42.     Ndk::LightComponent & lightLight = light->AddComponent<Ndk::LightComponent>();
  43.     lightLight.SetLightType(Nz::LightType_Point);
  44.     lightLight.SetAmbientFactor(0.1f);
  45.     lightLight.SetRadius(100);
  46.     lightNode.SetPosition(Nz::Vector3f(5, 5, 0));
  47.  
  48.     world.GetSystem<Ndk::RenderSystem>().SetDefaultBackground(Nz::ColorBackground::New(Nz::Color(117, 122, 214)));
  49.  
  50.     Nz::Clock clock;
  51.  
  52.     while (application.Run())
  53.     {
  54.         cubeNode.SetRotation(Nz::Quaternionf(Nz::EulerAnglesf(clock.GetSeconds() * 10, clock.GetSeconds() * 23.2f, 0)));
  55.         //lightLight.SetRadius(clock.GetSeconds());
  56.         mainWindow.Display();
  57.     }
  58.  
  59.     return EXIT_SUCCESS;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement