Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有三个变量(在 2D 字段上):
NumSquares, WindowSize (X 和 Y 都有这个值), Index
因此,例如,如果 NumSquares 为 8,WindowSize 为 256,Index 为 64;从这些变量中获取位置数据的算法看起来如何?
我假设“位置数据”是指网格上的坐标。index 表示使用公式计算的线性化数组中瓦片的位置X + width * Y。然后:
X + width * Y
X = index % width Y = index / width
我不确定您使用的是哪种语言,所以请确定: % 是模数, / 在这种情况下是整数除法。