【发布时间】:2012-03-04 05:20:51
【问题描述】:
我正在将此 SimplexNoise 模块从 C++ 移植到 C#,并且遇到了程序员从数组中检索值的方式的问题。他有如下内容:
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# 端口中:
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。这是合乎逻辑的,但这在 C++ 版本中怎么没有任何错误?我只知道 C++ 的基础知识,但据我所知,这是尝试用一维 int 数组分配一个整数变量,这没有任何意义。
有什么想法吗?
【问题讨论】:
-
dot()的 your 版本是什么样的?这就是问题所在。
标签: c# c++ arrays multidimensional-array porting