13
que tienen código:CGPoint a NSValue y revertir
NSMutableArray *vertices = [[NSMutableArray alloc] init];
//Getting mouse coordinates
loc = [self convertPoint: [event locationInWindow] fromView:self];
[vertices addObject:loc]; // Adding coordinates to NSMutableArray
//Converting from NSMutableArray to GLfloat to work with OpenGL
int count = [vertices count] * 2; // * 2 for the two coordinates of a loc object
GLFloat []glVertices = (GLFloat *)malloc(count * sizeof(GLFloat));
int currIndex = 0;
for (YourLocObject *loc in vertices) {
glVertices[currIndex++] = loc.x;
glVertices[currIndex++] = loc.y;
}
loc
es CGPoint, así que necesito alguna manera de cambiar de CGPoint a NSValue para añadirlo a NSMutableArray y después de que convertir de nuevo a CGPoint. ¿Cómo podría hacerse?
me trataron 'NSValue * cgpointObj = [NSValue valueWithPoint: loc]; '. Pero, ¿cómo convertir de nuevo a CGPoint? – hockeyman
Algo como 'CGPoint loc = cgpointObj.pointValue' debería funcionar. Agregué el código actualizado. – Stream
Creo que no agrega ningún valor. Si escribo código: | 'NSUInteger sum = vertices.count; NSLog (@ "count:% lu", sum); ' Siempre escribe que suma = 0. ¿Por qué? No se han agregado valores? Entonces, ¿por qué no se han agregado? – hockeyman