109 lines
3.5 KiB
C++
109 lines
3.5 KiB
C++
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include "CubesExampleApp.hpp"
|
|
#include "Scene/Scene.hpp"
|
|
#include "Scene/Shader.hpp"
|
|
#include "Scene/Vertex.hpp"
|
|
#include "Input/InputManager.hpp"
|
|
#include "Host/GraphicsAppManager.hpp"
|
|
#include "Math/Math.hpp"
|
|
#include "Base/EngineConfiguration.hpp"
|
|
#include "Controller/FreeCamCameraController.hpp"
|
|
|
|
#pragma clang diagnostic push
|
|
#pragma ide diagnostic ignored "cert-msc50-cpp"
|
|
#pragma ide diagnostic ignored "cppcoreguidelines-narrowing-conversions"
|
|
|
|
using namespace openVulkanoCpp::Scene;
|
|
using namespace openVulkanoCpp::Input;
|
|
using namespace openVulkanoCpp::Math;
|
|
|
|
uint32_t GEOS = 3000, OBJECTS = 10000, DYNAMIC = 1000;
|
|
|
|
class CubesExampleAppImpl final : public CubesExampleApp
|
|
{
|
|
Scene scene;
|
|
PerspectiveCamera cam;
|
|
openVulkanoCpp::FreeCamCameraController camController;
|
|
Material mat;
|
|
Shader shader;
|
|
std::vector<Drawable> drawablesPool;
|
|
std::vector<Node> nodesPool;
|
|
|
|
InputAction* actionForward;
|
|
InputAction* actionSide;
|
|
InputAction* actionLookUp;
|
|
InputAction* actionLookSide;
|
|
|
|
float yaw = 0, pitch = 0;
|
|
Vector3f_SIMD position = {0,0,-10};
|
|
|
|
public:
|
|
std::string GetAppName() override { return "ExampleApp"; }
|
|
std::string GetAppVersion() override { return "v1.0"; }
|
|
int GetAppVersionAsInt() override { return 1; }
|
|
|
|
void Init() override
|
|
{
|
|
auto engineConfig = openVulkanoCpp::EngineConfiguration::GetEngineConfiguration();
|
|
engineConfig->SetNumThreads(4);
|
|
engineConfig->SetPreferFramebufferFormatSRGB(false);
|
|
|
|
std::srand(1); // Fix seed for random numbers
|
|
scene.Init();
|
|
cam.Init(70, 16, 9, 0.1f, 100);
|
|
scene.SetCamera(&cam);
|
|
cam.SetMatrix(Utils::translate(Matrix4f(1), Vector3f_SIMD(0,0,-10)));
|
|
shader.AddShaderProgram(ShaderProgramType::VERTEX, "Shader/basic");
|
|
shader.AddShaderProgram(ShaderProgramType::FRAGMENT, "Shader/basic");
|
|
shader.AddVertexInputDescription(openVulkanoCpp::Vertex::GetVertexInputDescription());
|
|
drawablesPool.resize(GEOS);
|
|
for(int i = 0; i < GEOS; i++)
|
|
{
|
|
Geometry* geo = new Geometry();
|
|
geo->InitCube(std::rand() % 1000 / 1000.0f + 0.01f, std::rand() % 1000 / 1000.0f + 0.01f, std::rand() % 1000 / 1000.0f + 0.01f, Vector4f((std::rand() % 255) / 255.0f, (std::rand() % 255) / 255.0f, (std::rand() % 255) / 255.0f, 1));
|
|
drawablesPool[i].Init(geo, &mat);
|
|
}
|
|
nodesPool.resize(OBJECTS);
|
|
for(int i = 0; i < OBJECTS; i++)
|
|
{
|
|
nodesPool[i].Init();
|
|
scene.GetRoot()->AddChild(&nodesPool[i]);
|
|
if (i < DYNAMIC) nodesPool[i].SetUpdateFrequency(UpdateFrequency::Always);
|
|
nodesPool[i].AddDrawable(&drawablesPool[std::rand() % GEOS]);
|
|
nodesPool[i].SetMatrix(Utils::translate(glm::mat4x4(1), Vector3f((std::rand() % 10000) / 1000.0f - 5, (std::rand() % 10000) / 1000.0f - 5, (std::rand() % 10000) / 1000.0f - 5)));
|
|
}
|
|
|
|
scene.shader = &shader;
|
|
|
|
GetGraphicsAppManager()->GetRenderer()->SetScene(&scene);
|
|
|
|
camController.Init(&cam);
|
|
camController.SetDefaultKeybindings();
|
|
}
|
|
|
|
void Tick() override
|
|
{
|
|
for(int i = 0; i < DYNAMIC; i++)
|
|
{
|
|
nodesPool[i].SetMatrix(glm::translate(glm::mat4x4(1), glm::vec3((std::rand() % 10000) / 1000.0f - 5, (std::rand() % 10000) / 1000.0f - 5, (std::rand() % 10000) / 1000.0f - 5)));
|
|
}
|
|
|
|
camController.Tick();
|
|
}
|
|
|
|
void Close() override{}
|
|
};
|
|
|
|
std::unique_ptr<openVulkanoCpp::IGraphicsApp> CubesExampleApp::Create()
|
|
{
|
|
return std::make_unique<CubesExampleAppImpl>();
|
|
}
|
|
|
|
#pragma clang diagnostic pop
|
|
#pragma clang diagnostic pop
|