Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!unhd.unh.edu!jwn727 From: jwn727@unhd.unh.edu (Jason W Nyberg) Newsgroups: comp.graphics Subject: Re: Graphics -- projectile movement question Message-ID: <1991Apr2.052936.17294@unhd.unh.edu> Date: 2 Apr 91 05:29:36 GMT References: <1991Mar26.125744.623@stat.appstate.edu> Organization: University of New Hampshire Lines: 54 Here is a description of a phisical model for projectile motion that I have used for this kind of thing, as well as simulating orbits, atomic- particle interaction, and other fun stuff with little bits flying around. I'd like to say its mine, but it's pretty basic so that would be a tad presumptuous. (Though Macintosh would have no problem with it! :-)*0.5 ) each particle (in your case 1) has a coordinate, (x,y,z...) a velocity vector (vx,vy,vz,...), and an updated coordinate (nx,ny,nz...) here's a little algorithm: while (some_condition) { for_each_particle { // Part A display_particle(); // do your own... for_each_particle { // Part B nx=x+vx; ny=y+vy; nz=z+vz; ... // update coordinate } for_each_particle { // Part C erase_particle(); for_each_particle { // Part D x=nx; y=ny; z=nz;... vy=vy-G; // Part E: G=gravity constant (fudgeable) } Initialy (before the while) you set your coordinates and velocity vectors at the position and velocity you want, and enter the loop. You only need part D if your particles interact somehow (like a bunch of planets floating around) and yours don't (doesn't!) so you can get rid of nx,ny,nz, part D, and modify part B so that x+=vx, etc... If you want to do more funky stuff with the particles, Modify part E so that the velocity gets modified in other ways... EX: The 1/d^2 gravity law: Assign each particle a mass. for each particle, use every other particle's mass and coordinate to modify the selected particle's velocity (here you need the nx,ny,nz). Believe it or not, I wrote a (very!) simple version of this for my Sinclair ZX-81, with 1k mem. (my first neat program ever, on my first computer, in 1984-85.) I've got a water drop simulator using this stuff, running on X, if anyone is interested I'll mail it. (send me mail) (not very optimized, in C++ kindof) It lets drops of water hang from the "ceiling" and drop and splash and bounce off walls and all kinds of fun stuff. Its the drop's molecules that are simulated. Jason Nyberg jwn727@unhd.unh.edu or jwn@vandam.cs.unh.edu