Add methods to get exact coordinate distances

This commit is contained in:
Rochet2
2015-03-06 17:18:18 +02:00
parent 947c3a3b10
commit 2d672d8828
2 changed files with 94 additions and 2 deletions

View File

@@ -211,7 +211,10 @@ ElunaRegister<WorldObject> WorldObjectMethods[] =
{ "GetNearestCreature", &LuaWorldObject::GetNearestCreature }, // :GetNearestCreature([range, entry]) - Returns nearest creature with given entry in sight or given range entry can be 0 or nil for any.
{ "GetNearObject", &LuaWorldObject::GetNearObject },
{ "GetNearObjects", &LuaWorldObject::GetNearObjects },
{ "GetDistance", &LuaWorldObject::GetDistance }, // :GetDistance(WorldObject or x, y, z) - Returns the distance between 2 objects or location
{ "GetDistance", &LuaWorldObject::GetDistance },
{ "GetExactDistance", &LuaWorldObject::GetExactDistance },
{ "GetDistance2d", &LuaWorldObject::GetDistance2d },
{ "GetExactDistance2d", &LuaWorldObject::GetExactDistance2d },
{ "GetRelativePoint", &LuaWorldObject::GetRelativePoint }, // :GetRelativePoint(dist, rad) - Returns the x, y and z of a point dist away from worldobject.
{ "GetAngle", &LuaWorldObject::GetAngle }, // :GetAngle(WorldObject or x, y) - Returns angle between world object and target or x and y coords.

View File

@@ -422,7 +422,9 @@ namespace LuaWorldObject
}
/**
* Returns the distance from this [WorldObject] to another [WorldObject], or from this [WorldObject] to a point.
* Returns the distance from this [WorldObject] to another [WorldObject], or from this [WorldObject] to a point in 3d space.
*
* The function takes into account the given object sizes. See also [WorldObject:GetExactDistance], [WorldObject:GetDistance2d]
*
* @proto dist = (obj)
* @proto dist = (x, y, z)
@@ -449,6 +451,92 @@ namespace LuaWorldObject
return 1;
}
/**
* Returns the distance from this [WorldObject] to another [WorldObject], or from this [WorldObject] to a point in 3d space.
*
* The function does not take into account the given object sizes, which means only the object coordinates are compared. See also [WorldObject:GetDistance], [WorldObject:GetDistance2d]
*
* @proto dist = (obj)
* @proto dist = (x, y, z)
*
* @param [WorldObject] obj
* @param float x : the X-coordinate of the point
* @param float y : the Y-coordinate of the point
* @param float z : the Z-coordinate of the point
*
* @return float dist : the distance in yards
*/
int GetExactDistance(Eluna* /*E*/, lua_State* L, WorldObject* obj)
{
WorldObject* target = Eluna::CHECKOBJ<WorldObject>(L, 2, false);
if (target && target->IsInWorld())
Eluna::Push(L, obj->GetExactDist(target));
else
{
float X = Eluna::CHECKVAL<float>(L, 2);
float Y = Eluna::CHECKVAL<float>(L, 3);
float Z = Eluna::CHECKVAL<float>(L, 4);
Eluna::Push(L, obj->GetExactDist(X, Y, Z));
}
return 1;
}
/**
* Returns the distance from this [WorldObject] to another [WorldObject], or from this [WorldObject] to a point in 2d space.
*
* The function takes into account the given object sizes. See also [WorldObject:GetDistance], [WorldObject:GetExactDistance2d]
*
* @proto dist = (obj)
* @proto dist = (x, y)
*
* @param [WorldObject] obj
* @param float x : the X-coordinate of the point
* @param float y : the Y-coordinate of the point
*
* @return float dist : the distance in yards
*/
int GetDistance2d(Eluna* /*E*/, lua_State* L, WorldObject* obj)
{
WorldObject* target = Eluna::CHECKOBJ<WorldObject>(L, 2, false);
if (target && target->IsInWorld())
Eluna::Push(L, obj->GetDistance2d(target));
else
{
float X = Eluna::CHECKVAL<float>(L, 2);
float Y = Eluna::CHECKVAL<float>(L, 3);
Eluna::Push(L, obj->GetDistance2d(X, Y));
}
return 1;
}
/**
* Returns the distance from this [WorldObject] to another [WorldObject], or from this [WorldObject] to a point in 2d space.
*
* The function does not take into account the given object sizes, which means only the object coordinates are compared. See also [WorldObject:GetDistance], [WorldObject:GetDistance2d]
*
* @proto dist = (obj)
* @proto dist = (x, y)
*
* @param [WorldObject] obj
* @param float x : the X-coordinate of the point
* @param float y : the Y-coordinate of the point
*
* @return float dist : the distance in yards
*/
int GetExactDistance2d(Eluna* /*E*/, lua_State* L, WorldObject* obj)
{
WorldObject* target = Eluna::CHECKOBJ<WorldObject>(L, 2, false);
if (target && target->IsInWorld())
Eluna::Push(L, obj->GetExactDist2d(target));
else
{
float X = Eluna::CHECKVAL<float>(L, 2);
float Y = Eluna::CHECKVAL<float>(L, 3);
Eluna::Push(L, obj->GetExactDist2d(X, Y));
}
return 1;
}
/**
* Returns the x, y and z of a point dist away from the [WorldObject].
*
@@ -475,6 +563,7 @@ namespace LuaWorldObject
/**
* Returns the angle between this [WorldObject] and another [WorldObject] or a point.
*
* The angle is the angle between two points and orientation will be ignored.
*
* @proto dist = (obj)