Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d141b77eaa | ||
|
|
132f24720e |
@@ -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>());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Renderer::CleanRenderer()
|
||||
@@ -91,6 +92,10 @@ namespace UE
|
||||
//Quiz�s deber�amos limpiar la cola y las Layers aqu� para eliminar residuos...
|
||||
//callCounter = 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()
|
||||
@@ -131,7 +136,6 @@ namespace UE
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Renderer::EndFrame()
|
||||
{
|
||||
//SDL_UpdateWindowSurface(window);
|
||||
@@ -160,11 +164,9 @@ namespace UE
|
||||
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;
|
||||
camPosition.y = posY;
|
||||
//UE_LOG_TRACE("Cam position chaged to: {0}x{1}", posX, posY);
|
||||
SDL_SetRenderDrawColor(main_Renderer, newColor.r, newColor.g, newColor.b, newColor.a);
|
||||
}
|
||||
|
||||
|
||||
@@ -172,7 +174,7 @@ namespace UE
|
||||
glm::ivec2 Renderer::WorldToSreenCoords(glm::ivec2 worldCoord)
|
||||
{
|
||||
//Convertimos las coordenas de WorldCoords a ScreenCoords relativas a la camPosition.
|
||||
glm::ivec2 fPos = worldCoord - camPosition;
|
||||
glm::ivec2 fPos = worldCoord - activeCam->GetCamPosition();
|
||||
|
||||
return fPos;
|
||||
}
|
||||
@@ -180,7 +182,7 @@ namespace UE
|
||||
glm::ivec2 Renderer::ScreenToWorldCoords(glm::ivec2 screenCoord)
|
||||
{
|
||||
//Convertimos las coordenas de ScreenCoords a WorldCoords relativas a la camPosition.
|
||||
glm::ivec2 fPos = screenCoord + camPosition;
|
||||
glm::ivec2 fPos = screenCoord + activeCam->GetCamPosition();
|
||||
|
||||
return fPos;
|
||||
}
|
||||
@@ -189,11 +191,8 @@ namespace UE
|
||||
//LAS COORDS QUE USAMOS EN LA COMPROBACI�N NO SON LAS ADECUADAS.
|
||||
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.
|
||||
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.");
|
||||
return false;
|
||||
@@ -220,16 +219,12 @@ namespace UE
|
||||
UE_LOG_ERROR("Can't add DrawCall to Layer {0} -> out of range\n", drawCall.layer);
|
||||
return;
|
||||
}
|
||||
//Comprobamos si el objeto es visible.
|
||||
//
|
||||
//Generamos un rect que representa la pantalla.
|
||||
SDL_Rect screen{ 0, 0, screenSize.x, screenSize.y };
|
||||
//Comprobamos si hay intersecci�n entre ambos.
|
||||
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;
|
||||
}
|
||||
// //Comprobamos si el objeto es visible.
|
||||
// if(!IsObjectVisible(&drawCall.pos_rect))
|
||||
// {
|
||||
// //Si no es visible, no lo renderizaríamos.
|
||||
// return;
|
||||
// }
|
||||
|
||||
renderLayers.at(drawCall.layer).push_back(drawCall);
|
||||
//rendererCounter++;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <glm/vec2.hpp>
|
||||
|
||||
#include "Drawable.h"
|
||||
#include "Camera.h"
|
||||
|
||||
//
|
||||
// TODO:
|
||||
@@ -80,12 +81,18 @@ namespace UE
|
||||
inline glm::ivec2 GetScreenSize() { return screenSize; }
|
||||
void SetScreenSize(int newWidth, int newHeight);
|
||||
|
||||
inline glm::ivec2 GetCamPosition() { return camPosition; }
|
||||
void SetCamPosition(int posX, int posY);
|
||||
//Permite cambiar el color de fondo.
|
||||
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. */
|
||||
//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);
|
||||
//Convierte coordenadas de la pantalla al mundo.
|
||||
glm::ivec2 ScreenToWorldCoords(glm::ivec2 screenCoord);
|
||||
@@ -128,7 +135,11 @@ namespace UE
|
||||
//int screenHeight = 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
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include "Logging/Logger.h"
|
||||
|
||||
#include "Render/Renderer.h"
|
||||
#include "Render/Camera.h"
|
||||
|
||||
#include "Drawables/Sprite.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)
|
||||
{
|
||||
//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);
|
||||
}
|
||||
if (eventHandler.type == SDL_KEYDOWN)
|
||||
@@ -146,29 +146,30 @@ void Loop()
|
||||
}
|
||||
|
||||
|
||||
UE::Camera* cam = UE_Renderer->GetCamera();
|
||||
if (keyStates[SDL_SCANCODE_W])
|
||||
{
|
||||
glm::ivec2 camPos = UE_Renderer->GetCamPosition();
|
||||
glm::ivec2 camPos = cam->GetCamPosition();
|
||||
camPos.y -= 5;
|
||||
UE_Renderer->SetCamPosition(camPos.x, camPos.y);
|
||||
cam->SetCamPosition(camPos.x, camPos.y);
|
||||
}
|
||||
if (keyStates[SDL_SCANCODE_S])
|
||||
{
|
||||
glm::ivec2 camPos = UE_Renderer->GetCamPosition();
|
||||
glm::ivec2 camPos = cam->GetCamPosition();
|
||||
camPos.y += 5;
|
||||
UE_Renderer->SetCamPosition(camPos.x, camPos.y);
|
||||
cam->SetCamPosition(camPos.x, camPos.y);
|
||||
}
|
||||
if (keyStates[SDL_SCANCODE_D])
|
||||
{
|
||||
glm::ivec2 camPos = UE_Renderer->GetCamPosition();
|
||||
glm::ivec2 camPos = cam->GetCamPosition();
|
||||
camPos.x += 5;
|
||||
UE_Renderer->SetCamPosition(camPos.x, camPos.y);
|
||||
cam->SetCamPosition(camPos.x, camPos.y);
|
||||
}
|
||||
if (keyStates[SDL_SCANCODE_A])
|
||||
{
|
||||
glm::ivec2 camPos = UE_Renderer->GetCamPosition();
|
||||
glm::ivec2 camPos = cam->GetCamPosition();
|
||||
camPos.x -= 5;
|
||||
UE_Renderer->SetCamPosition(camPos.x, camPos.y);
|
||||
cam->SetCamPosition(camPos.x, camPos.y);
|
||||
}
|
||||
|
||||
currentScene->SceneUpdate();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//#include "UberEngine.h"
|
||||
#pragma once
|
||||
|
||||
#include "Engine.h"
|
||||
#include "Scene/Scene.h"
|
||||
#include "Render/Renderer.h"
|
||||
#include "Assets/AssetManager.h"
|
||||
@@ -33,6 +34,13 @@ public:
|
||||
{
|
||||
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::Texture* test1Texture = as->getTexture("test1");
|
||||
|
||||
|
||||
+20
-38
@@ -13,6 +13,7 @@ workspace (""..GameName.."")
|
||||
project (""..GameName.."")
|
||||
kind "ConsoleApp"
|
||||
language "C++"
|
||||
cppdialect "C++17"
|
||||
|
||||
location ""
|
||||
|
||||
@@ -44,19 +45,35 @@ project (""..GameName.."")
|
||||
|
||||
}
|
||||
|
||||
cppdialect "C++17"
|
||||
|
||||
|
||||
filter "configurations:Debug"
|
||||
defines { "DEBUG" }
|
||||
symbols "On"
|
||||
postbuildcommands
|
||||
{
|
||||
"{COPYDIR} UberEngine/vendor/SDL/lib/x64/*.dll bin/Debug/",
|
||||
"{COPYDIR} UberEngine/vendor/SDL2_image/lib/x64/*.dll bin/Debug/",
|
||||
"{COPYDIR} UberEngine/vendor/SDL2_ttf/lib/x64/*.dll bin/Debug/",
|
||||
"{COPYDIR} resources/ bin/Debug/resources/"
|
||||
}
|
||||
|
||||
|
||||
filter "configurations:Release"
|
||||
defines { "NDEBUG" }
|
||||
optimize "On"
|
||||
postbuildcommands
|
||||
{
|
||||
"{COPYDIR} UberEngine/vendor/SDL/lib/x64/*.dll bin/Release/",
|
||||
"{COPYDIR} UberEngine/vendor/SDL2_image/lib/x64/*.dll bin/Release/",
|
||||
"{COPYDIR} UberEngine/vendor/SDL2_ttf/lib/x64/*.dll bin/Release/",
|
||||
"{COPYDIR} resources/ bin/Release/resources/"
|
||||
}
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
-- Opciones de Windows.
|
||||
-------------------------------------------------
|
||||
filter "system:windows"
|
||||
systemversion "latest"
|
||||
includedirs
|
||||
@@ -70,26 +87,10 @@ project (""..GameName.."")
|
||||
links { "opengl32.lib", "SDL2.lib", "SDL2main.lib", "SDL2_image.lib", "SDL2_ttf.lib" }
|
||||
defines { "SDL_VIDEO_DRIVER_WINDOWS" }
|
||||
|
||||
filter { "system:windows", "configurations:Debug" }
|
||||
postbuildcommands
|
||||
{
|
||||
"xcopy UberEngine\\vendor\\SDL\\lib\\x64\\*.dll bin\\Debug\\ /y /f",
|
||||
"xcopy UberEngine\\vendor\\SDL2_image\\lib\\x64\\*.dll bin\\Debug\\ /y /f",
|
||||
"xcopy UberEngine\\vendor\\SDL2_ttf\\lib\\x64\\*.dll bin\\Debug\\ /y /f",
|
||||
"xcopy resources\\ bin\\Debug\\resources\\ /e /y /f"
|
||||
}
|
||||
|
||||
|
||||
filter { "system:windows", "configurations:Release" }
|
||||
postbuildcommands
|
||||
{
|
||||
"xcopy UberEngine\\vendor\\SDL\\lib\\x64\\*.dll bin\\Release\\ /y /f",
|
||||
"xcopy UberEngine\\vendor\\SDL2_image\\lib\\x64\\*.dll bin\\Release\\ /y /f",
|
||||
"xcopy UberEngine\\vendor\\SDL2_ttf\\lib\\x64\\*.dll bin\\Release\\ /y /f",
|
||||
"xcopy resources\\ bin\\Release\\resources\\ /e /y /f"
|
||||
}
|
||||
|
||||
-------------------------------------------------
|
||||
-- Opciones de Linux.
|
||||
-------------------------------------------------
|
||||
filter "system:linux"
|
||||
includedirs
|
||||
{
|
||||
@@ -98,22 +99,3 @@ project (""..GameName.."")
|
||||
|
||||
links { "SDL2", "SDL2main", "SDL2_image", "SDL2_ttf", "dl", "GL", "GLEW"}
|
||||
defines { "SDL_VIDEO_DRIVER_X11" }
|
||||
|
||||
filter { "system:linux", "configurations:Debug" }
|
||||
postbuildcommands
|
||||
{
|
||||
-- "cp UberEngine/vendor/SDL/lib/x64/*.dll bin/Debug/",
|
||||
-- "cp UberEngine/vendor/SDL2_image/lib/x64/*.dll bin/Debug/",
|
||||
-- "cp UberEngine/vendor/SDL2_ttf/lib/x64/*.dll bin/Debug/",
|
||||
"cp -r resources/ bin/Debug/resources/"
|
||||
}
|
||||
|
||||
|
||||
filter { "system:linux", "configurations:Release" }
|
||||
postbuildcommands
|
||||
{
|
||||
-- "cp UberEngine/vendor/SDL/lib/x64/*.dll bin/Release/",
|
||||
-- "cp UberEngine/vendor/SDL2_image/lib/x64/*.dll bin/Release/",
|
||||
-- "cp UberEngine/vendor/SDL2_ttf/lib/x64/*.dll bin/Release/",
|
||||
"cp -r resources/ bin/Release/resources/"
|
||||
}
|
||||
Reference in New Issue
Block a user