移植C++;数组到C#数组 我将这个模式从C++移植到C语言,并遇到程序员从数组中翻新值的问题。他有如下几点:
simplexnoise.h移植C++;数组到C#数组 我将这个模式从C++移植到C语言,并遇到程序员从数组中翻新值的问题。他有如下几点:,c#,c++,arrays,multidimensional-array,porting,C#,C++,Arrays,Multidimensional Array,Porting,simplexnoise.h static const int grad3[12][3] = { {1,1,0}, {-1,1,0}, {1,-1,0}, {-1,-1,0}, {1,0,1}, {-1,0,1}, {1,0,-1}, {-1,0,-1}, {0,1,1}, {0,-1,1}, {0,1,-1}, {0,-1,-1} }; simplesxnoise.cpp n1 = t1 * t1 * dot(grad3[gi1], x1, y1); 在我的C#po
static const int grad3[12][3] = {
{1,1,0}, {-1,1,0}, {1,-1,0}, {-1,-1,0},
{1,0,1}, {-1,0,1}, {1,0,-1}, {-1,0,-1},
{0,1,1}, {0,-1,1}, {0,1,-1}, {0,-1,-1}
};
simplesxnoise.cpp
n1 = t1 * t1 * dot(grad3[gi1], x1, y1);
在我的C#port中:
SimplexNoise.cs
private static int[][] grad3 = new int[][] { new int[] {1,1,0}, new int[] {-1,1,0}, new int[] {1,-1,0}, new int[] {-1,-1,0},
new int[] {1,0,1}, new int[] {-1,0,1}, new int[] {1,0,-1}, new int[] {-1,0,-1},
new int[] {0,1,1}, new int[] {0,-1,1}, new int[] {0,1,-1}, new int[] {0,-1,-1}};
...
n1 = t1 * t1 * dot(grad3[gi1], x1, y1);
和我所得到的那行,不能从int [int ]转换成int。这是逻辑的,但是C++版本中没有错误吗?我只知道C++的基础知识,但从我知道的是,尝试用一个1D int数组来分配一个整型变量,而这只是没有任何意义。
有什么想法吗?这是因为根据您链接的源代码,
dot()
需要一个数组作为其第一个参数:
float dot(const int* g, const float x, const float y);
const int*g
表示“指向整数的指针”或“整数数组”。考虑到用法,签名暗示的是“整数数组”。因此,您需要更改C#dot()的签名
:
试试这个:
int grad3[,] = {
{1,1,0}, {-1,1,0}, {1,-1,0}, {-1,-1,0},
{1,0,1}, {-1,0,1}, {1,0,-1}, {-1,0,-1},
{0,1,1}, {0,-1,1}, {0,1,-1}, {0,-1,-1}
};
<>我建议你也阅读这个MSDN文章(虽然可能有点过时),把C++移植到C ^:这个答案似乎与问题无关,你的版本<代码> dot()/Cuth>看起来像什么?这就是问题所在。
int grad3[,] = {
{1,1,0}, {-1,1,0}, {1,-1,0}, {-1,-1,0},
{1,0,1}, {-1,0,1}, {1,0,-1}, {-1,0,-1},
{0,1,1}, {0,-1,1}, {0,1,-1}, {0,-1,-1}
};