Originally Posted by
robert83
But I have no idea why.... why do I Need to divide by 12.... I guess 12 should be calculated but from what ?
I would like a bit of Explanation... otherwise it is functioning perfectly.... I tried yesterday a complete Level... the Shooting was great....
I have no idea why you have to divide everything by 12. I guess the answer to this might be in your code that is using this information.
Also after preparing a quick test case for your approach (calculating angle of y mouse cursor position to a fixed point on the form) I'm getting wrong results even when I remove division by 12.
Code:
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var Direction: Single;
begin
Form1.Canvas.Brush.Color := clBtnFace;
Form1.Canvas.FillRect(Form1.ClientRect);
Form1.Canvas.Brush.Color := clBlack;
Form1.Canvas.MoveTo(Form1.Width div 2, Form1.Height div 2);
Form1.Canvas.LineTo(X,Y);
Direction :=(90-radtodeg(Math.arctan2(Form1.Height div 2 - Y, Form1.Width div 2 - X)));
Form1.Caption := Format('Direction = %n', [Direction]);
end;
It kinda works when mouse cursor is top left, bottom left or bottom right in relation to center position but when I move mouse cursor to top right position in relation to center position I get a negative value.
Also the angle is increasing in counter-clockwise direction but generally should do so in clockwise direction.
If I change my code to :
Code:
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var Direction: Single;
begin
Form1.Canvas.Brush.Color := clBtnFace;
Form1.Canvas.FillRect(Form1.ClientRect);
Form1.Canvas.Brush.Color := clBlack;
Form1.Canvas.MoveTo(Form1.Width div 2, Form1.Height div 2);
Form1.Canvas.LineTo(X,Y);
Direction :=(180-radtodeg(Math.arctan2(Form1.Height div 2 - Y, Form1.Width div 2 - X)));
Form1.Caption := Format('Direction = %n', [Direction]);
end;
I'm getting correct results and the angle is at 0 degrees when mouse cursor is directly left of the center point.
Bookmarks