PDA

View Full Version : Global Scaling?


Renderer10
11-24-2009, 01:35 AM
Ok, I've been struggling with a problem for about a week now, and finally decided to create an account here; hopefully I can provide as much help to others as I receive!

The problem: I need to be able to scale a rotated instance globally, not along the local x and y axis of the instance.

I realize that there is no such thing as "rotation", but that scaling and skewing are used to make an instance appear rotated. I haven't tried messing with the instance's transformation matrix yet, I really don't think that would help right now. I've been trying to use trig to scale locally and have it appear global, but no luck with that either. Nested movieclips won't work, simply because it would wreck havoc with any other transformations.

Any help with this is greatly appreciated, if anything sounds a bit vague, just ask to have it clarified!

-Renderer10

chups
11-24-2009, 07:44 AM
Put each instance inside it's own separate container sprite, then scale instances (not containers) and rotate containers (not instances).

Renderer10
11-24-2009, 05:24 PM
Thanks, but that won't cut it. I actually need to be able to scale an object along any angle, taking into account any previous scaling. I already have a system set up that takes care of the previous scaling, but how would I go about scaling along any angle? Anyone have a way to approach this with trig? I've been trying and trying... to no avail :(

creynders
11-24-2009, 09:38 PM
Chups is right though, have a movieclip to perform scaling on and inside it another to rotate (or vice versa)
'Taking into account any previous scaling' sounds like incrementing scaling, which is a matter of performing a correct calculation, the rotating (or not) of it's children doesn't make any difference.
Still, if you're quite certain this isn't what you want to do you'll need to explain it more visually I guess...

abeall
11-24-2009, 09:52 PM
So when you say global scale you mean you want to scale against a center point other than the object's local 0,0?

Renderer10
11-24-2009, 11:33 PM
@abeall, yes, but I've already taken care of that, by global, I mean no matter how the object is rotated, I want to be able to scale it along the stage's x and y axis, not the object's.

To everyone else:

Ok, well I'm working at developing an actual application, and I need to have an interface that provides intuitive controls for common transformations like dragging, rotating, and scaling. I have the scaling left to complete yet, before I can move on with this application. I've attached a swf of the last stable compilation, that is before I started with the scaling concept. You'll be able to see what I'm aiming for by checking this out (please note, I have made a few updates to fix minor issues in this, but that release isn't stable yet).

I want the user to be able to simply select objects, and have to ability to transform them however they want with no restrictions. So no matter what the rotation(actually scale and skew) or scale was before hand, I want them to be able to scale the object(s) in the direction desired.

So yes, the rotation of the children(if I would use that method) does matter. If you scale the parent instance, then rotate the child instance, it will constantly be distorted by the scaling of the parent instance.

Try this: Open Flash, draw a shape, and make it a symbol. Then scale that symbol along the x axis. Now double click that symbol and rotate the contents - you'll see how they are being affected by the scale. However, if you scale the symbol, then rotate the symbol(instead of rotating the contents), you'll see that the scale is preserved as the object is rotated. That's what I need to accomplish, hopefully that explanation helped.

I've been playing with the transformation matrix, and that allows you to scale an object globally, since your essentially bypassing the rotation. There is no rotation with the transform matrix, the rotation is stored directly as scale and skew information, meaning I can alter the scale on a global axis (scaleX and scaleY aren't pulled from the matrix, but are rather calculated by reverse-engineering the matrix info and using trig to make them "local", hence why I can't use them). However, with the matrix method, now the skew becomes a problem. When changing the scale on a "rotated" object, the skew stays the same, thus distorting the object. Does any of this make sense?

I've been working on the skew problem, but I haven't even come close to fixing it. The skew data in the transformation matrix is stored as the tangent of the skew angle(in radians). I've successfully extracted it with arctan, but I'm not sure what to do with the data...

I know this is rather complicated, but I haven't found ANY relevant information about the math involved in doing this, other than how matrices are used and how trig works(which I already understand). I was really hoping someone here could help... Thanks in advance!

For those interested in the attached file:

The only object you can add are the pentagons you see, however you can change the color using the text input. Click objects to select, hold shift or ctrl to select multiple objects. You can also drag a selection box, and if you hold shift when you let go, the objects will be added to the selection. Shift-clicking an object will also deselect.
Dragging objects is self-explanatory, though if you hold shift while dragging, you can snap the drag in 45 degree increments. Your selection will also snap to other objects while dragging, and you can also snap the selection back to it's original position by moving your mouse close to the "+" that appears. You can also use the arrow keys to "nudge" selected objects.
To rotate objects, turn on the transform handles (middle button), and hover your cursor outside the corner handles(just like in flash) to get a spin cursor, then click to rotate. It will automatically snap in 90 degree increments relative to the starting rotation, but if you hold shift, it will give you even more precision. You can drag the little white circle to change where the object(s) rotate around, and the circle will snap to each grab handle, as well as to the center of the transform box.
Right-clicking objects gives you depth controls, and you can even re-order multiple objects while preserving their order.
Auto-snapping can be toggled with the magnet button, though even with it off, shift-snapping still works.

Questions/comments/suggestions on the project so far are also welcomed!

-Renderer10

abeall
11-25-2009, 02:55 AM
Have you seen these?
http://www.senocular.com/?entry=372
http://www.senocular.com/flash/tutorials/transformmatrix/

Renderer10
11-25-2009, 03:07 AM
I've seen the second link, but not the first... I'll have to check it out. I want to use my code, as I'll have a full understanding of how it works, but I may be able to learn a thing or two from it though! Thanks a lot, though I'm still open to others ideas.

-Renderer10

creynders
11-25-2009, 07:13 AM
Try this: Open Flash, draw a shape, and make it a symbol. Then scale that symbol along the x axis. Now double click that symbol and rotate the contents - you'll see how they are being affected by the scale. However, if you scale the symbol, then rotate the symbol(instead of rotating the contents), you'll see that the scale is preserved as the object is rotated. That's what I need to accomplish, hopefully that explanation helped.
That's exactly what you get if you have separate movieclips to perform the separate transformations on: 1 for scaling, 1 for rotation. However, you have to scale the inner movieclip, not the outer one. (In other words, have a movieclip for rotating and inside it one for scaling)
To try it out create a shape, place it in a movieclip 'a' and place that in a movieclip 'b'
then add this code to the timeline:
b.a.scaleX = 1.5;
b.rotation = 125
You'll notice that it's scaled and rotated, but not skewed like it would be if you would scale 'b' and rotate 'a'

abeall
11-25-2009, 07:52 AM
Something else that comes to mind, if you aren't implementing skewing in the first place you don't have to build the transform tool around the transform matrix. DisplayObject's rotation property would make it very easy to maintain the relative transform which it seems like you are describing, but to me that's the opposite of "global" scale so I'm still not sure I understand.

Renderer10
11-25-2009, 07:59 PM
@abeall Your right, it is very easy to maintain the relative transform, but you're correct, it's not what I want, I want to have the global control over it. So that's where I'm beginning to explore the transform matrix further... though the skewing is messing me up.

@creynders:

Isn't your code
b.a.scaleX = 1.5;
b.rotation = 125
doing the same thing as this code would?
b.scaleX = 1.5;
b.rotation = 125

However, if you would switch the order of the commands of your code or mine, so that it rotated first, then scaled, you would see the same result; because it's still scaling on the local axis, which is now rotated along with the parent.

With your code, if you scale the inner instance, then rotate the outer instance, everything is fine and dandy. But what if, after you rotate the outer instance, you scale the inner instance some more? It will be relative to the outer instance. The inner instance is basically inheriting it's parent's transformation. Like I said earlier, the transformation matrix ignores the rotation, but scaling this way means I have to mess with skew, which is presenting a problem...

Thanks though, and I hope we can resolve this! ;)

-Renderer10

Renderer10
11-25-2009, 09:31 PM
Have you seen these?
http://www.senocular.com/?entry=372
http://www.senocular.com/flash/tutorials/transformmatrix/

The first link that I said I'd examine further doesn't have near the capabilities I'm looking for. It would also be hard to implement into my current system, as it doesn't support multiple selections or the snapping that I've already coded. Also, the method of scaling used is completely inaccurate, so I can't get any help from that, either. When scaling, it doesn't account for the skew at all, but rather just makes use of the scale info in the transform matrix. It also doesn't support rotated scaling - when you rotate an object and then scale it, it still scales according to the global x and y coordinates, when it should scale to it's relative coordinates. Only should it scale globally when you have multiple objects selected, which his system doesn't support, and even then, it should scale relative to the transform control's rotation, regardless of the different rotations each object has.

When I first started this project, I had no idea the scaling would be this complicated, but I know there has to be a way to achieve it... mathematically you can do just about anything! Getting this project to it's current point has been difficult, but I'm having trouble just wrapping my mind around the total scale of this problem! I'm already going to have to make some major changes to my current code to support the skewing involved in proper scaling, but I'll do that after I get the scaling to work - which isn't even close yet.

-Renderer10