Note: You must be registered in order to post a reply. To register, click here. Registration is FREE!
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;