How to orient an image to a point ?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

How to orient an image to a point ?

Post by jmburnod » Sun Oct 01, 2017 3:48 pm

Hi All,
I search a way to orient an image to a point.
Is there someone who have a function to get it ?
Thanks in advance
Best regards
Jean-Marc
https://alternatic.ch

Klaus
Posts: 13821
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to orient an image to a point ?

Post by Klaus » Sun Oct 01, 2017 3:52 pm

Bonjour Jean-Marc,

sorry, what do you mean with "orienting an image to a point"?


Best

Klaus

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: How to orient an image to a point ?

Post by jmburnod » Sun Oct 01, 2017 5:02 pm

Hi Klaus,
I try to set the angle of an image according the mouseloc.
Jean-Marc
https://alternatic.ch

Klaus
Posts: 13821
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to orient an image to a point ?

Post by Klaus » Sun Oct 01, 2017 5:08 pm

Ah, thanks, will search my archives! :D

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to orient an image to a point ?

Post by dunbarx » Mon Oct 02, 2017 1:13 pm

Jean-Marc.

Well, this seems to be what you want, though the image does not seem to like it much, and does not respond very well:

Code: Select all

on mousemove
   set the angle of me to  the mouseH
end mousemove
So I am thinking I do not understand what you need, and am also not sure why the rotation of the img seems so sluggish.

Of course, the mouseH should be both set and scaled according to the loc and size of the image

Craig

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: How to orient an image to a point ?

Post by jmburnod » Mon Oct 02, 2017 3:01 pm

Hi Craig,
Imagine you have an image of arrow on cd.
When I clic somewhere on the card, arrow rotate and point to the mouseloc direction
Best
Jean-Marc
https://alternatic.ch

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: How to orient an image to a point ?

Post by bn » Mon Oct 02, 2017 8:25 pm

Hi Jean-Marc,

if I understand correctly what you want have a look at this stack.

It is based on

-- from Jim James Hurley
-- http://runtime-revolution.278305.n4.nab ... l#a4276694

click on every control/image/button

I just saw what exactly you wanted. You would have to adapt the scripts.

Kind regards
Bernd
Attachments
setAngleOfImageToCenterOfMass.livecode.zip
(220.74 KiB) Downloaded 119 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to orient an image to a point ?

Post by dunbarx » Mon Oct 02, 2017 8:38 pm

A bit wordy, but I left it as I made it. There is a fld 1 so I could see the angles.

Code: Select all

on mouseMove
   if the optionKey is down then
      put the loc of img 1 into imgLoc
      put the mouseLoc into tMouseLoc
      
      if item 1 of tMouseLoc = item 1 of imgLoc then pass mouseMove
      put (item 2 of tMouseLoc - item 2 of imgLoc) / (item 1 of tMouseLoc - item 1 of imgLoc)  into vector
     
      put  atan(vector) into tAngle ; put tAngle * (360 / (2* pi)) && vector
       put  trunc(tAngle * (360 / (2* pi)))  into fld 1
      set the angle of img 1 to trunc(tAngle * (360 / 2* pi))
   end if
end mouseMove
The problem is it does not really work. The angles seem OK as one moves the cursor around (though one gets a problem at 90° and -90° if the "pass" line is not there), and there is still an issue with the quadrants, but within even a "working" quadrant, the image does not behave at all.

So.

Hermann, what am I doing wrong?

Everybody, what is up with the image angle setting?

Craig

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: How to orient an image to a point ?

Post by bn » Mon Oct 02, 2017 11:25 pm

Hi Craig,

this works for me

Code: Select all

on mouseMove
   if the optionKey is down then
      local tLocI, tMSL, tXI, tXm, tYI, tYm, dX, dY, tA2
      put the loc of image 1 into tLocI
      put the mouseloc into tMSL
      put item 1 of tLocI into tXI
      put item 1 of tMSL into tXm
      put item 2 of tLocI into tYI
      put item 2 of tMSL into tYm
      
      put (tXI - tXm) into dX
      put (tYI - tYm) into dY
      
      put ((round(abs (atan2(dY,dX)*180/pi-180))) + 270) mod 360 into tA2
      set the angle of image 1 to tA2
      put tA2 into field 1
   end if
end mouseMove
Kind regards
Bernd

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to orient an image to a point ?

Post by dunbarx » Mon Oct 02, 2017 11:50 pm

Lovely.

Mine was hasty and did not even take into consideration proper x and y values. In fact, if I ran the cursor at a perfect 45°, the image does not rotate at all.

Craig

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: How to orient an image to a point ?

Post by [-hh] » Tue Oct 03, 2017 9:47 am

You may have a look at Rotation Control:
http://forums.livecode.com/viewtopic.ph ... 11#p155611

The central function is very simple:

Code: Select all

-- x,y is the mouseLoc
-- x0,y0 is "the point", usually the loc of the image
-- The "90" determines that 0 degrees are at high noon.

constant pi180=57.29577951 -- 180/pi

function getAngle x,y,x0,y0
  put x - x0 into dX; put y - y0 into dY
  put max(1, sqrt(dX*dX+dY*dY)) into tR0
  if dY < 0 then return 90 - acos(dX/tR0)*pi180
  else return 90 + acos(dX/tR0)*pi180
end getAngle
shiftLock happens

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: How to orient an image to a point ?

Post by jmburnod » Tue Oct 03, 2017 11:11 am

Hi Friends,
Thank a lot for help
Here is a stack use Hermann's "very simple central function"
Kind regards
Jean-Marc
setImgAngleRegardingMouseLoc.zip
(1.55 KiB) Downloaded 107 times
https://alternatic.ch

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”