diff --git a/graphics/vector3d.h b/graphics/vector3d.h index ec23d659449..81508120e24 100644 --- a/graphics/vector3d.h +++ b/graphics/vector3d.h @@ -110,6 +110,14 @@ public: return yaw; } + void normalize() { + float len = sqrt(dotProduct(x(), y(), z())); + if (len != 0.0f) { + float t = 1.0f / len; + set(x() * t, y() * t, y() * t); + } + } + float dotProduct(float sx, float sy, float sz) { return x() * sx + y() * sy + z() * sz; }