48 lines
1.1 KiB
C++
48 lines
1.1 KiB
C++
/*
|
|
* RenderContext.cpp
|
|
*
|
|
* Created on: Nov 30, 2016
|
|
* Author: tibi
|
|
*/
|
|
#include <base/Camera.h>
|
|
#include <base/GameObject.h>
|
|
#include <base/RenderContext.h>
|
|
#include <base/Transform.h>
|
|
|
|
namespace farmlands {
|
|
namespace base {
|
|
|
|
float RenderContext::xToWorld(float x)
|
|
{
|
|
float cellW = viewport.pixelsPerUnitX * m_camera->scale;
|
|
return (x - viewport.width / 2) / cellW + m_cameraTransform->x;
|
|
}
|
|
|
|
float RenderContext::yToWorld(float y)
|
|
{
|
|
float cellH = viewport.pixelsPerUnitY * m_camera->scale;
|
|
return (y - viewport.height / 2) / cellH + m_cameraTransform->y;
|
|
}
|
|
|
|
float RenderContext::xToScreen(float x)
|
|
{
|
|
float cellW = viewport.pixelsPerUnitX * m_camera->scale;
|
|
return (x - m_cameraTransform->x) * cellW + viewport.width / 2;
|
|
}
|
|
|
|
float RenderContext::yToScreen(float y)
|
|
{
|
|
float cellH = viewport.pixelsPerUnitY * m_camera->scale;
|
|
return (y - m_cameraTransform->y) * cellH + viewport.height / 2;
|
|
}
|
|
|
|
void RenderContext::setCamera(GameObject* camera)
|
|
{
|
|
m_cameraObj = camera;
|
|
m_cameraTransform = camera->component<Transform>();
|
|
m_camera = camera->component<Camera>();
|
|
}
|
|
|
|
}
|
|
}
|