Skip to content

Commit

Permalink
fixed?
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSapps committed Nov 8, 2016
1 parent e6a40b5 commit f40d30e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,9 @@ glm::vec2 CoordinateSpace::WorldToScreen(const glm::vec2& worldPos)
return ((mProjection * mView) * glm::vec4(worldPos, 1, 1)) * glm::vec4(mW / 2, -mH / 2, 1, 1) + glm::vec4(mW / 2, mH / 2, 0, 0);
}

// TODO: FIX ME
glm::vec2 CoordinateSpace::ScreenToWorld(const glm::vec2& screenPos)
{
return (glm::inverse(mProjection * mView) * glm::vec4(screenPos, 1, 1)) * glm::vec4(mW / 2, -mH / 2, 1, 1) + glm::vec4(mW / 2, mH / 2, 0, 0);
return glm::inverse(mProjection * mView) * ((glm::vec4(screenPos.x ,screenPos.y, 1, 1) - glm::vec4(mW / 2, mH / 2, 0, 0)) / glm::vec4(mW / 2, -mH / 2, 1, 1));
}

Renderer::Renderer(const char *fontPath)
Expand Down
7 changes: 3 additions & 4 deletions test/collision_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TestCoordinateSpace : public CoordinateSpace
using CoordinateSpace::UpdateCamera;
};

/*

TEST(CoordinateSpace, WorldToScreen_11)
{
TestCoordinateSpace coords(640, 480);
Expand All @@ -25,8 +25,8 @@ TEST(CoordinateSpace, WorldToScreen_11)
coords.UpdateCamera();

const glm::vec2 actual = coords.WorldToScreen({ 50.0f, 100.0f });
ASSERT_EQ(glm::round(50.0f), glm::round(actual.x));
ASSERT_EQ(glm::round(100.0f), glm::round(actual.y));
ASSERT_EQ(glm::round((640.0f/2)+50.0f), glm::round(actual.x));
ASSERT_EQ(glm::round((480.0f/2)+100.0f), glm::round(actual.y));
}


Expand All @@ -41,7 +41,6 @@ TEST(CoordinateSpace, ScreenToWorld_11)
ASSERT_EQ(glm::round(50.0f - 640/2), glm::round(actual.x));
ASSERT_EQ(glm::round(100.0f - 480/2), glm::round(actual.y));
}
*/

/*
TEST(CoordinateSpace, WorldToScreen_12)
Expand Down

0 comments on commit f40d30e

Please sign in to comment.