diff --git a/src/scriptengine/scriptvec3.cpp b/src/scriptengine/scriptvec3.cpp index 29e4d1818..b2eab94eb 100644 --- a/src/scriptengine/scriptvec3.cpp +++ b/src/scriptengine/scriptvec3.cpp @@ -57,6 +57,7 @@ namespace Scripting float getX(SimpleVec3* v) { return v->getX(); } float getY(SimpleVec3* v) { return v->getY(); } float getZ(SimpleVec3* v) { return v->getZ(); } + float getLength(SimpleVec3* v) { return v->getLength(); } void RegisterVec3(asIScriptEngine *engine) { @@ -71,5 +72,6 @@ namespace Scripting r = engine->RegisterObjectMethod("Vec3", "float getX()", asFUNCTION(getX), asCALL_CDECL_OBJLAST); assert(r >= 0); r = engine->RegisterObjectMethod("Vec3", "float getY()", asFUNCTION(getY), asCALL_CDECL_OBJLAST); assert(r >= 0); r = engine->RegisterObjectMethod("Vec3", "float getZ()", asFUNCTION(getZ), asCALL_CDECL_OBJLAST); assert(r >= 0); + r = engine->RegisterObjectMethod("Vec3", "float getLength()", asFUNCTION(getLength), asCALL_CDECL_OBJLAST); assert(r >= 0); } } diff --git a/src/scriptengine/scriptvec3.hpp b/src/scriptengine/scriptvec3.hpp index 25a8cdbf0..db3f00f83 100644 --- a/src/scriptengine/scriptvec3.hpp +++ b/src/scriptengine/scriptvec3.hpp @@ -35,6 +35,11 @@ namespace Scripting float getY() const { return y; } float getZ() const { return z; } + float getLength() const + { + return sqrt(x*x + y*y + z*z); + } + SimpleVec3() : x(0), y(0), z(0) { } SimpleVec3(float p_x, float p_y, float p_z) : x(p_x), y(p_y), z(p_z) { } SimpleVec3(const SimpleVec3& other) : x(other.x), y(other.y), z(other.z) { }