missiles with parabolic paths for Magnant (C language).

M

mohydine

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
 
J

Joona I Palaste

mohydine said:
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 ):

(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 ([email protected]) ---------------------------\
| 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
 
R

Richard Heathfield

mohydine said:
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?

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.
 
B

Bertrand Mollinier Toublet

Richard said:
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,

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...
 
M

Mark McIntyre

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.

I am wondering if anybody knows a good algorithm or a good formula for
implementing this?
Virtually any A level maths student or physical science undergrad
wouild know an algo for this. In fact you could could look up the
formula for the parabola in pretty much any textbook. This is not a C
question.

<snip unreadable code>

When you're posting from web-based sources, you need to remember that
they almost certainly screw up your line endings. In your case, the
cut-paste resulted in every CR being translated into CRLF and every LF
_also_ being translated into CRLF.
 
R

Richard Heathfield

Bertrand Mollinier Toublet wrote:

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.

That's a relief.
It is just off-topic and
doesn't really answer the question (in that, IMHO, it is not all that
helpful for an algorithm).

It was intended to set the OP thinking. I /could/ have scribbled out the C
code for him, but that would have been "doing the homework", which I was
loathe to do. I was hoping to get him to realise that he's gonna have to
think about this.
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,

Oh, but I /did/ resist. I was all set to show him how to calculate time of
flight, height at a given time, maximising range whilst taking air
resistance into account, and heaven knows what else; but I managed to
prevent myself from doing this, on the grounds that it would teach him
little about projectiles but much about free lunches.
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 ?

It didn't occur to me, to be honest with you. Sorry about that.
 
N

nrk

Bertrand Mollinier Toublet wrote:

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...

Actually, it is a pretty reasonable answer (OT, but reasonable). All the OP
needs to do is recollect some high-school physics that says
s = ut + 0.5 at^2, s being distance, u being initial velocity, a being
acceleration and t being time, to simulate the x and y co-ords. of the
projectile.

-nrk.
 
M

mohydine

HI all,



First thanks for your answers. Unfortunately, this is not helping me a
lot.

As you suggested, I used simple parabolic formula, w/o using t, but
using a simple y=f(x).

x=x+step;

so y=yo+Cst*Sqrt[(x-xm)^2-(xo-xm)^2];

where (xo,yo) is starting point, xm is such that dy(xm) /dx=0.



I can get xm from

Xd=missile->DX; // impact of the missile X

Yd=missile->DY; // impact of the missile Y

Xo=missile->SourceX; //Source missile X

Yo=missile->SourceY; //Source missile Y

then

Xm=(-1/Cst*(Yd-Yo)*(Yd-Yo)+Xd*Xd-Xo*Xo)/(2*(Xd-Xo));



Since I know which parabola I am going to use(3 parameters known)



it works fine if yD(destination(impact of missible))= y0, but I can't
have it working when yd<yo. Even if I know my 3 parameters formula



any idea? Mathematically, I can't find the problem. So that is why I am
wondering if this has something to do with the C implementation or
something else.



Sorry for posting so much code.





Mohydine
 
R

Rajasekar Ramakrishnan

hi,
i am actually new to c.l.c
and i happen to read lots of mails in this newsgroup

and the very bad part of this newsgroup
is that ppl start to hurt a newbie, if the person asks for a very basic doubt

and that too, joona i palaste, if i could see ur mails i could only
know that you do not provide solutions
but mostly ask people to not send basic doubts to this comp.lang.c

i think the news readers need to be more professional, not all of them

please try to help a novice or if not, keep mum , so that he is not
discouraged

rajasekar.
 
J

Joona I Palaste

Rajasekar Ramakrishnan said:
This is a multi-part message in MIME format.
--------------8ABFF92D41955E546EDA90A4
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Don't do that.
hi,
i am actually new to c.l.c
and i happen to read lots of mails in this newsgroup
and the very bad part of this newsgroup
is that ppl start to hurt a newbie, if the person asks for a very basic doubt

Expressing criticism is not hurting. Did you see me insult or flame the
OP anywhere?
and that too, joona i palaste, if i could see ur mails i could only
know that you do not provide solutions
but mostly ask people to not send basic doubts to this comp.lang.c

Did you see me ask the OP not to send basic doubts anywhere? All I
said that he should reformat the code better.
i think the news readers need to be more professional, not all of them
please try to help a novice or if not, keep mum , so that he is not
discouraged

Which would mean that if the OP's code was bad, we shouldn't have to
tell him that, because it would hurt his feelings and scar him
emotionally. Thus he wouldn't know that his code could be better, and
go on writing bad code. That doesn't fit in with my vision of the world.

You seem to be mistaking telling someone "you are not the greatest
coder to walk this Earth (yet)" with telling him "you are a pathetic
loser". I was doing the former, not the latter.

PS. Please don't top-post. Thanks.

(v-card snipped)

--
/-- Joona Palaste ([email protected]) ---------------------------\
| 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 could take his life and..."
- Mirja Tolsa
 
D

Daniel Haude

On Thu, 18 Sep 2003 12:05:20 +0530,
in Msg. said:
This is a multi-part message in MIME format.

....which is something we don't like to see on Usenet.
and the very bad part of this newsgroup
is that ppl start to hurt a newbie, if the person asks for a very basic doubt
and that too, joona i palaste, if i could see ur mails i could only
know that you do not provide solutions
but mostly ask people to not send basic doubts to this comp.lang.c

He didn't do that. He merely told the OP that he'd like to see more
legible code, and quite politely so:
please try to help a novice or if not, keep mum , so that he is not
discouraged

If the novice can't deal with polite criticism, that's his problem. I
mean, what do you expect -- most novices obviously haven't read the Usenet
netiquette (like you, by the way), let alone the C FAQ.

It's rude to post into a C language Usenet group not having done your
homework and knowing zilch about either C or Usenet. It's not rude to
politely criticize such behavior.

And please lay off top-posting.

--Daniel
 
R

Randy Howard

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.

I snipped the code, because it was unreadable, as already pointed out
to you. If you really want it to be be accurate, I would recommend a
book called "Understanding Firearm Ballistics" by Robert A. Rinker.
The subject also applies pretty well to missiles, particularly if you
focus on the external ballistics section and disregard the internal stuff
like chamber pressure, twist rates, gyroscopic drift (assuming your
missile isn't spinning it won't have an effect), powders, primers,
temperature, etc. You probably can also disregard the terminal
ballistics portion (what happens to the object that gets hit by the
bullet). It includes drag, wind deflection and all the trajectory
info you can imagine.
 
L

Lawrence V. Cipriani

Virtually any A level maths student or physical science undergrad
wouild know an algo for this. In fact you could could look up the
formula for the parabola in pretty much any textbook. This is not a C
question.

Search for a free exterior ballistics program. It would be a lot more
realistic than a simple parabolic curve.
 
M

Mark McIntyre

Actually, it is a pretty reasonable answer (OT, but reasonable). All the OP
needs to do is recollect some high-school physics that says
s = ut + 0.5 at^2, s being distance, u being initial velocity, a being
acceleration and t being time, to simulate the x and y co-ords. of the
projectile.

Helps if you can remember how to rotate a frame of reference too, so
you can normalise the equations wrt the straight line joining the two
objects, even when they're in relative motion..
 
M

Mark McIntyre

and the very bad part of this newsgroup
is that ppl start to hurt a newbie, if the person asks for a very basic doubt

I realise that english is not your first language, but a douby is not
the same as a question.
and that too, joona i palaste, if i could see ur mails i could only
know that you do not provide solutions

but the purpose of this group is NOT to give people the answer to
their problem so that they don't havae to think, but to help them
solve it themselves. Nor is it to answer questions about mathematics.
 
D

Daniel Haude

On Thu, 18 Sep 2003 21:42:32 +0100,
in Msg. said:
I realise that english is not your first language, but a douby is not
the same as a question.

Damn right fifteen! Doubylessy.

--Daniel
 
W

WA Support

W

WA Support

Top posting was a direct response to the original question, and I
gave him useful information instead of all the anal ankle biting.

Murrah Boswell
 
A

Alex

<rearranged>

Top posting was a direct response to the original question, and I
gave him useful information instead of all the anal ankle biting.

I think that you are failing to grasp the concepts of top-posting
and bottom-posting. Take a look at this message, then take a look
at your previous message. If you still don't get it, I can't help
you.

Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top