PDA

View Full Version : Mathy stretchy stuff


Yen
08-30-2006, 06:42 AM
Yeah, math (the stuff I need, anyway) isn't my strong point.

I have a 64x128 (4x8) image.
I want to rotate and stretch the image so it begins and point a and ends at point b.
I've played around with lots of tan, cos, and sin.. But I'm not getting anywhere.

Could someone help me out here? I had thought it would be easy, I'd just stretch the x to be equal to the distance and rotate it, but it turns out that stretchx and stretchy are applied after rotations.

contiga
08-30-2006, 06:03 PM
Yeah, math (the stuff I need, anyway) isn't my strong point.

I have a 64x128 (4x8) image.
I want to rotate and stretch the image so it begins and point a and ends at point b.
I've played around with lots of tan, cos, and sin.. But I'm not getting anywhere.

Could someone help me out here? I had thought it would be easy, I'd just stretch the x to be equal to the distance and rotate it, but it turns out that stretchx and stretchy are applied after rotations.

I could do anything with maths, it's just that I don't get what you want!

Angel_Light
08-30-2006, 06:43 PM
stretchx = imgx-pointa+(findimgwidth+pointb);

i dunno if that would work. :/

Tolnaftate2004
08-30-2006, 07:50 PM
This is theory, may not work. Pardon my bad drawing.

http://img48.imageshack.us/img48/5450/rotateandstretchqz6.png

1. Let's say you have you image and points set up like this (this method should work for any set-up). First, find the distance between A and B.

2. Get the slope of AB by using deltay/deltax. You can get the angle to rotate by using arctan( slope AB ) or getangle( deltax , deltay ). The slope of CD is -deltax/deltay or -1 / tan( angle ). (The dashed corner is not at A, I just suck at drawing on the computer.)

3. The green axis helps us draw an angle, theta. Theta = arctan( slope of CD ). We can then reposition the image's top point at A by:
making x = A.x - cos( theta ) * ||CD||
making y = A.y

Note: ||v|| is vector notation for magnitude. I'm using it as distance. ||CD|| is the image's height.

4. Finish up by stretching the image.
stretchx = ||AB|| * cos( rotationangle )
stretchy = ||AB|| * sin( rotationangle )

Note: it may be -sin() because of Graal's upside-down axes, but I'm not positive...

Voila!

Polo
08-30-2006, 08:29 PM
I could do anything with maths, it's just that I don't get what you want!
These were my thoughts exactly. ^^

Yen
08-30-2006, 09:23 PM
Tolnaftate2004: That's what I was trying at first, but it didn't work.. :/

Okay.
Let's say I have a rope image, which is 4x8 tiles.
I want to show the rope so it stretches to fit from point a to point b.

Polo
08-31-2006, 05:49 AM
Ah I understand now. If stretchx and stretchy are applied after the rotation though, then applying either of them will make the rope 'thicker' (give it more width along its direction) as well as making it longer. That would make the rope look... odd.

Instead, if I remember correctly, recent GS2 changes allow for textured polygons, which would allow you to do what you want pretty easily.

contiga
08-31-2006, 06:40 PM
Instead, if I remember correctly, recent GS2 changes allow for textured polygons, which would allow you to do what you want pretty easily.

I believe it was like;
with( findImg( 200)) {
polygon = { x1, y1, x2, y2, x3, y3, x4, y4};
image = "lol.png";
dimension = 2;
}

Not sure tho, look in Stefan's new features post, when V4.1 was released.