Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!batcomputer!cornell!vax5.cit.cornell.edu!nujy From: nujy@vax5.cit.cornell.edu Newsgroups: comp.graphics Subject: Re: Graphics -- projectile movement question Message-ID: <1991Mar27.193157.3660@vax5.cit.cornell.edu> Date: 27 Mar 91 19:31:57 EDT References: <1991Mar26.125744.623@stat.appstate.edu> <165722.22170@timbuk.cray. Distribution: comp Organization: CIT, Cornell University Lines: 51 In article <165722.22170@timbuk.cray.com>, kilian@cray.com (Alan Kilian) writes: > In article <1991Mar26.125744.623@stat.appstate.edu>, > c_s245010114@stat.appstate.edu writes: >> >> My question is, what's the best way to devise the arc it will follow using t >> pixels as the "bomb?" I will generate a random x-position at the bottom of t >> screen and a random angle of elevation. The "speed" will be a fixed value >> which I must mess around with. "Gravity" will also be a problem. >> >> BITNET: C_S245010114@appstate.bitnet Scott E. Schnegelberger >> INTERNET: C_S245010114@conrad.appstate.edu Appalachian State University > > > This is easy do do really fast. Here's how: > < psuedocode deleted > > > -- > -Alan Kilian kilian@cray.com 612.683.5499 > Cray Research, Inc. | If you were plowing a field what would > 655 F Lone Oak Drive | rather use? 2 strong oxen or 1024 chicke`ns > Eagan MN, 55121 | -Seymour Cray (On massivly paralell machine I thought you might be interested in more specific initial conditions. Using Alan's program set: xv=cos(angle)*speed yv=sin(angle)*speed Also, in case you're interested, you can make the "bomb" go through two points on the 'ground' (y=0) and reach a particular height (y=hmax) with the following equations for yv and gravity. x0 is the initial x coordinate, x2 is the final x coordinate, and hmax is the maximum altitude (which occurs at (x0+x2)/2. By the way, you can use any xv but it looks best when it is 1 because the "bomb" moves exactly one pixel horizontally at each step. Given: float xv, x0, x2, hmax h = -4.0*hmax / ((x0-x2) * (x0-x2)) /* only used for gravity and yv */ gravity = -2.0*xv*xv*h yv = ((x0-x2)*xv + xv*xv) * h x = x0 y = 0.0 Of course, you can optimize this for xv=1.0 Chris Schoeneman | "I was neat, clean, shaved, and sober, nujy@vax5.cit.cornell.edu | and I didn't care who knew it." | - Raymond Chandler