图形:为什么坐标要浮动?
在许多图形库中,我看到坐标存储为浮点型或双精度型。我的问题是,为什么它们不应该存储为简单整数?你能得到什么更高的精度,在某些时候双精度仍然必须转换为整数(你不能从像素 45.8 开始在屏幕上传输图像,例如 :P )。
In many graphics libraries I've seen coordinates stored as floats
or doubles
. My question is, why should they not be stored as simple integers? What more precision can you get, the double is still going to have to be converted to an integer at some point (you can't blit an image on the screen starting from pixel 45.8, for example :P ).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
理论上,您可以从 45.8 开始复制图像。更多的是关于图形库使用的坐标系,以及它们如何管理图形的平移和转换等。通过向量移动图像是一个很好的例子......
即极坐标,或与相关的笛卡尔坐标系2D 坐标系...
例如,您希望球图形在 Windows 窗体周围随机弹跳。实现此目的的直观方法是:
首先,按照规范方式反弹
(dx = -dx 或 dy = -dy 取决于
碰撞)
然后将 dx 和 dy 转换为极坐标(theta 和 r)
将 theta 抖动少量(+ 或- 几度,根据您的喜好)
确保 θ 不会撞到您刚刚弹起的墙壁上关闭
将 theta 和 r 转换回 dx (x) 和 dy (y) 坐标(属于整数数据类型)。 .
了解漂移了吗?
可能会发现这个有用。
In theory, you can blit an image from 45.8. It's more about the coordinate system, in which the graphics library utilises, and how they manage translation and transformation of graphics etc. Moving an image via, Vectors is a good example...
i.e. Polar Coordinates, or the Cartesian coordinate system in relation with a 2D coordinate systems...
An example, you want a ball graphic to randomly bounce around a windows form. An intuitive way to accomplish this is:
first, bounce back the canonical way
(dx = -dx or dy = -dy depending on
the collision)
then convert the dx and dy to polar coordinates (theta and r)
jitter theta by a small amount (+ or - a few degrees, according to your taste)
make sure theta isn't heading into a wall that you just bounced off
convert theta and r back to dx (x) and dy (y) coordinates (which are of an integer data type)...
Get the drift?
May find this useful.