Im trying to encode into a NSValue an multidimensional array of structs.
This is the struct:
typedef struct {
float Position[3];
float Color[4];
} Vertex;
const Vertex Vertices[] = {
// Front
{{1, -1, 0}, {1, 0, 0, 1}},
{{1, 1, 0}, {1, 0, 0, 1}},
(etc...)
I need to encode into a NSValue to store it in the object "Block".
This is what I do to store:
Block *newBlock = [[Block alloc] init];
newBlock.blockVertices = [NSValue value:&Vertices withObjCType:@encode(Vertex)];
And to get it back:
Vertex tempVertices[24];
[newBlock.blockVertices getValue:&tempVertices];
Everything seems to work fine, then I try to compare values like this:
for (int i = 0; i < 24; i++){
NSLog(@"%f = %f", Vertices[i].Position[0], tempVertices[i].Position[0]);
NSLog(@"%f = %f", Vertices[i].Position[1], tempVertices[i].Position[1]);
NSLog(@"%f = %f", Vertices[i].Position[2], tempVertices[i].Position[2]);
NSLog(@" ");
}
And I'm getting weird results, like: -1.000000 = -1.998905
where could be the problem? Any help would be appreciated.