0
我有一個typedef結構如參數如下:錯誤:發送「浮動[3]」到不兼容的類型「浮動」
typedef struct {
float Position[3];
float Color[4];
float TexCoord[2];
} Vertex;
我想通過對位置,顏色,以及TexCoord數據進行迭代:
+ (void)arrayConverter: (Vertex *) v
{
// Turn typeDef struct into seperate arrays
NSMutableArray *position = [[NSMutableArray alloc] init];
for (int p=0; p<(sizeof(v->Position)/sizeof(v)); p++) {
[position addObject:[NSNumber numberWithFloat:v[p].Position]]; // Error: Sending 'float[3]' to parameter of incompatible type 'float'
}
}
傳遞進來的數據:
Vertex Square_Vertices[] = {
// Front
{{0.5, -0.5, 1}, {0, 0, 0, 1}, {1, 0}},
{{0.5, 0.5, 1}, {0, 0, 0, 1}, {1, 1}},
{{-0.5, 0.5, 1}, {0, 0, 0, 1}, {0, 1}},
{{-0.5, -0.5, 1}, {0, 0, 0, 1}, {0, 0}},
// Back
{{0.5, 0.5, -1}, {0, 0, 0, 1}, {0, 1}},
{{-0.5, -0.5, -1}, {0, 0, 0, 1}, {1, 0}},
{{0.5, -0.5, -1}, {0, 0, 0, 1}, {0, 0}},
{{-0.5, 0.5, -1}, {0, 0, 0, 1}, {1, 1}},
// Left
{{-0.5, -0.5, 1}, {0, 0, 0, 1}, {1, 0}},
{{-0.5, 0.5, 1}, {0, 0, 0, 1}, {1, 1}},
{{-0.5, 0.5, -1}, {0, 0, 0, 1}, {0, 1}},
{{-0.5, -0.5, -1}, {0, 0, 0, 1}, {0, 0}},
// Right
{{0.5, -0.5, -1}, {0, 0, 0, 1}, {1, 0}},
{{0.5, 0.5, -1}, {0, 0, 0, 1}, {1, 1}},
{{0.5, 0.5, 1}, {0, 0, 0, 1}, {0, 1}},
{{0.5, -0.5, 1}, {0, 0, 0, 1}, {0, 0}},
// Top
{{0.5, 0.5, 1}, {0, 0, 0, 1}, {1, 0}},
{{0.5, 0.5, -1}, {0, 0, 0, 1}, {1, 1}},
{{-0.5, 0.5, -1}, {0, 0, 0, 1}, {0, 1}},
{{-0.5, 0.5, 1}, {0, 0, 0, 1}, {0, 0}},
// Bottom
{{0.5, -0.5, -1}, {0, 0, 0, 1}, {1, 0}},
{{0.5, -0.5, 1}, {0, 0, 0, 1}, {1, 1}},
{{-0.5, -0.5, 1}, {0, 0, 0, 1}, {0, 1}},
{{-0.5, -0.5, -1}, {0, 0, 0, 1}, {0, 0}}
};
我如何通過數據進行迭代,並添加到我的NSMutabl eArray沒有得到這個錯誤?
當我做到這一點我沒有得到我的全部傳遞 – user1585646
@ user1585646數據:你想添加一個頂點的位置或頂點數組的頂點? - 也許顯示如何調用該方法。 –
頂點數組 – user1585646