CGPoint to NSValue and reverse

后端 未结 1 453
忘掉有多难
忘掉有多难 2020-12-30 07:20

I have code:

NSMutableArray *vertices = [[NSMutableArray alloc] init];

//Getting mouse coordinates
loc = [self convertPoint: [event locationInWindow] fromVi         


        
相关标签:
1条回答
  • 2020-12-30 08:06

    The class NSValue has methods +[valueWithPoint:] and -[CGPointValue]? Is this what you are looking for?

    //Getting mouse coordinates
    NSMutableArray *vertices = [[NSMutableArray alloc] init];
    CGPoint location = [self convertPoint:event.locationInWindow fromView:self];
    NSValue *locationValue = [NSValue valueWithPoint:location];
    [vertices addObject:locationValue];
    
    //Converting from NSMutableArray to GLFloat to work with OpenGL
    NSUInteger count = vertices.count * 2; // * 2 for the two coordinates
    GLFloat GLVertices[] = (GLFloat *)malloc(count * sizeof(GLFloat));
    for (NSUInteger i = 0; i < count; i++) {
        NSValue *locationValue = [vertices objectAtIndex:i];
        CGPoint location = locationValue.CGPointValue;
        GLVertices[i] = location.x;
        GLVertices[i] = location.y;
    }
    
    0 讨论(0)
提交回复
热议问题