Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Duke Leto

macrumors regular
Original poster
Mar 17, 2008
166
0
I am making an arrow that resizes itself and rotates so that it can point from one point to the user's finger. I have attempted this with CGAffineTransforms, but it seems that when I rotate or scale, the arrow also gets translated. I am trying to figure out a way to offset the translation. Any advice on an easier solution to the problem or an other help with transforms will be greatly appreciated.
 

Delirium39

macrumors regular
May 19, 2008
205
0
I am making an arrow that resizes itself and rotates so that it can point from one point to the user's finger. I have attempted this with CGAffineTransforms, but it seems that when I rotate or scale, the arrow also gets translated. I am trying to figure out a way to offset the translation. Any advice on an easier solution to the problem or an other help with transforms will be greatly appreciated.

I'm not sure I fully understand what is happening vs. what your goal is. Could you give more detail, and perhaps the transformation calls you're making?
 

Duke Leto

macrumors regular
Original poster
Mar 17, 2008
166
0
Okay. I have a physics simulation. In order for a user to create an initial velocity for an object, he would touch that object and drag out an arrow. I make a CGAffineTransform, then rotated it to the correct angle, then scaled it to meet the finger. However, the arrow gets skewed and translated. I think the problem may be with my initialization of the arrow's frame, but to be honest, I have never done anything like this before.
 

CommanderData

macrumors 6502
Dec 1, 2007
250
3
Okay. I have a physics simulation. In order for a user to create an initial velocity for an object, he would touch that object and drag out an arrow. I make a CGAffineTransform, then rotated it to the correct angle, then scaled it to meet the finger. However, the arrow gets skewed and translated. I think the problem may be with my initialization of the arrow's frame, but to be honest, I have never done anything like this before.

I guess it might depend on what's containing that arrow. I do some rotations of a CALayer (which is sized to fit it's view, in turn sized to take up most of the screen). When I rotate the layer, it rotates around the *upper left* corner. which means once I've rotated right 90 degrees the image is completely off the screen to the left. In my case I needed to translate it after rotation in order to re center the image in the view.

You also need to be careful applying transforms, order does matter a lot. In your description for example I think you'd want to *scale* the image first, then rotate (to avoid additional skew you're seeing by scaling second). Finally, you'll probably have to translate it to get the tail of your arrow back to where you want it (center of screen, or where ever you wanted the arrow's origin).
 

Delirium39

macrumors regular
May 19, 2008
205
0
Okay. I have a physics simulation. In order for a user to create an initial velocity for an object, he would touch that object and drag out an arrow. I make a CGAffineTransform, then rotated it to the correct angle, then scaled it to meet the finger. However, the arrow gets skewed and translated. I think the problem may be with my initialization of the arrow's frame, but to be honest, I have never done anything like this before.

It may be easier to scale first, and then rotate. Choosing the correct translation point is key. If you had a picture of your desired before and after, I'd probably be able to give a better answer. But generally, choose a point for the transform to work around, and then do a transform. Then, reposition the point based on the next transform you need to do.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.