Topic: First patches. Solve #230 and fast vector normalization.
Hey,
I decided to give a shot the nasty bug in here -> http://ix.teewars.com/trac/ticket/230
First problem was the bug in vector normalization function. It didn't handle small values resulting in dividing by zero which resulted in nan. Got that fixed. Next thing was adding a special case for the cursor position (0,0). I defaulted the shooting and hook direction to vector (1,0) as it would be expected from the tee's barrel position.
Here's the patch. I think that it should be abstracted to "get_direction" method somewhere, but I leave it to you
http://eros.vlo.gda.pl/~rush/teewars-0.3.0-fix230.patch
The second patch depends on the first one and it adds a fast normalization method which could speed the things up on slower machines. Dunno if it's worth it. Possibly it is hardware dependant because of the IEEE-32 operations. Also, your templates are a bit decieving. They all take T as an argument, but obviously most of them operates only on floats. I followed this weird style. :> And the last thing .. I assume that such small math code is in public domain but I can't be 100% sure, there is a reference in the comment from where it was taken ...
Here is the second patch:
http://eros.vlo.gda.pl/~rush/teewars-0. … norm.patch
Cheers,
Ergo