次のような typedef 構造体があります。
typedef struct {
float Position[3];
float Color[4];
float TexCoord[2];
} Vertex;
Position、Color、および 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}}
};
このエラーを発生させずに、データを反復処理して NSMutableArray に追加するにはどうすればよいですか?