用于自动将输入缩放到表面分辨率的本机 PyGame 方法?

发布于 2024-11-25 23:33:00 字数 843 浏览 5 评论 0原文

这个问题与另一个问题相关。

在我的程序中(使用 pygame 在视频上绘制对象)我的世界有两种表示形式

  • 物理模型,我用它来进行模拟中涉及的所有计算,其中对象位于 1000x1000 米的表面上。
  • 我用来在屏幕上绘制的视觉对象,其中我的对象位于 100x100 像素的窗口中。

我想要实现的是能够将我的物理/真实坐标传递给我的pygame绘图函数(通常接受像素输入)。换句话说,我希望能够说:

Draw a 20m radius circle at coordinates (200m, 500m)

使用精确的 pygame 语法:

pygame.draw.circle(surface, (255,255,255), (200,500), 20)

并得到以像素(20,50)为中心的 2px 半径的圆。

请注意,这个问题是关于本机 pygame 方法来执行此操作,而不是某种实现该结果的解决方法(如果您想回答这个问题,您应该看看我已经提到)。

预先感谢您的时间和支持。

This question is related to this other one.

In my program (which uses pygame to draw objects on the video) I have two representation of my world:

  • A physical one that I use to make all the calculations involved in the simulation and in which objects are located on a 1000x1000 metres surface.
  • A visual one which I use to draw on the screen, in which my objects are located in a window measuring 100x100 pixels.

What I want to achieve is to be able to pass to my pygame drawing functions (which normally accept inputs in pixels) my physical/real-word coordinates. In other words, I would like to be able to say:

Draw a 20m radius circle at coordinates (200m, 500m)

using the precise pygame syntax:

pygame.draw.circle(surface, (255,255,255), (200,500), 20)

and get my circle of 2px radius at centred on pixels (20,50).

Please note that this question is about a native pygame way to do this, not some sort of workaround to achieve that result (if you want to answer that, you should take a look to the question I already mentioned) instead.

Thanks in advance for your time and support.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忆悲凉 2024-12-02 23:33:00

没有原生的 pygame 方法可以做到这一点。

您可能误解了 pygame 的功能。它不适用于绘制矢量对象。它用于将像素写入视频表面。

由于您有矢量对象,因此必须定义它们如何转换为像素。这样做并不是一种解决方法 - 这是您使用 pygame 的方式。

There is no native pygame way to do this.

You may be misunderstanding the function of pygame. It is not for drawing vector objects. It is for writing pixels into video surfaces.

Since you have vector objects, you must define how they will be converted into pixels. Doing this is not a workaround - it's how you are intended to use pygame.

无语# 2024-12-02 23:33:00

由于 PyGame 开发人员似乎不会在这里闲逛太多,我将问题带到了 Pygame 邮件列表,它起源于 怪物线程,这个问题已经引起了广泛的争论。

总结如下:

  • 目前还没有这样的功能。
  • 有兴趣实现它,或者至少尝试实现它......
  • 尽管无论如何,这都不是核心开发人员的优先事项
  • 剥猫皮的方法不止一种:
    • 缩放应该是双向的(输入坐标并读取它们)吗?
    • 如何处理没有粗细但应该可见的线条?
    • 如何处理图像边缘物体的可见性?应该以他们的哪一点作为参考来知道某个像素是否应该为他们点亮?
    • 以及更多内容(请参阅链接主题)。

Since it seems that PyGame developers do not hang around here too much, I brought the question to the Pygame mailing list where it originated a monster thread and the issue has been debated at large.

The summary would be:

  • At present there is not such a feature.
  • There is interest to implement it, or at least to try to implement it...
  • ...although is not a priority of the core devs in any way
  • There is more than one way to skin a cat:
    • should be the scaling happen both ways (inputting coordinates and reading them)?
    • how to deal with lines that have no thickness but that should be visible?
    • how to deal with visibility of objects at the edge of the image? which of their points should be taken as reference to know if a pixel should be lit or not for them?
    • and more (see linked thread).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文