1

In fact i want to draw an animated line from a given Tpoint coordinates to an other Tpoint on a Bitmap canvas for that i tried to read some open sources of OpenGl but task seems to be hard for my little competences in delphi i found this C++ source on github and its exactly what i want to do but under delphi 2009 if the line is animated it could be better for this personnal game prototype.

i tried some functions like -LineDDA- but its is very limited. i look for somthing like this:

 function Make_Projectile( canvas:tcanvas;Start,Target:Tpoint):boolean;   
 with canvas do  
 draw the animated_arc_line  form start to trget;

if we toutch target then result= true else false...
end;

I tried this piece of code:

procedure ArcByStartEndAngle(Canvas:TCanvas;P0, P1: TPoint; Angle: Double; NSeg: Integer);
var
  i: Integer;
  len, dx, dy, mx, my, px, py, t, cx, cy, p0x, p0y, an: Double;
  xx, yy: Integer;
begin
  mx := (P0.x + P1.x) / 2;
  my := (P0.y + P1.y) / 2;

  dx := (P1.x - P0.x) / 2;
  dy := (P1.y - P0.y) / 2;

  len := Math.Hypot(dx, dy);

  px := -dy / len;
  py := dx / len;

  if Angle = Pi then
    t := 0
  else
    t := len / Math.Tan(Angle / 2);

  cx := mx + px * t;
  cy := my + py * t;

  p0x := P0.x - cx;
  p0y := P0.y - cy;

  for i := 0 to NSeg + 1 do
  begin

   an := i * Angle / (NSeg + 1);
   xx := Round(cx + p0x * Cos(an) - p0y * Sin(an));
   yy := Round(cy + p0x * Sin(an) + p0y * Cos(an));
   Canvas.Pen.Color:=clBlue;
   Canvas.Brush.Color:=clRed;
   Canvas.Ellipse(xx - 3, yy - 3, xx + 4, yy + 4);
  end;
end;

and for these arguments it gives : this result

ArcByStartEndAngle(Form1.Image1.Canvas, Point(574,199),Point(62,202), Pi / 2, 8);

Please left a piece of code that can help or at list a translation of c code above for drawing the desired effect. the following screenshoot could give an idea : ScreenShoot enter image description here **

Ken White
  • 123,280
  • 14
  • 225
  • 444
Novicius
  • 31
  • 5
  • 1
    You have not specific question. Start to solve your problem step-by-step. The first: learn how to calculate trajectory of shoot with given start point, direction angle, bullet velocity, gravitation. – MBo Sep 28 '18 at 00:50
  • ok heer a starting point – Novicius Sep 28 '18 at 09:39
  • When accessing pixels on a tBitmap, you need to remember that the lines are addressed starting at the bottom. So the bottom line is Y=0, the line above that is Y=1 and so on. Try adding a line to set YY := aBitmap.Height-1 - YY; – David Dubois Sep 29 '18 at 17:20
  • eany code please? – Novicius Sep 29 '18 at 22:32

0 Answers0