这是我的代码:
float SmoothNoise(float x, float y)
{
float fractX = x - (int)x;
float fractY = y - (int)y;
float x1 = ((int)x + noiseWidth) % noiseWidth;
float y1 = ((int)y + noiseHeight) % noiseHeight;
float x2 = ((int)x + noiseWidth - 1f) % noiseWidth;
float y2 = ((int)y + noiseHeight - 1f) % noiseHeight;
float value = 0f;
value += fractX * fractY * noise[x1, y1];
value += fractX * (1f - fractY) * noise[x1, y2];
value += (1f - fractX) * fractY * noise[x2, y1];
value += (1f - fractX) * (1f - fractY) * noise[x2, y2];
return value;
}
Run Code Online (Sandbox Code Playgroud)
错误发生在以下四行:
value += fractX * fractY * noise[x1, y1];
value += fractX * (1f - fractY) * noise[x1, y2];
value += (1f - fractX) * fractY * noise[x2, y1];
value += (1f - fractX) * (1f - fractY) * noise[x2, y2];
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我使用的唯一的int是明确的,所以我真的很困惑,它认为我试图隐式地将任何东西转换为int.
我应该提到这种类型的8个相同的错误,四个行中的每个错误都有2个.这令我难以置信.
noise是float [,]类型的数组