我一整天都在尝试让 Perlin 噪声生成正常工作,但在实现本教程中的伪代码时遇到了问题。
此问题的答案中显示了类似的代码。
问题是我不知道PerlinNoise_2D在 Hugo Elias 文章底部附近的函数中x 和 y 的输入值应该是什么(或者Total函数中的 i 和 j 值,如果您正在查看早期的 Stack溢出问题)。
我有一个 500 x 500 的数组,我将我的像素值存储到其中,所以起初我以为我只是应该为每个像素循环遍历PerlinNoise_2D(或Total)函数,但这导致我超出了我的数组立即,因为第一个函数调用有一个使用 index 的代码x - 1,这当然意味着当我给它我的第一个 x 索引(0,显然)时,它会中断。
该PerlinNoise_2D(或Total)函数肯定看起来像预期的切入点Perlin的类,它也像这将使我回来,我想要的值的功能,但我不能为我的生活找不出什么我应该传入,因为它绝对不是我的 x 和 y 像素数组索引。
有人知道我应该在这里传递什么吗?
我一直在用这种方式初始化我的一个结构而没有任何问题很长一段时间:
struct MyStruct
{
float firstArr[4];
float secondArr[4];
float thirdArr[4];
float fourthArr[4];
};
void Function()
{
std::vector<MyStruct> myArr;
myArr.push_back // This works fine
({
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }
});
}
Run Code Online (Sandbox Code Playgroud)
当我开始从Parent派生我的结构时,我不再能够这样做了.
struct Parent
{
// Nothing
};
struct MyStruct: Parent
{
float firstArr[4];
float secondArr[4];
float thirdArr[4];
float fourthArr[4];
};
void Function()
{
std::vector<MyStruct> myArr;
myArr.push_back // This gets compiler …Run Code Online (Sandbox Code Playgroud)