我们使用GLPaint示例来创建一个新的应用程序。 我们希望向用户演示如何绘制少量对象。 我们看到苹果GLPaint有一个关于如何播放点到绘图的数据的例子。在GLPaint中倒过来的CGPoints
因此,我们设法提供了我们自己的数据,并且它在使问题颠倒的问题旁边工作良好。
时提供的点为 -
会得出
是否有一个简单的解决方案?
感谢,沙尼
我们使用GLPaint示例来创建一个新的应用程序。 我们希望向用户演示如何绘制少量对象。 我们看到苹果GLPaint有一个关于如何播放点到绘图的数据的例子。在GLPaint中倒过来的CGPoints
因此,我们设法提供了我们自己的数据,并且它在使问题颠倒的问题旁边工作良好。
时提供的点为 -
会得出
是否有一个简单的解决方案?
感谢,沙尼
iPhone的坐标系中读取升转跌,而openGL的使用笛卡尔坐标系。所以,openGL中的所有图形都会在iPhone上颠倒。渲染时尝试颠倒翻转图像。
感谢Ginamin
帮了很多忙。 它听起来应该使某种构建功能来翻转坐标。
我做到了 - 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];
}
IM新的节目,所以我希望有我的代码没有问题。 希望这将有助于
SHANI
只是颠倒,或倒置和向后所描绘? – genpfault 2010-12-08 20:13:09