Ios 在GLPaint中颠倒绘制的CG点

Ios 在GLPaint中颠倒绘制的CG点,ios,opengl-es,drawing,Ios,Opengl Es,Drawing,我们正在为一个新应用程序使用GLPaint示例。 我们希望向用户演示如何绘制一些对象。 我们看到apple GLPaint有一个关于如何将点的数据回放到图形的示例 因此,我们设法提供了我们自己的数据,除了让数据颠倒的问题外,它工作得很好 当所提供的点数用于以下目的时— 它会得出这样的结论 有没有简单的解决办法 谢谢,ShaniiPhone坐标系的读数从上到下,而openGL使用笛卡尔坐标系。因此,openGL中的所有图形都将在iPhone上颠倒显示。渲染时请尝试将图像翻转过来。谢谢Ginam

我们正在为一个新应用程序使用GLPaint示例。 我们希望向用户演示如何绘制一些对象。 我们看到apple GLPaint有一个关于如何将点的数据回放到图形的示例

因此,我们设法提供了我们自己的数据,除了让数据颠倒的问题外,它工作得很好

当所提供的点数用于以下目的时—

它会得出这样的结论

有没有简单的解决办法


谢谢,Shani

iPhone坐标系的读数从上到下,而openGL使用笛卡尔坐标系。因此,openGL中的所有图形都将在iPhone上颠倒显示。渲染时请尝试将图像翻转过来。

谢谢Ginamin

这帮了大忙。 听起来他们应该做一些内置函数来翻转坐标

是我干的- 1.在y坐标中找到最高点和最低点。 2.将-1中的每个y点相乘,并将最高点和最低点相加。因此,图像绘制正确

这是代码,如果它能帮助任何人

   //points array for example
points = [[NSArray alloc] initWithObjects:
              [NSValue valueWithCGPoint:CGPointMake(0, 0)],
              [NSValue valueWithCGPoint:CGPointMake(0, 90)],
              [NSValue valueWithCGPoint:CGPointMake(100, 90)],
              [NSValue valueWithCGPoint:CGPointMake(100, 0)],
              [NSValue valueWithCGPoint:CGPointMake(0, 0],
              nil];


     CGPoint point;
     NSValue *val;
     NSDictionary * dict;
     NSMutableArray *yPoints =[[NSMutableArray alloc] initWithCapacity:[points count]];

     for (int i=0; i<[points count]; ++i) {
     val = [points objectAtIndex:i];
     point = [val CGPointValue];
     dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:point.y] forKey:@"y"];
     [yPoints addObject:dict];

     }

             //sort the array by the y value
     NSSortDescriptor * yDescriptor =
     [[NSSortDescriptor alloc] initWithKey:@"y"
     ascending:YES];

     NSArray * descriptors =
     [NSArray arrayWithObjects:yDescriptor, nil];
     NSArray * sortedArray =
     [yPoints sortedArrayUsingDescriptors:descriptors];

             //get the first and last points from the sorted array

     yFactorHighest =  [[[sortedArray lastObject] objectForKey:@"y"] intValue];
     yFactorlowst =  [[[sortedArray objectAtIndex:0] objectForKey:@"y"] intValue];

     [yDescriptor release];
     [yPoints release];
//例如点数组
points=[[NSArray alloc]initWithObjects:
[NSValue valueWithCGPoint:CGPointMake(0,0)],
[NSValue VALUE WITH CGPOINT:CGPointMake(0,90)],
[NSValue VALUE WITH CGPOINT:CGPointMake(100,90)],
[NSValue VALUE WITH CGPOINT:CGPointMake(100,0)],
[NSValue valueWithCGPoint:CGPointMake(0,0],
零];
CGPoint点;
NSValue*val;
NSDictionary*dict;
NSMUTABLEARRY*yPoints=[[NSMUTABLEARRY alloc]initWithCapacity:[点数]];

对于(int i=0;i必须颠倒,还是如图所示颠倒和向后?
    - (void) playback:(NSString*)letter 
{

    NSUInteger pointsCount = [points count]-1;


    // Render the current path


    val1 = [points objectAtIndex:p];
    point1 = [val1 CGPointValue];
    point1.y=-(p1.y)+yFactorHighest+yFactorlowst;

    val2 = [points objectAtIndex:p+1];
    point2 = [val2 CGPointValue];
    point2.y=-(p2.y)+yFactorHighest+yFactorlowst;

    [self renderLineFromPoint:point1 toPoint:point2];
    p++;    

    if(p<pointsCount)
        [self performSelector:@selector(playback:) withObject:@"a" afterDelay:0.1];

}