diff options
author | Peter Kohaut | 2016-10-04 02:21:08 +0200 |
---|---|---|
committer | Peter Kohaut | 2016-10-04 18:15:57 +0200 |
commit | 6547c35e15252fd24f260ebd6b8f01d9edd01aa2 (patch) | |
tree | 89fec132f3325fed022c4f7bd7fd003942604352 /engines/bladerunner/vector.h | |
parent | 281c19ab036f387a99192594aa645e696009f40b (diff) | |
download | scummvm-rg350-6547c35e15252fd24f260ebd6b8f01d9edd01aa2.tar.gz scummvm-rg350-6547c35e15252fd24f260ebd6b8f01d9edd01aa2.tar.bz2 scummvm-rg350-6547c35e15252fd24f260ebd6b8f01d9edd01aa2.zip |
BLADERUNNER: trying to figure out walking, added structures for obstacles used for pathfinding, fixed bug in searching for walkboxes
Diffstat (limited to 'engines/bladerunner/vector.h')
-rw-r--r-- | engines/bladerunner/vector.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/engines/bladerunner/vector.h b/engines/bladerunner/vector.h index 070ca86190..84e4df63bb 100644 --- a/engines/bladerunner/vector.h +++ b/engines/bladerunner/vector.h @@ -108,6 +108,54 @@ inline Vector4 operator/(Vector4 a, Vector4 b) { return Vector4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w); } +inline +int angle_1024(float x1, float z1, float x2, float z2) +{ + float angle_rad = atan2(x2 - x1, z1 - z2); + int a = int(512.0 * angle_rad / M_PI); + return (a + 1024) % 1024; +} + +inline +int angle_1024(const Vector3 &v1, const Vector3 &v2) +{ + return angle_1024(v1.x, v1.z, v2.x, v2.z); +} + +inline +float distance(float x1, float z1, float x2, float z2) +{ + float dx = x1 - x2; + float dz = z1 - z2; + float d = sqrt(dx*dx + dz*dz); + + float int_part = (int)d; + float frac_part = d - int_part; + + if (frac_part < 0.001) + frac_part = 0.0; + + return int_part + frac_part; +} + +inline +float distance(const Vector3 &v1, const Vector3 &v2) +{ + return distance(v1.x, v1.z, v2.x, v2.z); +} + +inline +float cos_1024(int angle1024) { + return cos(angle1024 * (M_PI / 512.0f)); +} + +inline +float sin_1024(int angle1024) { + return sin(angle1024 * (M_PI / 512.0f)); +} + + + } // End of namespace BladeRunner #endif |