Advertise here

Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

CGPointApplyAffineTransform not correct

QuantumDojaQuantumDoja London/PeterboroughPosts: 643Registered Users @ @ @
Hi, I have the code below in an NSView, but when it runs, the rectangles co-ordinates are incorrect after running through the transformation...any ideas?
- (void)drawRect:(NSRect)dirtyRect
    [super drawRect:dirtyRect];
    NSRect newRect = NSMakeRect(50, 50, 100, 100);
    CATransform3D transform;
    transform = CATransform3DIdentity;
    transform.m34 = 1.0 / -500.0;
	transform = CATransform3DRotate(transform,radians(45.0),0,1,0 );

    CGAffineTransform affineTransform = CATransform3DGetAffineTransform(transform);
    NSPoint a = NSMakePoint(newRect.origin.x, newRect.origin.y);
    NSPoint b = NSMakePoint(newRect.origin.x, newRect.origin.y+newRect.size.height);
    NSPoint c = NSMakePoint(newRect.origin.x+newRect.size.width, newRect.origin.y+newRect.size.height);
    NSPoint d = NSMakePoint(newRect.origin.x+newRect.size.width, newRect.origin.y);

    CGPoint bl = CGPointApplyAffineTransform(a, affineTransform);
    CGPoint tl = CGPointApplyAffineTransform(b, affineTransform);
    CGPoint tr = CGPointApplyAffineTransform(c, affineTransform);
    CGPoint br = CGPointApplyAffineTransform(d, affineTransform);

    NSBezierPath *pathAf = [NSBezierPath bezierPath];
    [pathAf moveToPoint:bl];
    [pathAf lineToPoint:tl];
    [pathAf lineToPoint:tr];
    [pathAf lineToPoint:br];
    [pathAf lineToPoint:bl];
    [[NSColor blueColor] set];
    [pathAf setLineWidth:2.0];
    [pathAf stroke];
Sign In or Register to comment.