/* * RenderContext.cpp * * Created on: Nov 30, 2016 * Author: tibi */ #include #include #include #include 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(); m_camera = camera->component(); } } }