Some Rendering Stuff.
Se ha añadido un método para cambiar el color de clear. Se ha abstraido la cámara del renderer para más versatilidad a futuro. Nota: La implementación de la cámara no es nada segura. Tocará revisarlo
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
#include "Camera.h"
|
||||||
|
#include "Logging/Logger.h"
|
||||||
|
|
||||||
|
namespace UE
|
||||||
|
{
|
||||||
|
|
||||||
|
void Camera::SetCamPosition(int posX, int posY)
|
||||||
|
{
|
||||||
|
camPosition.x = posX;
|
||||||
|
camPosition.y = posY;
|
||||||
|
|
||||||
|
UE_LOG_TRACE("Cam position chaged to: {0}x{1}", posX, posY);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <glm/vec2.hpp>
|
||||||
|
|
||||||
|
//
|
||||||
|
// ToDO:
|
||||||
|
// - La cámara debería tener un tamaño definido.
|
||||||
|
// para hacer zoom y esas cosas.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
namespace UE
|
||||||
|
{
|
||||||
|
class Camera
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Camera() {}
|
||||||
|
|
||||||
|
Camera(int posX, int posY)
|
||||||
|
: camPosition{posX, posY}
|
||||||
|
{}
|
||||||
|
|
||||||
|
inline glm::ivec2 GetCamPosition() { return camPosition; }
|
||||||
|
void SetCamPosition(int posX, int posY);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
glm::ivec2 camPosition { 0, 0 };
|
||||||
|
|
||||||
|
//glm::ivec2 camSize { 0, 0 };
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -56,6 +56,7 @@ namespace UE
|
|||||||
{
|
{
|
||||||
renderLayers.push_back(std::vector<DrawCall>());
|
renderLayers.push_back(std::vector<DrawCall>());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::CleanRenderer()
|
void Renderer::CleanRenderer()
|
||||||
@@ -91,6 +92,10 @@ namespace UE
|
|||||||
//Quiz�s deber�amos limpiar la cola y las Layers aqu� para eliminar residuos...
|
//Quiz�s deber�amos limpiar la cola y las Layers aqu� para eliminar residuos...
|
||||||
//callCounter = 0;
|
//callCounter = 0;
|
||||||
//rendererCounter = 0;
|
//rendererCounter = 0;
|
||||||
|
|
||||||
|
//Actualizamos el rect que representa la pantalla.
|
||||||
|
glm::ivec2 camPos = activeCam->GetCamPosition();
|
||||||
|
_screenRect = {camPos.x, camPos.y, screenSize.x, screenSize.y};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::RenderData()
|
void Renderer::RenderData()
|
||||||
@@ -131,7 +136,6 @@ namespace UE
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Renderer::EndFrame()
|
void Renderer::EndFrame()
|
||||||
{
|
{
|
||||||
//SDL_UpdateWindowSurface(window);
|
//SDL_UpdateWindowSurface(window);
|
||||||
@@ -160,11 +164,9 @@ namespace UE
|
|||||||
UE_LOG_TRACE("Screen size chaged to: {0}x{1}", newWidth, newHeight);
|
UE_LOG_TRACE("Screen size chaged to: {0}x{1}", newWidth, newHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::SetCamPosition(int posX, int posY)
|
void Renderer::SetDrawingColor(SDL_Color& newColor)
|
||||||
{
|
{
|
||||||
camPosition.x = posX;
|
SDL_SetRenderDrawColor(main_Renderer, newColor.r, newColor.g, newColor.b, newColor.a);
|
||||||
camPosition.y = posY;
|
|
||||||
//UE_LOG_TRACE("Cam position chaged to: {0}x{1}", posX, posY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -172,7 +174,7 @@ namespace UE
|
|||||||
glm::ivec2 Renderer::WorldToSreenCoords(glm::ivec2 worldCoord)
|
glm::ivec2 Renderer::WorldToSreenCoords(glm::ivec2 worldCoord)
|
||||||
{
|
{
|
||||||
//Convertimos las coordenas de WorldCoords a ScreenCoords relativas a la camPosition.
|
//Convertimos las coordenas de WorldCoords a ScreenCoords relativas a la camPosition.
|
||||||
glm::ivec2 fPos = worldCoord - camPosition;
|
glm::ivec2 fPos = worldCoord - activeCam->GetCamPosition();
|
||||||
|
|
||||||
return fPos;
|
return fPos;
|
||||||
}
|
}
|
||||||
@@ -180,7 +182,7 @@ namespace UE
|
|||||||
glm::ivec2 Renderer::ScreenToWorldCoords(glm::ivec2 screenCoord)
|
glm::ivec2 Renderer::ScreenToWorldCoords(glm::ivec2 screenCoord)
|
||||||
{
|
{
|
||||||
//Convertimos las coordenas de ScreenCoords a WorldCoords relativas a la camPosition.
|
//Convertimos las coordenas de ScreenCoords a WorldCoords relativas a la camPosition.
|
||||||
glm::ivec2 fPos = screenCoord + camPosition;
|
glm::ivec2 fPos = screenCoord + activeCam->GetCamPosition();
|
||||||
|
|
||||||
return fPos;
|
return fPos;
|
||||||
}
|
}
|
||||||
@@ -189,11 +191,8 @@ namespace UE
|
|||||||
//LAS COORDS QUE USAMOS EN LA COMPROBACI�N NO SON LAS ADECUADAS.
|
//LAS COORDS QUE USAMOS EN LA COMPROBACI�N NO SON LAS ADECUADAS.
|
||||||
bool Renderer::IsObjectVisible(SDL_Rect* objectRect)
|
bool Renderer::IsObjectVisible(SDL_Rect* objectRect)
|
||||||
{
|
{
|
||||||
|
|
||||||
//Generamos un rect que representa la pantalla.
|
|
||||||
SDL_Rect screen{ camPosition.x, camPosition.y, screenSize.x, screenSize.y };
|
|
||||||
//Comprobamos si hay intersecci�n entre ambos.
|
//Comprobamos si hay intersecci�n entre ambos.
|
||||||
if (!SDL_HasIntersection(&screen, objectRect))
|
if (!SDL_HasIntersection(&_screenRect, objectRect))
|
||||||
{
|
{
|
||||||
//UE_LOG_TRACE("Se omite el renderizado de un objeto al estar fuera de la c�mara.");
|
//UE_LOG_TRACE("Se omite el renderizado de un objeto al estar fuera de la c�mara.");
|
||||||
return false;
|
return false;
|
||||||
@@ -220,16 +219,12 @@ namespace UE
|
|||||||
UE_LOG_ERROR("Can't add DrawCall to Layer {0} -> out of range\n", drawCall.layer);
|
UE_LOG_ERROR("Can't add DrawCall to Layer {0} -> out of range\n", drawCall.layer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//Comprobamos si el objeto es visible.
|
// //Comprobamos si el objeto es visible.
|
||||||
//
|
// if(!IsObjectVisible(&drawCall.pos_rect))
|
||||||
//Generamos un rect que representa la pantalla.
|
// {
|
||||||
SDL_Rect screen{ 0, 0, screenSize.x, screenSize.y };
|
// //Si no es visible, no lo renderizaríamos.
|
||||||
//Comprobamos si hay intersecci�n entre ambos.
|
// return;
|
||||||
if (!SDL_HasIntersection(&screen, &drawCall.pos_rect))
|
// }
|
||||||
{
|
|
||||||
//UE_LOG_TRACE("Se omite el renderizado de un objeto al estar fuera de la c�mara.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
renderLayers.at(drawCall.layer).push_back(drawCall);
|
renderLayers.at(drawCall.layer).push_back(drawCall);
|
||||||
//rendererCounter++;
|
//rendererCounter++;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <glm/vec2.hpp>
|
#include <glm/vec2.hpp>
|
||||||
|
|
||||||
#include "Drawable.h"
|
#include "Drawable.h"
|
||||||
|
#include "Camera.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
// TODO:
|
// TODO:
|
||||||
@@ -80,12 +81,18 @@ namespace UE
|
|||||||
inline glm::ivec2 GetScreenSize() { return screenSize; }
|
inline glm::ivec2 GetScreenSize() { return screenSize; }
|
||||||
void SetScreenSize(int newWidth, int newHeight);
|
void SetScreenSize(int newWidth, int newHeight);
|
||||||
|
|
||||||
inline glm::ivec2 GetCamPosition() { return camPosition; }
|
//Permite cambiar el color de fondo.
|
||||||
void SetCamPosition(int posX, int posY);
|
void SetDrawingColor(SDL_Color& newColor);
|
||||||
|
|
||||||
|
//Cambia la cámara que se utiliza en el renderizado.
|
||||||
|
inline void SetCamera(Camera* newCam) { activeCam = newCam; }
|
||||||
|
inline Camera* GetCamera() { return activeCam; }
|
||||||
|
|
||||||
|
|
||||||
/* M�todos para transformar las coordenadas entre Screen y Wolrd. */
|
/* M�todos para transformar las coordenadas entre Screen y Wolrd. */
|
||||||
//WorldCoords = ScreenPos + CamPos -> ScreenPos = WorldCoords - CamPos;
|
//WorldCoords = ScreenPos + CamPos -> ScreenPos = WorldCoords - CamPos;
|
||||||
//Convierte coordenadas de mundo a la pantalla (en funci�n de la c�mara).
|
|
||||||
|
//Convierte coordenadas de mundo a la pantalla (en función de la cámara).
|
||||||
glm::ivec2 WorldToSreenCoords(glm::ivec2 worldCoord);
|
glm::ivec2 WorldToSreenCoords(glm::ivec2 worldCoord);
|
||||||
//Convierte coordenadas de la pantalla al mundo.
|
//Convierte coordenadas de la pantalla al mundo.
|
||||||
glm::ivec2 ScreenToWorldCoords(glm::ivec2 screenCoord);
|
glm::ivec2 ScreenToWorldCoords(glm::ivec2 screenCoord);
|
||||||
@@ -128,7 +135,11 @@ namespace UE
|
|||||||
//int screenHeight = 480;
|
//int screenHeight = 480;
|
||||||
|
|
||||||
glm::ivec2 screenSize{ 640,480 };
|
glm::ivec2 screenSize{ 640,480 };
|
||||||
glm::ivec2 camPosition{ 0,0 };
|
|
||||||
|
//glm::ivec2 camPosition{ 0,0 };
|
||||||
|
Camera* activeCam;
|
||||||
|
|
||||||
|
SDL_Rect _screenRect{ 0, 0, screenSize.x, screenSize.y};
|
||||||
|
|
||||||
|
|
||||||
//DEBUG
|
//DEBUG
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
#include "Logging/Logger.h"
|
#include "Logging/Logger.h"
|
||||||
|
|
||||||
#include "Render/Renderer.h"
|
#include "Render/Renderer.h"
|
||||||
|
#include "Render/Camera.h"
|
||||||
|
|
||||||
#include "Drawables/Sprite.h"
|
#include "Drawables/Sprite.h"
|
||||||
|
|
||||||
#include "Assets/AssetManager.h"
|
#include "Assets/AssetManager.h"
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Aquí habrá que definir los tipos custom para UberEngine.
|
||||||
|
Por ejemplo:
|
||||||
|
- glm::ivec2 -> UE_Vec2
|
||||||
|
|
||||||
|
*/
|
||||||
+10
-9
@@ -116,7 +116,7 @@ void Loop()
|
|||||||
}
|
}
|
||||||
if (eventHandler.type == SDL_WINDOWEVENT && eventHandler.window.event == SDL_WINDOWEVENT_RESIZED)
|
if (eventHandler.type == SDL_WINDOWEVENT && eventHandler.window.event == SDL_WINDOWEVENT_RESIZED)
|
||||||
{
|
{
|
||||||
//GAME_LOG_CRITICAL("Window Size chaged {0}x{1}", eventHandler.window.data1, eventHandler.window.data2);
|
GAME_LOG_INFO("Window Size chaged {0}x{1}", eventHandler.window.data1, eventHandler.window.data2);
|
||||||
UE_Renderer->SetScreenSize(eventHandler.window.data1, eventHandler.window.data2);
|
UE_Renderer->SetScreenSize(eventHandler.window.data1, eventHandler.window.data2);
|
||||||
}
|
}
|
||||||
if (eventHandler.type == SDL_KEYDOWN)
|
if (eventHandler.type == SDL_KEYDOWN)
|
||||||
@@ -146,29 +146,30 @@ void Loop()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
UE::Camera* cam = UE_Renderer->GetCamera();
|
||||||
if (keyStates[SDL_SCANCODE_W])
|
if (keyStates[SDL_SCANCODE_W])
|
||||||
{
|
{
|
||||||
glm::ivec2 camPos = UE_Renderer->GetCamPosition();
|
glm::ivec2 camPos = cam->GetCamPosition();
|
||||||
camPos.y -= 5;
|
camPos.y -= 5;
|
||||||
UE_Renderer->SetCamPosition(camPos.x, camPos.y);
|
cam->SetCamPosition(camPos.x, camPos.y);
|
||||||
}
|
}
|
||||||
if (keyStates[SDL_SCANCODE_S])
|
if (keyStates[SDL_SCANCODE_S])
|
||||||
{
|
{
|
||||||
glm::ivec2 camPos = UE_Renderer->GetCamPosition();
|
glm::ivec2 camPos = cam->GetCamPosition();
|
||||||
camPos.y += 5;
|
camPos.y += 5;
|
||||||
UE_Renderer->SetCamPosition(camPos.x, camPos.y);
|
cam->SetCamPosition(camPos.x, camPos.y);
|
||||||
}
|
}
|
||||||
if (keyStates[SDL_SCANCODE_D])
|
if (keyStates[SDL_SCANCODE_D])
|
||||||
{
|
{
|
||||||
glm::ivec2 camPos = UE_Renderer->GetCamPosition();
|
glm::ivec2 camPos = cam->GetCamPosition();
|
||||||
camPos.x += 5;
|
camPos.x += 5;
|
||||||
UE_Renderer->SetCamPosition(camPos.x, camPos.y);
|
cam->SetCamPosition(camPos.x, camPos.y);
|
||||||
}
|
}
|
||||||
if (keyStates[SDL_SCANCODE_A])
|
if (keyStates[SDL_SCANCODE_A])
|
||||||
{
|
{
|
||||||
glm::ivec2 camPos = UE_Renderer->GetCamPosition();
|
glm::ivec2 camPos = cam->GetCamPosition();
|
||||||
camPos.x -= 5;
|
camPos.x -= 5;
|
||||||
UE_Renderer->SetCamPosition(camPos.x, camPos.y);
|
cam->SetCamPosition(camPos.x, camPos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentScene->SceneUpdate();
|
currentScene->SceneUpdate();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
//#include "UberEngine.h"
|
//#include "UberEngine.h"
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Engine.h"
|
||||||
#include "Scene/Scene.h"
|
#include "Scene/Scene.h"
|
||||||
#include "Render/Renderer.h"
|
#include "Render/Renderer.h"
|
||||||
#include "Assets/AssetManager.h"
|
#include "Assets/AssetManager.h"
|
||||||
@@ -33,6 +34,13 @@ public:
|
|||||||
{
|
{
|
||||||
UE_LOG_INFO("Escena {0} ha sido cargada", _sceneName);
|
UE_LOG_INFO("Escena {0} ha sido cargada", _sceneName);
|
||||||
|
|
||||||
|
//Configuramos las cosas del Renderer.
|
||||||
|
//UE::Engine::GetRenderer()->SetCamPosition(150, 25);
|
||||||
|
|
||||||
|
SDL_Color newColor{40, 160, 195, 255};
|
||||||
|
UE::Engine::GetRenderer()->SetDrawingColor(newColor);
|
||||||
|
|
||||||
|
|
||||||
UE::AssetManager* as = UE::Engine::GetAssetManager();
|
UE::AssetManager* as = UE::Engine::GetAssetManager();
|
||||||
UE::Texture* test1Texture = as->getTexture("test1");
|
UE::Texture* test1Texture = as->getTexture("test1");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user