• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Affine Transform
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Affine Transform


  • Subject: Re: Affine Transform
  • From: Terry Heaford <email@hidden>
  • Date: Sun, 12 Feb 2006 20:05:32 +0000

Hi again,

Can someone point me to some simple explanation or tutorial of how the following work.

ScrollView/NSview/origin/bounds/frame/document in conjunction with NSaffineTransforms

with some solid and not to lengthy examples.


I have searched high and low and each time I reach a dead end. Either the explanation is incomplete, the code is incomplete or perhaps it is to difficult for an easy explanation.


Perhaps someone has cracked it and will not divulge the solution????

It's driving me nuts.

Perhaps learning this Cocoa beast was not a good idea.

Help!!!!!

Regards

Terry


On 12 Feb 2006, at 19:12, Terry Heaford wrote:

Greg,

Just deleted the lines as you suggested and it does not work.

Please don't forget I am not scaling it to fit a fixed view.

I need the full sized image rotated and placed into a view that is a subview of a scrollview.

Surely I need to adjust the size of the frame and/or bounds to reflect the size of the image when it has been rotated or are they adjusted automatically somehow (I am not sure).

Similarly i think I have to relocate the frame and/or bounds as the centre of the image is in a different location when it is rotated.


Regards

Terry


On 12 Feb 2006, at 18:23, Greg Herlihy wrote:

There's no need for a destination rect. Just draw the rotated image in its
current rect. In other words, delete the following lines of code and the
image will then rotate properly and in the right place:


    float    newImageWidth = w1 + w2;
    float    newImageHeight = h1 + h2;

NSRect newImageRect = NSMakeRect (0,0,newImageWidth,newImageHeight);
NSPoint imageOffset = NSMakePoint((newImageWidth - imageWidth)/2,
(newImageHeight - imageHeight)/2);


NSRect dstRect =
NSMakeRect(-imageOffset.x,- imageOffset.y,newImageWidth,newImageHeight);


   [self setFrame:dstRect];
   [self setBounds:dstRect];

Greg

On 2/12/06 7:32 AM, "Terry Heaford" <email@hidden> wrote:

degrees = 75;

//calculate new image size & rectangle from original image dims
plus degrees of rotation
imageWidth = [image size].width;
imageHeight = [image size].height;

imageRect = NSMakeRect(0,0,imageWidth,imageHeight);

//calculate via trig the new image size.
w1 = cos(degrees * pi/180) * imageWidth;
w2 = cos((90-degrees) * pi/180) * imageHeight;
h1 = sin(degrees * pi/180) * imageWidth;
h2 = sin((90-degrees) * pi/180) * imageHeight;
newImageWidth = w1 + w2;
newImageHeight = h1 + h2;

newImageRect = NSMakeRect(0,0,newImageWidth,newImageHeight);

//rotation point of image
centrePoint = NSMakePoint(NSMidX(imageRect), NSMidY(imageRect));

// offset to centre point of new image size.
imageOffset = NSMakePoint((newImageWidth - imageWidth)/2,
(newImageHeight - imageHeight)/2);

NSRect dstRect = NSMakeRect(-imageOffset.x,-
imageOffset.y,newImageWidth,newImageHeight);

[self setFrame:dstRect];
[self setBounds:dstRect];

[transform translateXBy:centrePoint.x yBy:centrePoint.y];
[transform rotateByDegrees:degrees];
[transform translateXBy:-centrePoint.x yBy:-centrePoint.y];
[transform concat];

[image drawInRect:imageRect fromRect:imageRect
operation:NSCompositeCopy fraction:opacity];



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40btopenworld.com


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Affine Transform
      • From: "John C. Randolph" <email@hidden>
References: 
 >Re: Affine Transform (From: Greg Herlihy <email@hidden>)
 >Re: Affine Transform (From: Terry Heaford <email@hidden>)

  • Prev by Date: Re: Finding all applications registered with launch services?
  • Next by Date: Re: Finding all applications registered with launch services?
  • Previous by thread: Re: Affine Transform
  • Next by thread: Re: Affine Transform
  • Index(es):
    • Date
    • Thread