大佬教程收集整理的这篇文章主要介绍了iphone – 使用OpenGL在iPad上绘制应用程序,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
那么我的应用程序工作,我可以写一些文本.但写作并不是很好,写作并不好玩.绘图路径不顺利,因为我从一个点到另一个点画一条线,是有角度的.而路径无处不在,宽度相同.我的想法是:当你写得很快时,线条比写入缓慢时更薄.它应该是一样的经验,像一个真正的笔写作.
如何使路径看起来更顺畅?如何根据写作速度来改变线条的宽度?
在这里你可以看到我的意思:
CGPoint drawBezier(CGPoint origin,CGPoint control,CGPoint desTination,int segments) { CGPoint vertices[segments/2]; CGPoint midPoint; glDisable(GL_TEXTURE_2D); float x,y; float t = 0.0; for(int i = 0; i < (segments/2); i++) { x = pow(1 - t,2) * origin.x + 2.0 * (1 - t) * t * control.x + t * t * desTination.x; y = pow(1 - t,2) * origin.y + 2.0 * (1 - t) * t * control.y + t * t * desTination.y; vertices[i] = CGPointMake(x,y); t += 1.0 / (segments); } //windowHeight is the height of you drawing canvas. midPoint = CGPointMake(x,windowHeight - y); glVertexPointer(2,GL_FLOAT,vertices); glDrawArrays(GL_POINTS,segments/2); return midPoint; }
这将以三点为基础.控制是中点,您需要返回.新的中点将与之前的不同.另外,如果你通过上面的代码,它只会画一半.下一个笔画将填写.这是必需的.我的代码调用这个函数(以上是在C中,这在Obj-C中):
//Invert the Y axis to conform the iPhone top-down approach invertedYBegCoord = self.bounds.size.height - [[currentstroke objectATindex:i] CGPointValue].y; invertedYEndCoord = self.bounds.size.height - [[currentstroke objectATindex:i+1] CGPointValue].y; invertedYThirdCoord = self.bounds.size.height - [[currentstroke objectATindex:i+2] CGPointValue].y; //figure our how many dots you need count = MAX(ceilf(sqrtf(([[currentstroke objectATindex:i+2] CGPointValue].x - [[currentstroke objectATindex:i] CGPointValue].X) * ([[currentstroke objectATindex:i+2] CGPointValue].x - [[currentstroke objectATindex:i] CGPointValue].X) + ((invertedYThirdCoord - invertedYBegCoord) * (invertedYThirdCoord - invertedYBegCoord))) / pointCount),1); newMidPoint = drawBezier(CGPointMake([[currentstroke objectATindex:i] CGPointValue].x,invertedYBegCoord),CGPointMake([[currentstroke objectATindex:i+1] CGPointValue].x,invertedYEndCoord),CGPointMake([[currentstroke objectATindex:i+2] CGPointValue].x,invertedYThirdCoord),count); int loc = [currentstroke count]-1; [currentstroke insertObject:[NSValue valueWithCGPoint:newMidPoint] aTindex:loc]; [currentstroke removeObjectATindex:loc-1];
该代码将基于倒置的iPad点获得中点,并将“控件”设置为当前点.
这将平滑边缘.现在关于线宽,你只需要找到该图的速度.找到你的线的长度是最简单的.这很容易使用组件数学.我没有任何代码,但here是来自物理网站的组件数学的底稿.或者你可以简单地划分(上面)计数一些数字,以找出你需要多大的行(计数使用组件数学).
我将点数据存储在名为currentstroke的数组中,以防不明显.
这应该是你需要的.
编辑:
要存储点,你应该使用touchesBegin和touchesEnd:
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { self.currentstroke = [NSMutableArray array]; CGPoint point = [ [touches anyObject] @R_696_5352@nInView:self]; [currentstroke addObject:[NSValue valueWithCGPoint:point]]; [self draw]; } - (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { CGPoint point = [ [touches anyObject] @R_696_5352@nInView:self]; [currentstroke addObject:[NSValue valueWithCGPoint:point]]; [self draw]; } - (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint point = [ [touches anyObject] @R_696_5352@nInView:self]; [currentstroke addObject:[NSValue valueWithCGPoint:point]]; [self draw]; }
这几乎是整个绘图应用程序.如果您使用GL_Paint,那么您已经在使用该系统构建的点精灵.
以上是大佬教程为你收集整理的iphone – 使用OpenGL在iPad上绘制应用程序全部内容,希望文章能够帮你解决iphone – 使用OpenGL在iPad上绘制应用程序所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。