Expose length method in scripting vector3

This commit is contained in:
Marianne Gagnon 2015-06-28 19:03:09 -04:00
parent 68eb4eb359
commit eda00e12f9
2 changed files with 7 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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) { }