findAngle tricks

Create fast, sprite powered games with Animation Engine, co-developed with DerBrill Software!

Moderators: heatherlaine, kevinmiller, robinmiller, malte

findAngle tricks

Postby malte » Mon Apr 10, 2006 3:07 pm

Hi,

another easy tutorial.

Create a stack with 2 regular polygon graphics. Name the graphics "triangle1" and "triangle2" Set the number of sides for each polygon to 3. In the messagebox:

set the constrainRectangular of grc "triangle1" to the rect of this card
set the constrainRectangular of grc "triangle1" to the rect of this card

Apply the following script to both graphics (mind linewraps):

Code: Select all
on mouseMove
  put findAngleX(the loc of grc "triangle1",the loc of grc "triangle2") into triangle1Rotation
  put findAngleX(the loc of grc "triangle2",the loc of grc "triangle1") into triangle2Rotation
  set the angle of grc "triangle1" to triangle1Rotation
  set the angle of grc "triangle2" to triangle2Rotation
  pass mouseMove
end mouseMove


Now switch to browse tool and start dragging the triangles.

Hope you like it.

All the best,

Malte
malte
 
Posts: 1096
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany

Re: findAngle tricks

Postby Surbhit29 » Sat Sep 01, 2012 6:22 am

HI Malte,
This was great. Can you tell me how can this be achieved for a freehand polygon having more than 3 sides inside the circle?
I tried it but it didn't work. Although when I used 3 side Polygon inside a circle, it gave desired result

Surbhit
Surbhit29
 
Posts: 80
Joined: Thu Aug 16, 2012 1:25 pm

Re: findAngle tricks

Postby malte » Sat Sep 01, 2012 8:57 am

Hi Surbhit,

the freehand polygon has no angle property I am afraid... You will have to use revRotatePoly for that. Make sure to store the original points of the polygon before you rotate it. then lock the screen, retore the original points and rotate from ther. It might be necessary to store the location too and reset it after rotation. The reason you need to do that is that revrotatePoly is prone to rounding errors and thus distorts the shape of your poly a little on each rotation.

Hth,

Malte
malte
 
Posts: 1096
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany

Re: findAngle tricks

Postby Surbhit29 » Tue Sep 04, 2012 9:08 am

Hi Malte,
I am using image now, but whenever I move the image its size changes according to its rotation. Is their anyway to avoid this change in size while we move the image?

Surbhit
Surbhit29
 
Posts: 80
Joined: Thu Aug 16, 2012 1:25 pm

Re: findAngle tricks

Postby sturgis » Tue Sep 04, 2012 2:39 pm

###EDIT: DOH yeah, has already been mentioned, but the 2nd part might still help.(using a snapshot instead)
1 thing you can do is store the original points of the poly then on each revrotatepoly a) lock the screen, b) set the points of the poly back to the original. C) rotate it to the new angle. d) unlock screen. This way you only have the rounding errors for a single rotate rather than the cumulative errors from multiple rotates.

It might be easier to take a snapshot of the poly, hide the poly, move the snapshot instead and rotate that, then when done moving lock screen, place the poly at the right location, remove the snapshot, show the poly and unlock the screen.

Surbhit29 wrote:Hi Malte,
I am using image now, but whenever I move the image its size changes according to its rotation. Is their anyway to avoid this change in size while we move the image?

Surbhit
sturgis
Livecode Opensource Backer
Livecode Opensource Backer
 
Posts: 1680
Joined: Sat Feb 28, 2009 11:49 pm

Re: findAngle tricks

Postby Surbhit29 » Tue Sep 04, 2012 2:50 pm

HI Sturgis,
I am not using Polygon. I am using an image instead. Also I am not using revRotatePoly command I am using the same commands mentioned by Malte in this topic. The problem is whenever I drag the object at one point it size decreases and at another point comes back to normal. I want the size of the image to remain same all the time whenever I drag it.

Surbhit
Surbhit29
 
Posts: 80
Joined: Thu Aug 16, 2012 1:25 pm

Re: findAngle tricks

Postby sturgis » Tue Sep 04, 2012 3:03 pm

Wow, I just didn't read very well. *sigh* To some extent as pointed out by malte the rounding problem sitll applies. A couple things that might help. Set the image quality to best, make sure you don't have size and position locked. If you do, then since the image is a rectangle shape, and the rect is locked as it rotates and the points of the image move around inside the rectangle container the image must shrink and grow to fit inside the box. (if that makes sense)

Of course i've misread every other single thing in this thread so you probably already have everything covered the best you can!
sturgis
Livecode Opensource Backer
Livecode Opensource Backer
 
Posts: 1680
Joined: Sat Feb 28, 2009 11:49 pm

Re: findAngle tricks

Postby sturgis » Tue Sep 04, 2012 3:21 pm

Here, this stack shows the difference between rotating a locked vs unlocked position. Border is turned on so you can see whats happening.
https://dl.dropbox.com/u/11957935/imagerotate.livecode

Left button is unlocked, right button sets the lockloc of the image to true. The buttons just goggle on and off, so if you click the left it will rotate, then clicking the right will stop it. Click the right again to start in the new mode. (any button click on either button will toggle animation on and off)
sturgis
Livecode Opensource Backer
Livecode Opensource Backer
 
Posts: 1680
Joined: Sat Feb 28, 2009 11:49 pm

Re: findAngle tricks

Postby Surbhit29 » Wed Sep 05, 2012 6:11 am

Thanks for the reply Sturgis.
But the file cannot be open in LiveCode. It is showing the error "Unable to open Stack"
Might be due to the format of LiveCode I am using.

Surbhit
Surbhit29
 
Posts: 80
Joined: Thu Aug 16, 2012 1:25 pm

Re: findAngle tricks

Postby Surbhit29 » Wed Sep 05, 2012 8:52 am

Also if I uncheck the "lock size and position" then I am unable to change the size of the image, don't know why :( . Only when I lock size and position of the image I am able to change it to desired size.
Surbhit29
 
Posts: 80
Joined: Thu Aug 16, 2012 1:25 pm

Re: findAngle tricks

Postby sturgis » Wed Sep 05, 2012 1:13 pm

Ah yep, I am using 5.5 and forgot to save it as a legacy format.

The reason you can't change the size of your image and make it "stick" when the lockloc is false is because the image has size data of its own. As soon as you do something that changes the location of the image in some way it reverts to its native size.

To get around this, size the image how you want it, then take a snapshot. The new image will have a native size that matches whatever dimensions you set the image at before the snapshot.

So, size the image how you want it to appear. then:
import snapshot from image "yourimage" --should create a new image that has the correct dimensions.

Then, since the image starts off the right size you can leave it unlocked and do what you want with it.

I just resaved the stack in the old format so it should be usable now.
sturgis
Livecode Opensource Backer
Livecode Opensource Backer
 
Posts: 1680
Joined: Sat Feb 28, 2009 11:49 pm

Re: findAngle tricks

Postby Surbhit29 » Thu Sep 06, 2012 6:39 am

Thanks a lot Sturgis.
That worked..
Surbhit29
 
Posts: 80
Joined: Thu Aug 16, 2012 1:25 pm


Return to Animation Engine

Who is online

Users browsing this forum: No registered users and 2 guests