How to orient an image to a point ?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- 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 ?
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
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
Re: How to orient an image to a point ?
Bonjour Jean-Marc,
sorry, what do you mean with "orienting an image to a point"?
Best
Klaus
sorry, what do you mean with "orienting an image to a point"?
Best
Klaus
-
- 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 ?
Hi Klaus,
I try to set the angle of an image according the mouseloc.
Jean-Marc
I try to set the angle of an image according the mouseloc.
Jean-Marc
https://alternatic.ch
Re: How to orient an image to a point ?
Ah, thanks, will search my archives!
-
- 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 ?
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:
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
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
Of course, the mouseH should be both set and scaled according to the loc and size of the image
Craig
-
- 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 ?
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
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
-
- 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 ?
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
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
-
- 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 ?
A bit wordy, but I left it as I made it. There is a fld 1 so I could see the angles.
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
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
So.
Hermann, what am I doing wrong?
Everybody, what is up with the image angle setting?
Craig
-
- 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 ?
Hi Craig,
this works for me
Kind regards
Bernd
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
Bernd
-
- 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 ?
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
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
-
- 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 ?
You may have a look at Rotation Control:
http://forums.livecode.com/viewtopic.ph ... 11#p155611
The central function is very simple:
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
-
- 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 ?
Hi Friends,
Thank a lot for help
Here is a stack use Hermann's "very simple central function"
Kind regards
Jean-Marc
Thank a lot for help
Here is a stack use Hermann's "very simple central function"
Kind regards
Jean-Marc
https://alternatic.ch