9 #include <argos3/core/utility/math/angles.h>
10 #include <argos3/core/utility/math/vector3.h>
11 #include <argos3/core/utility/math/quaternion.h>
13 #include <argos3/core/wrappers/lua/lua_vector3.h>
14 #include <argos3/core/wrappers/lua/lua_utility.h>
21 const std::string CLuaQuaternion::m_strTypeId(
"argos3.quaternion");
28 lua_pushcfunction(pt_state,
Create);
29 lua_setglobal(pt_state,
"quaternion");
31 luaL_newmetatable(pt_state, m_strTypeId.c_str());
49 switch(lua_gettop(pt_state)) {
60 if(lua_isnumber(pt_state, 1)) {
61 CRadians cAngle(lua_tonumber(pt_state, 1));
66 lua_pushstring(pt_state,
"invalid arguments to quaternion");
72 if(lua_isnumber(pt_state, 1) &&
73 lua_isnumber(pt_state, 2) &&
74 lua_isnumber(pt_state, 3) &&
75 lua_isnumber(pt_state, 4)) {
77 lua_tonumber(pt_state, 1),
78 lua_tonumber(pt_state, 2),
79 lua_tonumber(pt_state, 3),
80 lua_tonumber(pt_state, 4));
83 lua_pushstring(pt_state,
"invalid arguments to quaternion");
88 lua_pushstring(pt_state,
"invalid arguments to quaternion");
102 luaL_checkudata(pt_state, n_index, m_strTypeId.c_str());
104 if(pvUserdatum ==
nullptr) {
105 lua_pushstring(pt_state,
"quaternion not found at requested index");
110 return *pcQuaternion;
117 if(lua_isuserdata(pt_state, 1) &&
118 lua_isstring(pt_state, 2)) {
120 const char* pchKey = lua_tolstring(pt_state, 2, &unLength);
125 lua_pushnumber(pt_state, cQuaternion.
GetW());
128 lua_pushnumber(pt_state, cQuaternion.
GetX());
131 lua_pushnumber(pt_state, cQuaternion.
GetY());
134 lua_pushnumber(pt_state, cQuaternion.
GetZ());
137 lua_pushstring(pt_state,
"invalid key for quaternion");
143 luaL_getmetatable(pt_state, m_strTypeId.c_str());
144 lua_pushvalue(pt_state, 2);
145 lua_gettable(pt_state, -2);
149 lua_pushstring(pt_state,
"invalid operation on quaternion");
158 if(lua_isuserdata(pt_state, 1) &&
159 lua_isstring(pt_state, 2) &&
160 lua_isnumber(pt_state, 3)) {
162 const char* pchKey = lua_tolstring(pt_state, 2, &unLength);
167 cQuaternion.
SetW(lua_tonumber(pt_state, 3));
170 cQuaternion.
SetX(lua_tonumber(pt_state, 3));
173 cQuaternion.
SetY(lua_tonumber(pt_state, 3));
176 cQuaternion.
SetZ(lua_tonumber(pt_state, 3));
179 lua_pushstring(pt_state,
"invalid key for quaternion");
185 lua_pushstring(pt_state,
"invalid operation on quaternion");
197 lua_pushboolean(pt_state, bEqual);
241 lua_pushnumber(pt_state, cAngle.
GetValue());
256 lua_pushnumber(pt_state, cZ.
GetValue());
257 lua_pushnumber(pt_state, cY.
GetValue());
258 lua_pushnumber(pt_state, cX.
GetValue());
269 std::ostringstream ossOutput;
270 ossOutput << cQuaternion;
272 lua_pushstring(pt_state, ossOutput.str().c_str());
The namespace containing all the ARGoS related code.
It defines the basic type CRadians, used to store an angle value in radians.
Real GetValue() const
Returns the value in radians.
void ToAngleAxis(CRadians &c_angle, CVector3 &c_vector) const
void ToEulerAngles(CRadians &c_z_angle, CRadians &c_y_angle, CRadians &c_x_angle) const
CQuaternion & Normalize()
static CQuaternion & ToQuaternion(lua_State *pt_state, int n_index)
static int Normalize(lua_State *pt_state)
static int Inverse(lua_State *pt_state)
static int ToAngleAxis(lua_State *pt_state)
static void RegisterType(lua_State *pt_state)
static int ToEulerAngles(lua_State *pt_state)
static void PushQuaternion(lua_State *pt_state, TArguments &&... t_arguments)
static int NewIndex(lua_State *pt_state)
static int Equal(lua_State *pt_state)
static int ToString(lua_State *pt_state)
static int Create(lua_State *pt_state)
static int Multiply(lua_State *pt_state)
static int Index(lua_State *pt_state)
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 void PushVector3(lua_State *pt_state, TArguments &&... t_arguments)
static CVector3 & ToVector3(lua_State *pt_state, int n_index)