简体   繁体   English

在内存中存储等轴测网格的最佳方法是什么?

[英]What is the best way to store an isometric grid in memory?

As a learning experience, I'm trying to make a turn based strategy game with Java+ObenGL, and I started with squares as terrain tiles. 作为一种学习经验,我正在尝试使用Java + ObenGL制作基于回合的策略游戏,我从正方形作为地形图开始。 Now I decided I'd rather have an isometric perspective and ever since I've been debating with myself over how to represent those tiles' coordinates in memory. 现在,我决定宁愿拥有等轴测透视图,而且自从我一直在与自己就如何在内存中表示这些图块的坐标进行辩论之后,我就决定了。

I see two alternatives: 我看到两种选择:

  1. A 2 dimensional array with X and Y axis going through the rhombus' vertices, resulting in a straight line on the rendered grid. X轴和Y轴穿过菱形顶点的二维数组,在渲染的网格上形成一条直线。

  2. A 2 dimensional array with X and Y axis following the sides of the cells (like what you'd do with a plain grid of rectangles), instead of the vertices, resulting in diagonal axis in the rendered grid. 一个X轴和Y轴跟随单元格侧面的二维数组(就像对矩形的普通网格所做的那样),而不是顶点,从而在渲染的网格中产生了对角轴。

What is usually done in these situations? 在这些情况下通常会做什么? Is one better than the other? 这个比那个好吗? Is there a better way I'm missing? 有什么更好的方法我想念吗?

The display mode and the data are two different things. 显示模式和数据是两个不同的东西。 A two dimensional array is fine if you have values in each cell. 如果每个单元格中都有值,则二维数组可以。 For the display find out which section of the grid is currently visible and access the array accordingly. 对于显示,找出网格的哪一部分当前可见,并相应地访问数组。 With a simple 2d topdown view you have a direct mapping between the grid and your array. 使用简单的2d俯视图,您可以在网格和阵列之间进行直接映射。 With another perspective you need to do some projection. 从另一个角度来看,您需要做一些预测。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM