Mercurial > projects > openmelee
diff ai/utilities.d @ 19:08ddf9e71b88
steer to avoid
author | zzzzrrr <mason.green@gmail.com> |
---|---|
date | Wed, 25 Mar 2009 14:44:47 -0400 |
parents | 7f74e064dad5 |
children |
line wrap: on
line diff
--- a/ai/utilities.d Wed Mar 25 11:28:25 2009 -0400 +++ b/ai/utilities.d Wed Mar 25 14:44:47 2009 -0400 @@ -31,6 +31,7 @@ module openmelee.ai.utilities; import tango.math.random.Kiss : Kiss; +import blaze.common.bzMath : bzVec2, bzDot; float scalarRandomWalk(float initial, float walkspeed, float min, float max) { @@ -40,6 +41,19 @@ return next; } +// return component of vector perpendicular to a unit basis vector +// IMPORTANT NOTE: assumes "basis" has unit magnitude(length==1) +bzVec2 perpendicularComponent(bzVec2 vector, bzVec2 unitBasis) { + return (vector - parallelComponent(vector, unitBasis)); +} + +// return component of vector parallel to a unit basis vector +// IMPORTANT NOTE: assumes "basis" has unit magnitude (length == 1) +bzVec2 parallelComponent(bzVec2 vector, bzVec2 unitBasis) { + float projection = bzDot(vector, unitBasis); + return unitBasis * projection; +} + // ---------------------------------------------------------------------------- // classify a value relative to the interval between two bounds: // returns -1 when below the lower bound @@ -52,6 +66,10 @@ return 0; } +float square(float x) { + return x * x; +} + T randomRange(T = int) (T min, T max) { return min + Kiss.instance.natural() % (max + 1 - min);