1

I am porting this SimplexNoise modual from C++ to C#, and have ran into issues with the way the programmer has retrevied values from arrays. He has something like as follows:

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);

And in my 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);

And for that line I get, cannot convert from int[] to int. Which is logical but how does this not have any errors in the C++ version? I only know the basics of C++ but from what I know that is an attempt to assign an integer variable with a 1D int array, which just doesn't make any sence.

Any ideas?

1
  • What does your version of dot() look like? That would be the issue. Commented Mar 4, 2012 at 10:53

2 Answers 2

2

This is because according to the source that you linked, dot() expects an array as its first argument:

float dot(const int* g, const float x, const float y);

const int* g means "a pointer to an integer", or "an integer array". Considering the usage, it is "an integer array" that the signature implies. Hence, you need to change the signature of your C# dot():

float dot(int g[], float x, float y);
Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

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}
               };

I suggest you also read this MSDN article (although it might be a little out of date) on porting C++ to C#: http://msdn.microsoft.com/en-us/magazine/cc301520.aspx

1 Comment

This answer seems irrelevant to the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.