我正在努力理解 Chocolate Doom 如何分配其余弦表。注释解释说,为了计算余弦表,它在正弦表上进行了 PI/2 移位,但我不明白它是如何使用 C 完成的。
这是 Chocolate Doom 的原始源代码tables.h
和tables.c
#define FINEANGLES 8192
const fixed_t finesine[10240] =
{
25,75,125,175,226,276,326,376,
...
}
const fixed_t *finecosine = &finesine[FINEANGLES/4];
Run Code Online (Sandbox Code Playgroud)
这就是我试图在 Kotlin 中实现的目标
val fineSine: Array<Fixed_t> = arrayOf(25,75,125,175,226,276,326,376, ...)
val fineCosine: Array<Fixed_t> = arrayOf() // This is where I'm stuck
Run Code Online (Sandbox Code Playgroud)
一个完整的圆是 2pi 弧度。所以要抵消 pi/2,你需要走四分之一的路。因此,如果您FINEANGLES
在圆圈中有值,则可以偏移FINEANGLES/4
.
但是为了访问需要的FINEANGLES
值finecosine
finesine
至少需要FINEANGLES + FINEANGLES/4
值(假设没有逻辑可以环绕)。
一个简化的例子:
#define FINEANGLES 4
float finesine[] = {0, 1, 0, -1, 0};
float *finecosine = &finesine[FINEANGLES/4]; // {1, 0, -1, 0}
Run Code Online (Sandbox Code Playgroud)