在 GLPaint 中倒置绘制的 CGPoints

发布于 2024-10-06 12:02:57 字数 337 浏览 0 评论 0原文

我们正在将 GLPaint 示例用于新应用程序。 我们希望向用户演示绘制少量对象的方法。 我们看到苹果GLPaint有一个关于如何回放绘图点数据的示例。

因此,我们设法提供了我们自己的数据,除了它使数据颠倒的问题之外,它的效果很好。

当提供的点是针对该 -

alt text

时,它将绘制

alt text

有一个简单的解决方案吗?

谢谢,沙尼

We are using GLPaint example for a new app.
We wish to demonstrate the user the way to draw few objects.
We saw apple GLPaint has an example on how to playback data of points to drawings.

So we have managed to supply our own data and it works great beside the problem that it makes it upside down.

When the points supplied are for that -

alt text

it will draw that

alt text

Is there a simple solution for that?

Thanks, Shani

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不离久伴 2024-10-13 12:02:58

感谢吉纳明

,帮了很多忙。
听起来他们应该制作某种内置函数来翻转坐标。

我这么做了——
1.找到y坐标的最高点和最低点。
2. 将每个 y 点乘以 -1,然后添加最高点 + 最低点。所以图像绘制正确。

如果这对任何人有帮助的话,这就是代码。

   //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];

和绘图功能 -

    - (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];

}

我是编程新手,所以我希望我的代码没有问题。
有帮助

希望这对沙尼

thanks Ginamin

that helped a lot.
it sounds that they should make some kind of a build in function to flip the coordinates.

i did that -
1. find the highest and lowest point in the y coordinates.
2. multiply each y point in -1, and add the highest + lowest points to it. so the image is drawn correctly.

this is the code if it will help anyone.

   //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];

and the drawing function -

    - (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];

}

im new to programming, so i hope there are no problems in my code.
hope it will help

shani

分開簡單 2024-10-13 12:02:57

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

The iPhone coordinate system reads up to down, while openGL uses a cartesian system. So, all drawings in openGL will appear upside down on the iPhone. Try and flip your image upside down when rendering.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文