C 为什么我的3d阵列是反向的?

C 为什么我的3d阵列是反向的?,c,arrays,tetris,C,Arrays,Tetris,我有一个3d数组,它存储在一个表示俄罗斯方块的结构中: typedef struct { int orientations[4][4][4]; dimension dimensions[4]; int i; int x; int y; }block; 方向由块的每个可能位置填充,尺寸是一个提供碰撞检查信息的结构: typedef struct { int left, right, bottom; }dimension; 每个方向和标注都应通过块的i值链接。由于某些原因,

我有一个3d数组,它存储在一个表示俄罗斯方块的结构中:

typedef struct
{
  int orientations[4][4][4];
  dimension dimensions[4];
  int i;
  int x;
  int y;
}block;
方向由块的每个可能位置填充,尺寸是一个提供碰撞检查信息的结构:

typedef struct 
{
int left, right, bottom;
}dimension;
每个方向和标注都应通过块的i值链接。由于某些原因,方向(而不是维度)似乎是相反的。有人知道这是为什么吗

以下是我如何为标注指定值:

block* shape = malloc(sizeof(block));
shape->dimensions[0].left = 0;
shape->dimensions[0].right = 3;
shape->dimensions[0].bottom = 1;
shape->dimensions[1].left = 2;
shape->dimensions[1].right = 2;
shape->dimensions[1].bottom = 3;
shape->dimensions[2].left = 0;
shape->dimensions[2].right = 3;
shape->dimensions[2].bottom = 2;
shape->dimensions[3].left = 1;
shape->dimensions[3].right = 1;
shape->dimensions[3].bottom = 3;
和方向:

int first[4][4] = {{0,0,0,0}, {2,2,2,2}, {0,0,0,0}, {0,0,0,0}};
int second[4][4] = {{0,0,2,0},{0,0,2,0},{0,0,2,0},{0,0,2,0}};
int third[4][4] = {{0,0,0,0},{0,0,0,0},{2,2,2,2},{0,0,0,0}};
int fourth[4][4] = {{0,2,0,0},{0,2,0,0},{0,2,0,0},{0,2,0,0}};
for (i = 0; i < 4; i++)
{
  for (j = 0; j < 4; j++)
  {
    shape->orientations[0][i][j] = first[i][j];
  }
}
for (i = 0; i < 4; i++)
{
  for (j = 0; j < 4; j++)
  {
    shape->orientations[1][i][j] = second[i][j];
  }
}
for (i = 0; i < 4; i++)
{
  for (j = 0; j < 4; j++)
  {
    shape->orientations[2][i][j] = third[i][j];
  }
}
for (i = 0; i < 4; i++)
{
  for (j = 0; j < 4; j++)
  {
    shape->orientations[3][i][j] = fourth[i][j];
  }
}

当我尝试访问形状->方向[3]时,它返回我先前设置为形状->方向[0]的值。任何帮助都将不胜感激,提前感谢。

原因是您的数组被索引为
[orientation][row][column]
,但您将其解释为
[orientation][x][y]
,而您应该将其解释为
[orientation][y][x]
。因此,您将得到一个x和y交换的模式,它看起来好像已旋转到不同的方向(实际上相当于旋转和翻转)。

很难理解您的代码片段和问题。例如,您的代码片段中根本没有当前的
,但您在问题中引用了它。我建议你用一个非常棒的感谢方式重新调整你的问题,我非常专注于找出一个数组是如何神奇地颠倒过来的,我甚至没有想到我犯了一个错误。
shape->orientations[current->i][i][j]