13
Ho codice:CGPoint a NSValue e invertire
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
è CGPoint, quindi ho bisogno in qualche modo di cambiare da CGPoint a NSValue per aggiungerlo alla NSMutableArray e dopo che riconvertirlo in CGPoint. Come potrebbe essere fatto?
ho cercato 'NSValue * cgpointObj = [NSValue valueWithPoint: loc];'. Ma come convertire nuovamente in CGPoint? – hockeyman
Qualcosa come 'CGPoint loc = cgpointObj.pointValue' dovrebbe funzionare. Ho aggiunto il codice aggiornato. – Stream
Penso che non aggiunga alcun valore. Se scrivo codice: | 'NSUInteger sum = vertici.count; NSLog (@ "count:% lu", sum); ' Scrive sempre tale somma = 0. Perché? Non sono stati aggiunti valori? Allora perché non sono stati aggiunti? – hockeyman