Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actually finish flipping the Y axis #275

Merged
merged 17 commits into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions ppb/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ppb.sprites import BaseSprite
from ppb.flags import DoNotRender


class Camera(BaseSprite):

image = DoNotRender
Expand Down Expand Up @@ -108,6 +109,4 @@ def translate_to_viewport(self, point: Vector) -> Vector:
"""
Converts a vector from in-game to pixel-based window coordinate space
"""
point = point.update(y=-point.y)
offset = (point - self.position) * self.pixel_ratio
return self.viewport_offset + offset
return Vector(point.x - self.frame_left, self.frame_top - point.y) * self.pixel_ratio
12 changes: 10 additions & 2 deletions tests/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,16 @@ def test_camera_translate_to_viewport():
assert cam.translate_to_viewport(Vector(0, 0)) == Vector(400, 300)
assert cam.translate_to_viewport(Vector(2, 1)) == Vector(560, 220)
cam.position = Vector(5, 5)
assert cam.translate_to_viewport(Vector(5, -5)) == Vector(400, 300)
assert cam.translate_to_viewport(Vector(7, -4)) == Vector(560, 220)
assert cam.translate_to_viewport(Vector(5, 5)) == Vector(400, 300)
assert cam.translate_to_viewport(Vector(7, 4)) == Vector(560, 380)


def test_camera_translate_to_viewport_2():
cam = Camera(viewport=(0, 0, 800, 600), pixel_ratio=1)
assert cam.position == Vector(0, 0)
assert cam.translate_to_viewport(Vector(0, 0)) == Vector(400, 300)
assert cam.translate_to_viewport(Vector(100, 100)) == Vector(500, 200)
assert cam.translate_to_viewport(Vector(-150, -500)) == Vector(250, 800)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to parameterize these tests? It seems like we have a lot of tests that are the same basic format?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do that when I find a spare moment.



def test_sprite_in_viewport():
Expand Down