ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Calculate mouse move/path angle

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
egrobler Posted - May 18 2014 : 07:20:00
Hi Everyone,

I need to allow the user to move an object with the mouse in the direction of the mouse path and rotate the object (a car for example) accordingly.

I assume it would involve code that is something like:
angle := ArcTan2(deltaX,deltaY)*180.0 / PI;

Is there an existing function/code in the ImageEn library that calculates the direction of the mouse movement?

Any tips or suggestions will be helpful.

Thanks and regards
Eric

1   L A T E S T    R E P L I E S    (Newest First)
egrobler Posted - May 18 2014 : 17:06:17
This seems to work ok:

function CalculateMouseDirection(const aStartPos, aCurrentPos : TPoint) : Integer;
{
 North      ->   0
 North-East ->  45
 East       ->  90
 South      -> 180
 West       -> 270
 NorthWest  -> 315
 etc.
}
var xDelta,yDelta : Integer;
               ex : Extended;
begin
  xDelta := aCurrentPos.X-aStartPos.X;
  yDelta := aStartPos.Y-aCurrentPos.Y;
  ex :=  (ArcTan2(xDelta, yDelta)*180) / PI;
  if ex<0 then ex := ex+360;
  Result := Round(ex);
end;