[gcompris-devel] Maze plugin enhancements (and cleanup)

Christof Petig christof at petig-baender.de
Mon Oct 14 00:43:02 UTC 2002


Hi Bastiaan,

sorry for delaying so long, but I had a busy summer. I was the one 
volunteering to write a 3D frontend to gmaze. Actually while enhancing 
my own ancieant maze program to use an easier algorithm I found out that 
everything you need to display a 3D maze is ray interception theorems 
(yes that's about 7th class math). The only drawback of not using OpenGL 
(matrix multiplication/hidden surface problems!) is that you cannot 
chose viewing directions other than parallel/orthogonal to the walls.

So my algorithm boiled down to one simple function (see P3S/P4S) and 
it's inverse and a lot of vector addition (read checking for wall 
existance).

So after having shaken out every bug of the function (one might not 
believe how many sign and bracket placement errors one can create from 
this simple function) I was ready for inclusion into gmaze. [patch later 
this week, perhaps tomorrow?]

First I tried to implement a "run until decision is needed" mode for the 
penguin to make myself familiar with the maze code. Here's the patch.

But since I dared to simplify/fix some things I have to explain:

- the key_press function might as well be static

- since C has excellent bit field operators (which sadly are not too 
popular ...), I replaced the A-X>=0 ... A=A-X by the bit equivalent: A&X 
(yes one operator does all the dirty work)

Actually the operators work as following
(X stands for the bit(s) to test/change):
- test whether a bit is set: A&X
- test whether a bit is clear: !(A&X)
- set a bit: A|=X;
- clear a bit: A&=~X; (sorry but this operation needs two operators 
combined)
- toggle a bit: A^=X;

- since movePos before needed to deduce the direction (richting) from 
the movement but it was available to the caller (one_step) I passed it 
down (extra argument)

So have fun with the turbo penguin
      Christof

PS: If you have any questions about the bit operators feel free to ask.
PPS: Of course I think that the turbo mode should be optional. I was not 
sure about how to set the variable (run_fast) by an additional button in 
gcompris.
P3S: [s0 + w*ex + (w*(1+ez)*(2*lx-(1+ex)))/(2*ly+1+ez); e? is the 3D eye 
position, l? the 2D wall distance, and s0 and w are screen position and 
width]
P4S: [s0 + w*(2*lx-1)/(2*ly+1) if you center the eye]
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: maze.patch
URL: <http://mail.kde.org/pipermail/gcompris-devel/attachments/20021014/518048e7/attachment.ksh>


More information about the Gcompris-devel mailing list