Read table values as raw values for luax_readquat

This commit is contained in:
xiejiangzhi 2024-02-05 09:56:17 +08:00
parent fa230dffff
commit fddd8e44e4
1 changed files with 7 additions and 8 deletions

View File

@ -151,23 +151,22 @@ int luax_readscale(lua_State* L, int index, vec3 v, int components, const char*
}
int luax_readquat(lua_State* L, int index, quat q, const char* expected) {
float angle, ax, ay, az;
float v[4];
switch (lua_type(L, index)) {
case LUA_TNIL:
case LUA_TNONE:
quat_identity(q);
return ++index;
case LUA_TNUMBER:
angle = luax_optfloat(L, index++, 0.f);
ax = luax_optfloat(L, index++, 0.f);
ay = luax_optfloat(L, index++, 1.f);
az = luax_optfloat(L, index++, 0.f);
quat_fromAngleAxis(q, angle, ax, ay, az);
v[0] = luax_optfloat(L, index++, 0.f);
v[1] = luax_optfloat(L, index++, 0.f);
v[2] = luax_optfloat(L, index++, 1.f);
v[3] = luax_optfloat(L, index++, 0.f);
quat_fromAngleAxis(q, v[0], v[1], v[2], v[3]);
return index;
case LUA_TTABLE:
float v[4];
luax_readobjarr(L, index, 4, v, "quat");
quat_fromAngleAxis(q, v[0], v[1], v[2], v[3]);
quat_init(q, v);
return index + 1;
default:
quat_init(q, luax_checkvector(L, index++, V_QUAT, expected ? expected : "quat or number"));