Skip to content

Camera2D unexpected results in simple case #2558

Open
@cdeil

Description

@cdeil

I'm trying to use Camera2D for the first time (x-ref #2557) and wanted to have a solar system with sun at world position (0, 0) and earth at world position (1, 0) etc, but then have it displayed on a larger window e.g. with 800 x 600 pixels.

I tried to create a Camera2D for this that does this world to screen pixel mapping like this:

>>> import arcade
>>> window = arcade.Window(width=800, height=600)
>>> window
Window=(width=800, height=600)
>>> rect = arcade.XYWH(x=0, y=0, width=8, height=6)
>>> camera = arcade.camera.Camera2D(projection=rect)
>>> camera.projection
Rect(left=-4.0, right=4.0, bottom=-3.0, top=3.0, width=8.0, height=6.0, x=0.0, y=0.0)
>>> camera.viewport
Rect(left=0, right=800, bottom=0, top=600, width=800, height=600, x=400.0, y=300.0)

My understanding from the docs is that camera.projection should be the Rect in world coordinates and camera.viewport the Rect in screen pixel coordinates. So far it looks good to me, what I expected.

However then when I try to use this to draw it doesn't do what I expected, to put the sun from world position (0, 0) to the screen center at pixel position (400, 300).

I see this is what project and unproject gives:

>>> camera.project((0, 0))
Vec2(x=-39600.0, y=-29700.0)
>>> camera.unproject((400, 300))
Vec3(x=400.0, y=300.0, z=0.0)
>>> camera.unproject((0, 0))
Vec3(x=396.0, y=297.0, z=0.0)

This is not what I expected.
Is this a bug?
Or probably I'm simply not grokking yet how cameras work?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions