Problem with Grouping the rotated object.

2008-04-02 Thread Ghufran Ahamad
Hi All,

 

We are developing a kind of drawing application in Objective C using Cocoa
framework. We have several separate graphical objects, each having their own
position and rotation angle, are then grouped. As soon as we group the
objects the rotated object has got shift with their angle. This happen only
with rotated object. Below is the code snippet that we are using.

 

NSRect stRect = NSZeroRect;

NSArray *objTlGraphic = [[self document] graphics];

unsigned iIndex, nCount =[objTlGraphic count];

if(in_Group != 0)

{

   for(iIndex = 0; iIndex  nCount; iIndex ++)

   {

 if([[objTlGraphic objectAtIndex:i] GroupNO] == in_Group)

   {

 stRect =NSUnionRect(stRect,[[objTlGraphic objectAtIndex:
iIndex] bounds]);

   }   

   }

 }   

 

NSAffineTransform* xform = [NSAffineTransform transform];

[currentContext saveGraphicsState];

[NSBezierPath clipRect:drawingBounds];

NSPoint center = NSMakePoint(NSMidX(stRect), NSMidY(stRect));

[xform translateXBy:center.x yBy:center.y];

[xform rotateByDegrees:[curGraphic GetAngle]];

[xform translateXBy:-center.x yBy:-center.y];

[xform concat];

 

Any one tells me what I'm missing here.

 

Thanks,

Ghufran Ahmad

+91 - 9953130470

Skype ID: ghufran_khan81

AOL ID: gahmad81

 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Problem with Grouping the rotated object.

2008-04-02 Thread Jens Alfke
That's not enough code to go on — it's not showing all the drawing.  
Are you remembering to restore the saved graphics state after you  
finish drawing an object?


Also, if you could paste in the code without the extra blank lines, it  
would make it more readable.


—Jens

smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Re: Problem with Grouping the rotated object.

2008-04-02 Thread Quincey Morris


On Apr 2, 2008, at 04:00, Ghufran Ahamad wrote:


NSAffineTransform* xform = [NSAffineTransform transform];

[currentContext saveGraphicsState];

[NSBezierPath clipRect:drawingBounds];

NSPoint center = NSMakePoint(NSMidX(stRect), NSMidY(stRect));

[xform translateXBy:center.x yBy:center.y];

[xform rotateByDegrees:[curGraphic GetAngle]];

[xform translateXBy:-center.x yBy:-center.y];

[xform concat];


This looks kind of wrong. Mathematically, wouldn't you want:

[xform translateXBy:-center.x yBy:-center.y];
[xform rotateByDegrees:[curGraphic GetAngle]];
[xform translateXBy:center.x yBy:center.y];

?


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Problem with Grouping the rotated object.

2008-04-02 Thread Gregory Weston

Quincey Morris wrote:


On Apr 2, 2008, at 04:00, Ghufran Ahamad wrote:


[xform translateXBy:center.x yBy:center.y];
[xform rotateByDegrees:[curGraphic GetAngle]];
[xform translateXBy:-center.x yBy:-center.y];

This looks kind of wrong. Mathematically, wouldn't you want:

[xform translateXBy:-center.x yBy:-center.y];
[xform rotateByDegrees:[curGraphic GetAngle]];
[xform translateXBy:center.x yBy:center.y];

?


Nope. The way the matrix multiplication works, the effect is that the  
transformations take place in the opposite order of the way they  
appeared in code.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Problem with Grouping the rotated object

2008-04-02 Thread Gordon Apple
Let me explain how we are handling grouped objects.

We have only one basic type of draw object with a dictionary of
characteristics.  That gives a lot of flexibility.  We do not let objects
draw themselves.  Instead, we use a separate rendering object.  This results
in a clean object data model.  (Hopefully, this will help when we do
Windows.)

We use an object of type group to replace grouped objects.  When the
renderer encounters a group type object, it creates another temporary
renderer object that draws the group.  This allows recursion for groups.  Of
course, the group object has to compute it's own bounds, including internal
and total rotations.  So far, this works quite well and we haven't
encountered the problem you have had.


 Message: 4
 Date: Wed, 2 Apr 2008 16:30:42 +0530
 From: Ghufran Ahamad [EMAIL PROTECTED]
 Subject: Problem with Grouping the rotated object.
 To: cocoa-dev@lists.apple.com
 Message-ID: [EMAIL PROTECTED]
 Content-Type: text/plain;charset=us-ascii
 
 Hi All,
 
 
 
 We are developing a kind of drawing application in Objective C using Cocoa
 framework. We have several separate graphical objects, each having their own
 position and rotation angle, are then grouped. As soon as we group the
 objects the rotated object has got shift with their angle. This happen only
 with rotated object. Below is the code snippet that we are using.
 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]