如何在opengl中递归绘制十六进制地图?
我是 GL 的新手,想要创建一个平铺地图作为自我教程。我想创建一个小的(也许 7 个六角形宽/高)六角形地图。我的第一个想法是创建一个方法来绘制一个六角形,然后平移适当的偏移并放置新的六角形。但这似乎并不有效。有什么想法吗?另外,作为一个附带问题,我如何确定 MotionEvent 是否在给定十六进制的区域中?
I'm new to GL and wanted to create a tiled map as a self tuorial. I want to create a small (maybe 7 hexes wide / tall) hex map. My first thought was to just create a method to draw one hex and then just translate the appropriate offset and place the new hex. But this doesn't seem effcient. Any Idea's? Alos as a side question, how do I determine if a MotionEvent is with in the are of a given hex?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
丰富的十六进制网格信息。
Extensive hex grid information.
要确定 MotionEvent 是否在某个十六进制范围内,您必须将通过运动事件传入的坐标转换为 OpenGL 世界坐标。它就像单位转换一样,您知道屏幕从 0 - WIDTH 变化,而您的 GL 世界可以说从 -1 变化到 1。
(xCoord / (Width - 0)) * (1 - (-1)) = xCoordWorld
将给你从 0 到 2 的 xCoord,然后减去 1 得到 -1 到 1。
就六角形而言,我一直使用“艺术”六角形。用油漆画出六角形,然后渲染一堆带有该艺术品的正方形,快速轻松地将一个六角形换成另一个六角形。
To determine if a MotionEvent is within a certain hex you have to convert the coords passed in via the motion event to your OpenGL World coords. Its just like a unit conversion, you know the screen goes from 0 - WIDTH and your GL world lets say goes from -1 to 1.
(xCoord / (Width - 0)) * (1 - (-1)) = xCoordWorld
will give you the xCoord from 0 to 2, then subtract 1 to get it in -1 to 1.
As far as the hexes go I've always used 'art' hexes. Draw the hex out in paint then render a bunch of squares with that piece of art on them, fast and easy to swap a hex out for another hex.