delphi - 如何在Delphi下在给定的bitmp上按照特定的XY坐标绘制弹丸
问题描述
事实上,我想在位图画布上从给定的 Tpoint 坐标到另一个 Tpoint 绘制一条动画线,因为我试图阅读 OpenGl 的一些开放源代码,但是对于我在 delphi 中的小能力来说,任务似乎很困难我找到了这个C++ 源在 github 上,这正是我想要做的,但在 delphi 2009 下,如果这条线是动画的,那么对于这个个人游戏原型来说可能会更好。
我尝试了一些像 -LineDDA- 这样的功能,但它非常有限。我寻找这样的东西:
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;
我试过这段代码:
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;
对于这些论点,它给出了:这个结果
ArcByStartEndAngle(Form1.Image1.Canvas, Point(574,199),Point(62,202), Pi / 2, 8);
请留下一段可以帮助的代码或在上面列出 c 代码的翻译以绘制所需的效果。以下屏幕截图可以提供一个想法:ScreenShoot enter image description here **
解决方案
推荐阅读
- python - 在 for 循环中过滤数据帧,为期两个月,增加 1 天
- delphi - ifassigned(MyObj) then 还是 if (MyObj <> nil) then 更好
- spring - Spring Data Mongo 从 1.9.6.RELEASE 升级到 2.0.0.RELEASE
- python - 这个 Python 函数是如何读取的?
- arrays - Vue.js + Element UI - 如何获取 v-model 数组 el-select
- django - Otree 保存静态结果页面
- linux - Cron 没有使用 initctl 命令
- windows - 在Windows中列出目录堆栈
- python - 如何使用子网 ID 以及我必须为子网使用的密钥在 azure for python 中创建网络安全组?
- firebase - 读取数据时触发功能的最佳方式。谷歌云函数