开发者

How to make the matrix caculating faster?

Hello guys: I have to project many points before drawing them on a frame. my codes are blow:

-(Coordination*)xyWorldToDev:(Coordination*)pt isIphoneYAxis:(BOOL)isIphoneYAxis{
    CGPoint tmpPoint=CGPointApplyAffineTransform(CGPointMake(pt.x,pt.y),worldToDevMatrix);
    Coordination *resultPoint=[[[Coordination alloc]initWithXY:tmpPoint.x withY:(isIphoneYAxis)?(sscy-tmpPoint.y):tmpPoint.y]autorelease];
    return resultPoint; }

-(Coordination*)xyDevTo3D:(Coordination开发者_如何学编程*)cPt{
    double x=0.0,y=0.0;
    double divide=1+m_cView3DPara.v*cPt.y;
    x=(m_cView3DPara.a*cPt.x+m_cView3DPara.b*cPt.y+m_cView3DPara.e)/divide;
    y=(m_cView3DPara.d*cPt.y+m_cView3DPara.f)/divide;
    return [[[Coordination alloc]initWithXY:x withY:sscy-y]autorelease];
}
-(Coordination*)transformWorldTo3D:(Coordination*)pt{
    return [self xyDevTo3D:[self xyWorldToDev:pt isIphoneYAxis:NO]];
} 

Therefore,the method "-(Coordination*)transformWorldTo3D:(Coordination*)pt " is called hundreds times because projecting.

But i found it is very very SLOW while calling transformWorldTo3D! Is there another way to accelerate it? Or using another framework which could caculate the projecting value faster?


Object allocations are expensive (relative to arithmetic operations); and it appears that you're doing 2 alloc-init-autorelease sequences for every point.

My first suggestion would be to try to do some of this work with CGPoints and avoid the allocations.

(Actually, that's my second suggestion: my first is to profile the code to see where the time is being spent.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜