Article View: rec.games.programmer
Article #992Re: Software Pinball Machine
From: gford
Date: Thu, 05 Nov 1992 14:44
Date: Thu, 05 Nov 1992 14:44
55 lines
2905 bytes
2905 bytes
>In article <Bx8H5G.Gt7@cs.vu.nl>, mgemmel@cs.vu.nl (Martin Gemmel) writes: >> Writing a pinball simulator is what I've been thinking of for a long >> time, too. >> Could be fun. >> f110019@hamlet.ucdavis.edu (Julian Burger) writes: >> > } In other words, you would have a pinball-table description language which > } would be parsed and a table created from it. > A good idea, I think >> The idea sounds good, but for the moment the most important question >> is just how to calculate ball motions and the effects of the various >> objects on the ball(s). The ball is moving on a sloping table, (slope in y direction). The x component of the velocity remains constant. And the y component vy(t) = vy(t-1) + a where a is a fraction of gravitational acceleration. Two approaches to ball motion: i) calculate the trajectories as you go, using the above equation. ii) precalculate the trajectories (I'm not sure how to do this, but..) Bresenham has a fast incremental algorithm for drawing an ellipse that will step one pixel at a time. This may be faster than method (i) and guarantees a reasonably smooth trajectory. The ellipse would be a suitable approximation to the parabolic path of an object moving in a uniform gravitational field, I don't know what the best way to initialise the algorithm would be, but I suspect a table lookup would save calculation. Note that, although the shape of the trajectory is pre-calculated, the actual position is calculated incrementally, so there is no problem with collision detection. You could handle collisions, by treating each object as a collection of surfaces of unit size, give each surface a position and an angle, and then when the position of the ball coincides with that of an object then calculate the deflected velocity of the ball.(I'm not sure about the trig formulae but I think it looks like: Vy(t+1) = Vy(t)cos(S + 180) + Vx(t)sin(S) Vx(t+1) = Vy(t)sin(S + 180) + Vx(t)cos(S) ). My guess is that only a few angles will suffice to give the appearance of infinite variation (particularly as the ball travels in a curve), so just specify the angle as an integer multiple of the minimum angle size (say 15 degrees) so the calculations can be done using a table lookup for sin and cos. eg VAR sin : ARRAY[0..23] OF INTEGER ; (scaled appropriately). * - Greg E kore e ngaro, he kakano * gford@waikato.ac.nz i ruia mai i Rangiatea
Technical Details
Message-ID:
<1992Nov6.034457.11981@waikato.ac.nz>Path:
arc1-ca.pugleaf.net!sparky!uunet!decwrl!waikato.ac.nz!gfordReferences:
<1992Nov2.204624.24267@u.washington.edu> <18899@ucdavis.ucdavis.edu> <Bx8H5G.Gt7@cs.vu.nl>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!decwrl!waikato.ac.nz!gford From: gford@waikato.ac.nz Newsgroups: rec.games.programmer Subject: Re: Software Pinball Machine Message-ID: <1992Nov6.034457.11981@waikato.ac.nz> Date: 6 Nov 92 03:44:57 +1300 References: <1992Nov2.204624.24267@u.washington.edu> <18899@ucdavis.ucdavis.edu> <Bx8H5G.Gt7@cs.vu.nl> Organization: University of Waikato, Hamilton, New Zealand Lines: 56