2#include "common/maths/Vec.h"
4const int number_of_sphere = 36;
5float sphere_radius = 25.0f;
6float space_between_spheres = 150.0f;
12 glm::vec3 suzannePosition = glm::vec3(0, 50, -200);
13 glm::vec3 lightPosition = glm::vec3(0, 0, 0);
16 Ref<Vivid::Shader> lightShader;
17 Ref<Vivid::Entity> suzanne = Vivid::ECS::CreateEntity(
"Sphere");
18 Ref<Vivid::Entity> light = Vivid::ECS::CreateEntity(
"Light");
19 Ref<Vivid::ModelComponent> modelComponent1;
20 Ref<Vivid::TransformComponent> sphereTransformComponent = Vivid::ECS::CreateComponent<Vivid::TransformComponent>();
23 Ref<Vivid::DirectionalLightComponent> directionalLightComponent;
24 Ref<Vivid::Shader> shader;
26 std::vector<Vivid::Maths::Vec3> translations;
34 shader = MakeRef<Vivid::Shader>(
35 "./../assets/shaders/instancing.vertexShader.glsl",
36 "./../assets/shaders/instancing.pixelShader.glsl");
38 sphere =
new Vivid::Mesh(
"./../assets/obj/newIcoSphere.obj", number_of_sphere);
39 sphere->BindShader(shader);
41 modelComponent1 = Vivid::ECS::CreateComponent<Vivid::ModelComponent>();
42 modelComponent1->AddMesh(sphere);
45 directionalLightComponent = Vivid::ECS::CreateComponent<Vivid::DirectionalLightComponent>();
48 Vivid::ECS::AddComponent(modelComponent1->GetComponentID(), suzanne->GetEntityID());
49 Vivid::ECS::AddComponent(sphereTransformComponent->GetComponentID(), suzanne->GetEntityID());
51 Vivid::ECS::AddComponent(directionalLightComponent->GetComponentID(), light->GetEntityID());
54 for (
unsigned int i = 0; i < number_of_sphere; i++)
59 translation.x = (float)(i % 6) * space_between_spheres + 200.0f;
60 translation.y = (float)(i / 6) * space_between_spheres + 200.0f;
63 translations.push_back(translation);
64 translations[i] = translation;
71 for (
unsigned int i = 0; i < number_of_sphere; i++)
76 translation.x = (float)(i % 6) * space_between_spheres;
77 translation.y = (float)(i / 6) * space_between_spheres;
80 translations[i] = translation;
83 Vector<Vivid::DirectionalLightComponent*> directionalLights;
84 Vivid::ECS::GetAllComponents(Vivid::ComponentType::DirectionalLightComponent, directionalLights);
87 sphere->BindShader(shader);
88 shader->SetUniform3f(
"LightDir", lightDir);
89 shader->SetUniform3f(
"LightColor", lightColor);
90 for (
unsigned int i = 0; i < number_of_sphere; i++)
92 shader->SetUniform3f((
"offsets[" + std::to_string(i) +
"]"),
106 mousePos = camera->ScreenToWorldCoords(mousePos.x, mousePos.y);
108 std::cout <<
"Mouse Pos: " << hitPos.x <<
", " << hitPos.y <<
"\n";
112 for (
unsigned int i = 0; i < number_of_sphere; i++)
117 float z2 = sphere_radius * sphere_radius - (hitPos.x - translation.x) * (hitPos.x - translation.x) - (hitPos.y - translation.y) * (hitPos.y - translation.y);
120 shader->SetUniform1f(
"isSelected[" + std::to_string(i) +
"]", 1.0f);
123 hitPos.z = sqrt(std::max(0.0f, z2));
126 float mag = sqrt(normal.x * normal.x + normal.y * normal.y + normal.z * normal.z);
127 normal = normal * (1.0f / mag);
128 shader->SetUniform3f(
"hitNormal", normal);
132 shader->SetUniform1f(
"isSelected[" + std::to_string(i) +
"]", 0.0f);
140 ImGui::Begin(
"Debug");
141 ImGui::Text(
"Application average %.3f ms/frame (%.1f FPS)",
142 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
143 ImGui::SliderFloat(
"Sphere Radius", &sphere_radius, 0.0f, 200.0f);
144 ImGui::SliderFloat(
"Space Between Spheres", &space_between_spheres, 0.0f, 500.0f);
156 Application* app = Application::GetInstance(1920, 1080,
"Rendering Assignment", camera);
165 return Vivid::main(0,
nullptr);
void Setup() override
Setup function.
void ImGuiRender() override
ImGuiRender function.
void Draw() override
Draw function.
A class for the OrthoCamera's.
RenderingInterface class.