Distance in a shootem up 2D
Quote:Originally posted by OneSadCookie
so you might as well multiply by the inverse of the square root[/b]
reciprocal...
This would likely be a perfect place for fresqrt, as that's exactly what it gives you

Steven
Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Thanks! That's been something I've had commented out for a very long time now, and it's great to finally have it working. Every sqrt() function that I was forced to leave in my main loop code made it feel that much more dirtied
just to recap what I had to do to get this working:
[SOURCECODE]
#include <ppc_intrinsics.h>
float qsqrt(register float arg)
{
register float res;
if (arg == 0.0f)
return 0.0f;
res = __frsqrtes (arg);
res += 0.5f * res * (1.0f - arg * res * res);
res += 0.5f * res * (1.0f - arg * res * res);
return res * arg;
}
[/SOURCECODE]
and in my active target settings, under gcc options, I had to add:
-force_cpusubtype_ALL
to other c compiler flags.
Thanks for the help OSC! I'll add a qrsqrt function to eliminate the extraneous mult. divide I was doing for normalisation as well.
just to recap what I had to do to get this working:
[SOURCECODE]
#include <ppc_intrinsics.h>
float qsqrt(register float arg)
{
register float res;
if (arg == 0.0f)
return 0.0f;
res = __frsqrtes (arg);
res += 0.5f * res * (1.0f - arg * res * res);
res += 0.5f * res * (1.0f - arg * res * res);
return res * arg;
}
[/SOURCECODE]
and in my active target settings, under gcc options, I had to add:
-force_cpusubtype_ALL
to other c compiler flags.
Thanks for the help OSC! I'll add a qrsqrt function to eliminate the extraneous mult. divide I was doing for normalisation as well.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Fast Distance formula? | mikey | 11 | 6,062 |
Nov 23, 2009 10:43 AM Last Post: mikey |
|
| calculating X and Y coordinates w/ an angle and distance | ferum | 13 | 12,670 |
Jun 25, 2008 10:53 PM Last Post: rosenth |
|
| Signed distance fields | imikedaman | 16 | 8,320 |
Jul 20, 2007 07:13 PM Last Post: imikedaman |
|
| Speed distance velocity and other headaches | Thinker | 6 | 3,224 |
Jul 3, 2003 09:55 AM Last Post: Thinker |
|

