Bowntz -- an audio-visual pseudo-physical simulation of colliding circles
Copyright (C) 2010,2013,2015 Claude-Heiland-Allen <claude@mathr.co.uk>
Build
-----
$ cabal sandbox init
$ cabal install
Usage
-----
$ scsynth -u 57110 &
-- wait for scsynth to start, connect its JACK ports --
$ ./bowntz
Bowntz requires a "clean" SC3 server to be running on its usual port.
Bowntz leaves this SC3 server in an "unclean" state when it exits.
This situation is far from ideal, but it's the current state of the code.
Notes
-----
The world is a collection of N circles which each move at a constant speed
in a straight line (in the absence of collisions). Given two such circles
it is possible to calculate the precise time of their next collision. For
N circles, O(N^2) such "next" collisions may occur.
Pick the soonest next collision between circles A and B. This collision
will change the velocities of A and B, but no other circle. Update the
collection of collisions, by removing all the other "next" collisions
involving either A or B, and computing the new collisions of A and B with
all the other circles (O(N) collisions). For maintaining a consistent
time-base for all circles in the world, it makes sense to advance in a
straight line each circle to its position at the time of the collision.
Given a world at time T, to find the world at time T+dT simply step
through the future collisions one by one until the soonest collision is
after T+dT, at which point one can just advance the circles in straight
lines to T+dT.
T T+1 T+2 T+3 T+4 T+5 T+6 T+7
... | | | | | | | | ...
----*---*---*---------*---------------**-*--*-*-------*------*--
Care needs to be taken in case of numerical imprecision: one can get an
infinite number of collisions without time increasing.
To do
-----
General code clean-up and documentation.
Optimizations based on collision possibility tree, example:
A 7 possible
| A~*~B
+---B A~*~E 5 impossible
| +---C B~*~C !A~*~C
| +---D B~*~D !A~*~D
| C~*~D !C~*~F
+---E B~*~E !D~*~F
+---F E~*~F !A~*~F
data Node = Node ID [Node]
possibles n@(Node _ ns) = possible n `map` ns ++ liftM2 possible ns
Infinite zoom into circles within circles within circles within circles?
When (if ever) would it be safe to prune "outside"?
Some kind of loop where circles contain themselves (I did try this in
another unreleased version but it resulted in hyperexponential kinetic
energy increase, which naturally caused problems).
Non-flat space.
Angular momentum affecting collisions.
Remove all sources of non-determinism to enable two-pass rendering:
1 pass to record audio from SC3 in realtime
2 pass to record video from OpenGL in non-realtime
Or just record ball positions in the first pass for later drawing (because
callback races and/or timing instability might affect the reproducibility
unless very precise care is taken at all stages..)
Interactivity.
More impressive audio-visuals.
Won't
-----
Anything other than circles (ok, maybe infinite lines would be ok, but
asymmetry with angular momentum would quickly make collision detection
get horribly complicated).
Legal
-----
License: GPL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.