我有一个 typedef 结构,如下所示:
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}}
};
如何遍历数据并添加到我的 NSMutableArray 而不会出现此错误?