Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Mathy stretchy stuff (https://forums.graalonline.com/forums/showthread.php?t=68449)

Yen 08-30-2006 06:42 AM

Mathy stretchy stuff
 
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

Quote:

Originally Posted by Yen
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/545...stretchqz6.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

Quote:

Originally Posted by contiga
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

1 Attachment(s)
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

Quote:

Originally Posted by Polo
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;
PHP Code:

withfindImg200)) {
  
polygon = { x1y1x2y2x3y3x4y4};
  
image "lol.png";
  
dimension 2;


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


All times are GMT +2. The time now is 06:24 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.