具有Magnant(C语言)抛物线路径的导弹。 [英] missiles with parabolic paths for Magnant (C language).

查看:95
本文介绍了具有Magnant(C语言)抛物线路径的导弹。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述






我正在尝试为导弹实施一些抛物线轨迹

在游戏中使用Magnant( http://www.insectwar.com )。这将使蚂蚁能够向其他蚂蚁射出更逼真的箭头。


现在蚂蚁正在射击指向点箭头,沿着一条箭射入>
直路(一条线)。


我想知道是否有人知道一个好的算法或一个好的公式来实现这个?<$
? br />

GPL代码目前是这样写的(stratagus引擎v1.18):


如果需要,我可以发送完整的.C。 br />

int dx;


int dy;


int xstep;


int ystep;


int i;


if(!(missile-gt; State& 1)){


//初始化


dy = missile-> DY-missile-> Y; ​​


ystep = 1;


if(dy< 0){


dy = -dy;

ystep = -1;


}


dx = missile-> DX-missile-> X;


xstep = 1;


if(dx< 0){


dx = -dx;


xstep = -1;


}


// FIXME:可以写得更好


if(missile-> Type-> Class == MissileClassWhirlwind


|| missile-> Type-> Class == MissileClassFlameShield){


//一定不能调用MissileNewHeading,也不能更改框架


}否则if (missile-> Type-> Class == MissileClassBlizzard){


missile-> SpriteFrame = 0;


}否则if (missile-> Type-> Class == MissileClassPointToPoint3Bounces){


missile-> DX- = xstep * TileSizeX / 2;


missile-> DY- = ystep * TileSizeY / 2;


}否则{


MissileNewHeadingFromXY(导弹,dx * xstep, dy * ystep);


}


if(dy == 0){//水平线


if(dx == 0){


返回1;


}


}否则if(dx == 0){//竖线


}否则if(dx< dy){//垂直方向步骤

导弹 - > D = dy-1;


dx + = dx;


dy + = dy;


}否则if(dx> dy){//在水平方向上执行


导弹 - > D = dx-1;


dx + = dx;


dy + = dy;


}


missile-> Dx = dx;


导弹 - > Dy = dy;


导弹 - > Xstep = xstep;


导弹 - > Ystep = ystep;


++ missile->州;


DebugLevel3Fn(" Init:%d,%d,%d,%d,=% d $ \\ n"


_C_ dx _C_ dy _C_ xstep _C_ ystep _C_ missile-> D);


返回0;


}否则{


//在途中


dx = missile-> Dx;


dy = missile-> Dy;


xstep = missile-> Xstep;


ystep = missile-> Ystep;


}


//


/ /移动导弹


//


if(dy == 0){//水平线

$ (b = b;(i = 0; I< missile->&型 - GT;速度; ++ i){


如果(导弹 - > X ==导弹 - > DX){


返回1;


}


missile-> X + = xstep;


}


返回0;


}


if(dx == 0){//垂直线


for(i = 0; i< missile-> Type-> Speed; ++ i){


if(missile-> Y ==导弹 - > DY){


返回1;


}


导弹 - > Y + = ystep;


}


返回0;


}




if(dx< dy){//垂直方向步骤


for(i = 0; i< ;导弹 - >类型 - >速度; ++ i){


if(导弹 - > Y ==导弹 - > DY){


返回1;


}


missile-> Y + = ystep;


导弹 - > D- = dx;


如果(导弹 - > D< 0){


导弹 - > D + = dy;


missile-> X + = xstep;


}


}


返回0;


}


if(dx> dy){//向水平方向迈步


for(i = 0; I< missile->&型 - GT;速度; ++ i){


如果(导弹 - > X ==导弹 - > DX){


返回1;


}


missile-> X + = xstep;


missile-> D- = dy;


如果(导弹 - > D< 0){


导弹 - > D + = dx;


导弹 - > Y + = ystep;


}


}


返回0;


}


//对角线


for(i = 0; i< missile-> Type-> Speed; ++ i){


if(missile-> Y == missile-> DY){


返回1;


}


missile-> X + = xstep;


导弹 - > Y + = ystep;


}


返回0;




Mohydine

-

发表于 http://dbforums.com


Hi,

I am trying to implement some parabolic trajectories for the missiles
used in the game Magnant (http://www.insectwar.com) . It would enable
Ants to shoot more realistic arrows to other ants.

Right now ants are shooting point to point arrows, that follow along a
straight path (a line).

I am wondering if anybody knows a good algorithm or a good formula for
implementing this?

The GPL code is currently written like this ( stratagus engine v1.18 ):

I can send the complete .C if necessary.

int dx;

int dy;

int xstep;

int ystep;

int i;

if( !(missile->State&1) ) {

// initialize

dy=missile->DY-missile->Y;

ystep=1;

if( dy<0 ) {

dy=-dy;

ystep=-1;

}

dx=missile->DX-missile->X;

xstep=1;

if( dx<0 ) {

dx=-dx;

xstep=-1;

}

// FIXME: could be better written

if( missile->Type->Class == MissileClassWhirlwind

|| missile->Type->Class == MissileClassFlameShield ) {

// must not call MissileNewHeading nor frame change

} else if( missile->Type->Class == MissileClassBlizzard ) {

missile->SpriteFrame = 0;

} else if( missile->Type->Class == MissileClassPointToPoint3Bounces ) {

missile->DX-=xstep*TileSizeX/2;

missile->DY-=ystep*TileSizeY/2;

} else {

MissileNewHeadingFromXY(missile,dx*xstep,dy*ystep) ;

}

if( dy==0 ) { // horizontal line

if( dx==0 ) {

return 1;

}

} else if( dx==0 ) { // vertical line

} else if( dx<dy ) { // step in vertical direction

missile->D=dy-1;

dx+=dx;

dy+=dy;

} else if( dx>dy ) { // step in horizontal direction

missile->D=dx-1;

dx+=dx;

dy+=dy;

}

missile->Dx=dx;

missile->Dy=dy;

missile->Xstep=xstep;

missile->Ystep=ystep;

++missile->State;

DebugLevel3Fn("Init: %d,%d, %d,%d, =%d\n"

_C_ dx _C_ dy _C_ xstep _C_ ystep _C_ missile->D);

return 0;

} else {

// on the way

dx=missile->Dx;

dy=missile->Dy;

xstep=missile->Xstep;

ystep=missile->Ystep;

}

//

// Move missile

//

if( dy==0 ) { // horizontal line

for( i=0; i<missile->Type->Speed; ++i ) {

if( missile->X==missile->DX ) {

return 1;

}

missile->X+=xstep;

}

return 0;

}

if( dx==0 ) { // vertical line

for( i=0; i<missile->Type->Speed; ++i ) {

if( missile->Y==missile->DY ) {

return 1;

}

missile->Y+=ystep;

}

return 0;

}



if( dx<dy ) { // step in vertical direction

for( i=0; i<missile->Type->Speed; ++i ) {

if( missile->Y==missile->DY ) {

return 1;

}

missile->Y+=ystep;

missile->D-=dx;

if( missile->D<0 ) {

missile->D+=dy;

missile->X+=xstep;

}

}

return 0;

}

if( dx>dy ) { // step in horizontal direction

for( i=0; i<missile->Type->Speed; ++i ) {

if( missile->X==missile->DX ) {

return 1;

}

missile->X+=xstep;

missile->D-=dy;

if( missile->D<0 ) {

missile->D+=dx;

missile->Y+=ystep;

}

}

return 0;

}

// diagonal line

for( i=0; i<missile->Type->Speed; ++i ) {

if( missile->Y==missile->DY ) {

return 1;

}

missile->X+=xstep;

missile->Y+=ystep;

}

return 0;



Mohydine
--
Posted via http://dbforums.com

推荐答案

mohydine< me ***** ****@dbforums.com>潦草地写道:
mohydine <me*********@dbforums.com> scribbled the following:

我正试图在游戏Magnant中使用导弹的一些抛物线轨迹( http://www.insectwar.com )。这将使蚂蚁能够向其他蚂蚁射击更逼真的箭。
现在蚂蚁正在射击点到箭头,沿着一条直线路径(一条直线)。
我想知道是否有人知道一个好的算法或一个好的公式来实现这个?
GPL代码目前是这样编写的(stratagus引擎v1.18):
Hi, I am trying to implement some parabolic trajectories for the missiles
used in the game Magnant (http://www.insectwar.com) . It would enable
Ants to shoot more realistic arrows to other ants. Right now ants are shooting point to point arrows, that follow along a
straight path (a line). I am wondering if anybody knows a good algorithm or a good formula for
implementing this? The GPL code is currently written like this ( stratagus engine v1.18 ):




(剪辑代码)


您发布的代码格式非常难以理解。请不要

在源代码行之间插入无偿的空白行(似乎

在代码的*每行*之间有2个空行),请,

拜托,请相当,学会缩进。非缩进源代码

在它超过Hello world后很快变得不可读

级别。


-

/ - Joona Palaste(pa*****@cc.helsinki.fi)----------------------- ---- \

| 飞翔的柠檬树中的金鸡王G ++ FR FW + M-#108 D + ADA N +++ |

| http://www.helsinki.fi/~palaste W ++ B OP + |

\ -----------------------------------------芬兰的规则! ------------ /

你可以选择你的朋友,你可以捡起你的鼻子,但你不能选择你的

亲戚。

- MAD杂志



(snip code)

The code you posted was in a very unreadable format. Please don''t
insert gratuitous blank lines between source code lines (there seemed
to be 2 blank lines between *every* line of your code), and please,
please, pretty please, learn to indent. Non-indented source code
becomes unreadable pretty soon after it advances past "Hello world"
level.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"You can pick your friends, you can pick your nose, but you can''t pick your
relatives."
- MAD Magazine


mohydine写道:
mohydine wrote:



我正在尝试为游戏Magnant中使用的导弹实现一些抛物线轨迹( http://www.insectwar.com )。这将使蚂蚁能够向其他蚂蚁射出更逼真的箭头。

现在蚂蚁正在射击指向点箭头,沿着直线路径(一条直线)。

我想知道是否有人知道一个好的算法或一个好的公式来实现这个?

Hi,

I am trying to implement some parabolic trajectories for the missiles
used in the game Magnant (http://www.insectwar.com) . It would enable
Ants to shoot more realistic arrows to other ants.

Right now ants are shooting point to point arrows, that follow along a
straight path (a line).

I am wondering if anybody knows a good algorithm or a good formula for
implementing this?




让箭头被解雇具有初始速度V,并且初始角度为水平的α弧度b b半径,在重力场中加速g。

它的初始向上速度是V sin alpha,它的横向速度V cos

alpha。如果你忽略了空气阻力,它会继续横着走,直到它b / b
击中某些东西。它的向上速度每秒减少g。


从那里拿走它。

-

Richard Heathfield: bi **** @ eton.powernet.co.uk

Usenet是一个奇怪的。地方" - Dennis M Ritchie,1999年7月29日。

C FAQ: http://www.eskimo.com/~scs/C-faq/top.html

K& R答案,C书等:< a rel =nofollowhref =http://users.powernet.co.uk/etontarget =_ blank> http://users.powernet.co.uk/eton



Let the arrow be fired with an initial velocity V, and an initial angle of
alpha radians from the horizontal, in a gravitational field accelerating
falling bodies at g.

Its initial upward velocity is V sin alpha, and its sideways velocity V cos
alpha. If you ignore air resistance, it''ll keep going sideways until it
hits something. Its upward velocity decreases by g each second.

Take it from there.
--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton


Richard Heathfield写道:
Richard Heathfield wrote:
mohydine写道:
mohydine wrote:


我正在尝试实施一些用于游戏Magnant的导弹的抛物线轨迹( http://www.insectwar.com )。这将使蚂蚁能够向其他蚂蚁射出更逼真的箭头。

现在蚂蚁正在射击指向点箭头,沿着直线路径(一条直线)。

我想知道是否有人知道一个好的算法或一个好的公式来实现这个?
Hi,

I am trying to implement some parabolic trajectories for the missiles
used in the game Magnant (http://www.insectwar.com) . It would enable
Ants to shoot more realistic arrows to other ants.

Right now ants are shooting point to point arrows, that follow along a
straight path (a line).

I am wondering if anybody knows a good algorithm or a good formula for
implementing this?



让箭头以初始速度发射V,以及从水平面开始的α弧度的初始角度,在重力场中加速g下降的物体。

它的初始向上速度是V sin alpha,其侧向速度V cos
alpha。如果你忽略了空气阻力,它会继续横着直到它击中某些东西。它的向上速度每秒减少g。

从那里拿走它。



Let the arrow be fired with an initial velocity V, and an initial angle of
alpha radians from the horizontal, in a gravitational field accelerating
falling bodies at g.

Its initial upward velocity is V sin alpha, and its sideways velocity V cos
alpha. If you ignore air resistance, it''ll keep going sideways until it
hits something. Its upward velocity decreases by g each second.

Take it from there.



Richard,


我'我想让自己引用你:这是一个很好的答案。这是关于主题的
,这是不正确的,并且它没有回答这个问题。 :-)


(联合国)幸运的是,你的回答是正确的。这只是偏离主题并且

并没有真正回答这个问题(在这种情况下,恕我直言,并不是所有这些都是有用的算法)。我想我们必须满足才能确定它只有好的价格。而不是精彩。


如果你像我一样喜欢物理,我就能明白你为什么能够这样做而不能抵抗炫耀你知道的东西的冲动,但你不觉得它

值得至少被标记为OT,更不用说交叉发布和fu2到

sci.physics.shooting-arrows或者什么?


好​​吧......别介意我...

-

Bertrand Mollinier Toublet

目前正在寻找旧金山湾区的就业
http://www.bmt.dnsalias.org/employment


Richard,

I''d like to allow myself to quote you: "This is a wonderful answer. It''s
off-topic, it''s incorrect, and it doesn''t answer the question." :-)

(Un)fortunately, your answer is correct enough. It is just off-topic and
doesn''t really answer the question (in that, IMHO, it is not all that
helpful for an algorithm). I guess we''ll have to settle to qualify it as
only "good" instead of wonderful.

If you liked physics as much as I did, I can understand why you could
not resist the urge to show off what you knew, but don''t you think it
deserved to at least be flagged as OT, let alone cross-posted and fu2 to
sci.physics.shooting-arrows or something ?

Ah well... don''t mind me...
--
Bertrand Mollinier Toublet
Currently looking for employment in the San Francisco Bay Area
http://www.bmt.dnsalias.org/employment


这篇关于具有Magnant(C语言)抛物线路径的导弹。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆