开发者

Problems accessing pre-defined array of floats in C++

I'm trying to make use of precalculated values by outputting them to a header file and then compiling them for use.

The precalculated values are cube co ordinates mapped onto a sphere and the data structure takes the form of:

typedef float heightMapCubeFace[5][5][3];

I am defining each face seperately like so:

    heightMapCubeFace face1 = {{{ -2.88675, -2.88675, -2.88675 }, { -3.38502, -3.38502, -1.44338 }, { -3.53553, -3.53553, 0 }, { -3.38502, -3.38502, 1.44338 }, { -2.88675, -2.88675, 2.88675}}, 
{{ -1.44338, -3.38502, -3.38502 }, { -1.69251, -4.38986, -1.69251 }, { -1.76777, -4.67707, 0 }, { -1.69251, -4.38986, 1.69251 }, { -1.44338, -3.38502, 3.38502}}, 
{{ 0, -3.53553, -3.53553 }, { 0, -4.67707, -1.76777 }, { 0, -5, 0 }, { 0, -4.67707, 1.76777 }, { 0, -3.53553, 3.53553}}, 
{{ 1.44338, -3.38502, -3.38502 }, { 1.69251, -4.38986, -1.69251 }, { 1.76777, -4.67707, 0 }, { 1.69251, -4.38986, 1.69251 }, { 1.44338, -3.38502, 3.38502}}, 
{{ 2.88675, -2.88675, -2.88675 }, { 3.38502, -3.38502, -1.44338 }, { 3.53553, -3.53553, 0 }, { 3.38502, -3.38502, 1.44338 }, { 2.88675, -2.88675, 2.88675}} 
}; 

and finally:

heightMapCubeFace * heightMapSaved[6] = {&face1, &face2, &face3, &face4, &face5, &face6};

Eventually the data structue will be bigger I hav ejust set it to 5x5 to make things easier at first.

The problem I am having is when I want to get the values back, something weird is happening and as a result access violations are occuring.

As shown in the following image

As you can see the assigned value does not match that of the data structure. Instead the value for index [0][0][0][1] is given the value of index [0][0][1][0]. here

I picked up on this because an unhaddled exception is thrown at a later stage (access violation), I think it is because 开发者_运维百科of this index problem but can't be certain.

I don't understand what is going on, am I dereferencing the pointer wrong?

Any help would be much appriciated, thanks.

Here is the code for that section:

    for(int i = 0; i < 6; i++)
    {    
        for(int j = 0; j < heightMapRes; j++)
        {
            for(int k = 0; k < heightMapRes; k++)
            {
                float xCoord =  *(heightMapSaved[i][j][k][0]);
                float yCoord =  *(heightMapSaved[i][j][k][1]);
                float zCoord =  *(heightMapSaved[i][j][k][2]);

                float newValue = myModule.GetValue( xCoord, yCoord, zCoord);

                heightMap.SetValue( j, k, newValue);
            }
        }
    }


layout is (heightMapSaved[6])[5][5][3] not (heightMapSaved[5][5][3][6])

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜