9 #include <argos3/core/utility/math/vector3.h>
10 #include <argos3/core/utility/math/quaternion.h>
12 #include <argos3/core/wrappers/lua/lua_quaternion.h>
13 #include <argos3/core/wrappers/lua/lua_utility.h>
20 const std::string CLuaVector3::m_strTypeId(
"argos3.vector3");
27 lua_pushcfunction(pt_state,
Create);
28 lua_setglobal(pt_state,
"vector3");
30 luaL_newmetatable(pt_state, m_strTypeId.c_str());
52 switch(lua_gettop(pt_state)) {
63 if(lua_isnumber(pt_state, 1) &&
64 lua_isnumber(pt_state, 2) &&
65 lua_isnumber(pt_state, 3)) {
67 lua_tonumber(pt_state, 1),
68 lua_tonumber(pt_state, 2),
69 lua_tonumber(pt_state, 3));
72 lua_pushstring(pt_state,
"invalid arguments to vector3");
77 lua_pushstring(pt_state,
"invalid arguments to vector3");
91 luaL_checkudata(pt_state, n_index, m_strTypeId.c_str());
93 if(pvUserdatum ==
nullptr) {
94 lua_pushstring(pt_state,
"vector3 not found at requested index");
106 if(lua_isuserdata(pt_state, 1) &&
107 lua_isstring(pt_state, 2)) {
109 const char* pchKey = lua_tolstring(pt_state, 2, &unLength);
114 lua_pushnumber(pt_state, cVector.
GetX());
117 lua_pushnumber(pt_state, cVector.
GetY());
120 lua_pushnumber(pt_state, cVector.
GetZ());
123 lua_pushstring(pt_state,
"invalid key for vector3");
129 luaL_getmetatable(pt_state, m_strTypeId.c_str());
130 lua_pushvalue(pt_state, 2);
131 lua_gettable(pt_state, -2);
135 lua_pushstring(pt_state,
"invalid operation on vector3");
144 if(lua_isuserdata(pt_state, 1) &&
145 lua_isstring(pt_state, 2) &&
146 lua_isnumber(pt_state, 3)) {
148 const char* pchKey = lua_tolstring(pt_state, 2, &unLength);
153 cVector.
SetX(lua_tonumber(pt_state, 3));
156 cVector.
SetY(lua_tonumber(pt_state, 3));
159 cVector.
SetZ(lua_tonumber(pt_state, 3));
162 lua_pushstring(pt_state,
"invalid key for vector3");
168 lua_pushstring(pt_state,
"invalid operation on vector3");
180 lua_pushboolean(pt_state, bEqual);
199 if(lua_isuserdata(pt_state, 1) && lua_isnumber(pt_state, 2)) {
201 PushVector3(pt_state, cVector * lua_tonumber(pt_state, 2));
203 else if(lua_isuserdata(pt_state, 2) && lua_isnumber(pt_state, 1)) {
205 PushVector3(pt_state, cVector * lua_tonumber(pt_state, 1));
208 lua_pushstring(pt_state,
"invalid arguments for multiplication by scalar");
258 lua_pop(pt_state, 1);
271 lua_pushnumber(pt_state, fDotProduct);
285 cVector.
Rotate(cQuaternion);
287 lua_pop(pt_state, 1);
299 std::ostringstream ossOutput;
300 ossOutput << cVector;
302 lua_pushstring(pt_state, ossOutput.str().c_str());
float Real
Collects all ARGoS code.
The namespace containing all the ARGoS related code.
CVector3 & CrossProduct(const CVector3 &c_vector3)
Calculates the cross product between this vector and the passed one.
void SetY(const Real f_y)
Sets the y coordinate of this vector.
CVector3 & Rotate(const CQuaternion &c_quaternion)
Rotates this vector by the given quaternion.
Real GetX() const
Returns the x coordinate of this vector.
void SetX(const Real f_x)
Sets the x coordinate of this vector.
Real DotProduct(const CVector3 &c_vector3) const
Returns the dot product between this vector and the passed one.
CVector3 & Normalize()
Normalizes this vector.
void SetZ(const Real f_z)
Sets the z coordinate of this vector.
Real GetY() const
Returns the y coordinate of this vector.
Real GetZ() const
Returns the z coordinate of this vector.
static CQuaternion & ToQuaternion(lua_State *pt_state, int n_index)
static void AddToTable(lua_State *pt_state, const std::string &str_key, void *pt_data)
Adds a pointer to a chunk of data with the given string key to the table located at the top of the st...
static int ToString(lua_State *pt_state)
static int Create(lua_State *pt_state)
static int Multiply(lua_State *pt_state)
static int Normalize(lua_State *pt_state)
static void PushVector3(lua_State *pt_state, TArguments &&... t_arguments)
static int DotProduct(lua_State *pt_state)
static void RegisterType(lua_State *pt_state)
static int Equal(lua_State *pt_state)
static int UnaryMinus(lua_State *pt_state)
static int CrossProduct(lua_State *pt_state)
static CVector3 & ToVector3(lua_State *pt_state, int n_index)
static int NewIndex(lua_State *pt_state)
static int Subtract(lua_State *pt_state)
static int Length(lua_State *pt_state)
static int Add(lua_State *pt_state)
static int Index(lua_State *pt_state)
static int Rotate(lua_State *pt_state)