2021-07-15 15:56:30 +04:30
|
|
|
#include <LightEngine.h>
|
|
|
|
|
2021-07-25 17:50:08 +04:30
|
|
|
namespace Light {
|
2021-07-15 15:56:30 +04:30
|
|
|
|
2021-07-25 17:50:08 +04:30
|
|
|
class MirrorLayer : public Layer
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::shared_ptr<Texture> m_AwesomefaceTexture;
|
2021-07-15 15:56:30 +04:30
|
|
|
|
2021-07-25 17:50:08 +04:30
|
|
|
std::vector<glm::vec3> positions;
|
|
|
|
std::vector<glm::vec2> sizes;
|
2021-07-15 15:56:30 +04:30
|
|
|
|
2021-07-25 17:50:08 +04:30
|
|
|
glm::vec2 m_Direction;
|
|
|
|
float m_Speed = 1000.0f;
|
2021-07-15 15:56:30 +04:30
|
|
|
|
2021-07-26 11:43:37 +04:30
|
|
|
Ref<Camera> m_Camera;
|
2021-07-15 15:56:30 +04:30
|
|
|
|
2021-07-26 11:43:37 +04:30
|
|
|
Ref<Framebuffer> m_Framebuffer;
|
2021-07-21 20:03:39 +04:30
|
|
|
|
2021-07-25 17:50:08 +04:30
|
|
|
Scene m_Scene;
|
|
|
|
|
|
|
|
Entity m_TestEntity;
|
2021-07-15 15:56:30 +04:30
|
|
|
|
2021-07-25 17:50:08 +04:30
|
|
|
bool m_GameSceneEvents = false;
|
2021-07-15 15:56:30 +04:30
|
|
|
|
2021-07-25 17:50:08 +04:30
|
|
|
public:
|
|
|
|
MirrorLayer(const std::string& name)
|
|
|
|
: Layer(name), m_Direction(glm::vec2(0.0f, 0.0f))
|
2021-07-15 15:56:30 +04:30
|
|
|
{
|
2021-07-25 17:50:08 +04:30
|
|
|
m_Camera = std::make_shared<Camera>(glm::vec2(500.0f), NULL, 1000.0f);
|
2021-07-15 15:56:30 +04:30
|
|
|
|
2021-07-25 17:50:08 +04:30
|
|
|
ResourceManager::LoadTexture("awesomeface", "res/Textures/awesomeface.png");
|
|
|
|
m_AwesomefaceTexture = ResourceManager::GetTexture("awesomeface");
|
2021-07-15 15:56:30 +04:30
|
|
|
|
2021-07-25 17:50:08 +04:30
|
|
|
m_Framebuffer = std::shared_ptr<Framebuffer>(Framebuffer::Create({ 800u, 600u, 1, glm::vec4(1.0f, 0.0f, 0.0f, 1.0f), false }, GraphicsContext::GetSharedContext()));
|
2021-07-15 15:56:30 +04:30
|
|
|
|
2021-07-25 17:50:08 +04:30
|
|
|
for (int i = 0; i < 250; i++)
|
|
|
|
{
|
|
|
|
glm::vec3 position = glm::vec3(rand() % 3000 - 1400.0f, rand() % 3000 - 1400.0f, 0.0f);
|
|
|
|
glm::vec2 size = glm::vec2(250.0f, 250.0f);
|
2021-07-15 15:56:30 +04:30
|
|
|
|
2021-07-25 17:50:08 +04:30
|
|
|
positions.push_back(position);
|
|
|
|
sizes.push_back(size);
|
2021-07-15 15:56:30 +04:30
|
|
|
|
2021-07-25 17:50:08 +04:30
|
|
|
m_Scene.CreateEntity("quad", position, size).AddComponent<SpriteRendererComponent>(m_AwesomefaceTexture);
|
|
|
|
}
|
|
|
|
}
|
2021-07-15 15:56:30 +04:30
|
|
|
|
2021-07-25 17:50:08 +04:30
|
|
|
void OnRender() override
|
2021-07-16 19:59:14 +04:30
|
|
|
{
|
2021-07-25 17:50:08 +04:30
|
|
|
m_Camera->CalculateProjection();
|
|
|
|
m_Camera->CalculateView();
|
|
|
|
|
|
|
|
Renderer::BeginScene(m_Camera, m_Framebuffer);
|
2021-07-21 20:03:39 +04:30
|
|
|
|
2021-07-25 17:50:08 +04:30
|
|
|
m_Scene.OnRender();
|
2021-07-21 20:03:39 +04:30
|
|
|
|
2021-07-25 17:50:08 +04:30
|
|
|
Renderer::EndScene();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnUserInterfaceUpdate()
|
|
|
|
{
|
|
|
|
if (ImGui::Begin("GameView"))
|
2021-07-21 20:03:39 +04:30
|
|
|
{
|
2021-07-25 17:50:08 +04:30
|
|
|
Input::ReceiveGameEvents(ImGui::IsWindowFocused());
|
|
|
|
|
|
|
|
static ImVec2 regionAvailPrev = { 0, 0 };
|
|
|
|
ImVec2 regionAvail = ImGui::GetContentRegionAvail();
|
|
|
|
|
|
|
|
if (regionAvail.x != regionAvailPrev.x || regionAvail.y != regionAvailPrev.y)
|
|
|
|
{
|
|
|
|
m_Framebuffer->Resize({ regionAvail.x, regionAvail.y });
|
|
|
|
m_Camera->OnResize({ regionAvail.x, regionAvail.y });
|
|
|
|
regionAvailPrev = regionAvail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GraphicsContext::GetGraphicsAPI() == GraphicsAPI::DirectX)
|
|
|
|
ImGui::Image(m_Framebuffer->GetColorAttachment(), regionAvail);
|
|
|
|
else
|
|
|
|
ImGui::Image(m_Framebuffer->GetColorAttachment(), regionAvail, ImVec2(0, 1), ImVec2(1, 0));
|
2021-07-21 20:03:39 +04:30
|
|
|
}
|
|
|
|
|
2021-07-25 17:50:08 +04:30
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnUpdate(float deltaTime) override
|
|
|
|
{
|
|
|
|
if (Input::GetKeyboardKey(KEY_A))
|
|
|
|
m_Direction.x = -1.0f;
|
|
|
|
else if (Input::GetKeyboardKey(KEY_D))
|
|
|
|
m_Direction.x = 1.0f;
|
|
|
|
else
|
|
|
|
m_Direction.x = 0.0f;
|
|
|
|
|
|
|
|
if (Input::GetKeyboardKey(KEY_W))
|
|
|
|
m_Direction.y = 1.0f;
|
|
|
|
else if (Input::GetKeyboardKey(KEY_S))
|
|
|
|
m_Direction.y = -1.0f;
|
2021-07-21 20:03:39 +04:30
|
|
|
else
|
2021-07-25 17:50:08 +04:30
|
|
|
m_Direction.y = 0.0f;
|
|
|
|
|
|
|
|
m_Camera->Move(m_Direction * m_Speed * deltaTime);
|
2021-07-16 19:59:14 +04:30
|
|
|
}
|
|
|
|
|
2021-07-25 17:50:08 +04:30
|
|
|
};
|
2021-07-15 15:56:30 +04:30
|
|
|
|
2021-07-25 17:50:08 +04:30
|
|
|
}
|