add mat4.from_quat(...) & update mat4.decompose(...)
This commit is contained in:
@@ -52,9 +52,9 @@ static int l_mul(lua::State* L) {
|
||||
switch (argc) {
|
||||
case 2: {
|
||||
if (len2 == 4) {
|
||||
return lua::pushvec4(L, matrix1 * lua::tovec4(L, 2));
|
||||
return lua::pushvec4_stack(L, matrix1 * lua::tovec4(L, 2));
|
||||
} else if (len2 == 3) {
|
||||
return lua::pushvec3(L, matrix1 * glm::vec4(lua::tovec3(L, 2), 1.0f));
|
||||
return lua::pushvec3_stack(L, matrix1 * glm::vec4(lua::tovec3(L, 2), 1.0f));
|
||||
}
|
||||
return lua::pushmat4(L, matrix1 * lua::tomat4(L, 2));
|
||||
}
|
||||
@@ -172,6 +172,7 @@ static int l_transpose(lua::State* L) {
|
||||
/// mat4.decompose(m: float[16]) -> {
|
||||
/// scale=float[3],
|
||||
/// rotation=float[16],
|
||||
/// quaternion=float[4],
|
||||
/// translation=float[3],
|
||||
/// skew=float[3],
|
||||
/// perspective=float[4]
|
||||
@@ -192,21 +193,24 @@ static int l_decompose(lua::State* L) {
|
||||
perspective
|
||||
);
|
||||
|
||||
lua::createtable(L, 0, 5);
|
||||
lua::createtable(L, 0, 6);
|
||||
|
||||
lua::pushvec3_arr(L, scale);
|
||||
lua::pushvec3(L, scale);
|
||||
lua::setfield(L, "scale");
|
||||
|
||||
lua::pushmat4(L, glm::toMat4(rotation));
|
||||
lua::setfield(L, "rotation");
|
||||
|
||||
lua::pushvec3_arr(L, translation);
|
||||
lua::pushquat(L, rotation);
|
||||
lua::setfield(L, "quaternion");
|
||||
|
||||
lua::pushvec3(L, translation);
|
||||
lua::setfield(L, "translation");
|
||||
|
||||
lua::pushvec3_arr(L, skew);
|
||||
lua::pushvec3(L, skew);
|
||||
lua::setfield(L, "skew");
|
||||
|
||||
lua::pushvec4_arr(L, perspective);
|
||||
lua::pushvec4(L, perspective);
|
||||
lua::setfield(L, "perspective");
|
||||
return 1;
|
||||
}
|
||||
@@ -227,6 +231,21 @@ static int l_look_at(lua::State* L) {
|
||||
}
|
||||
}
|
||||
|
||||
static int l_from_quat(lua::State* L) {
|
||||
uint argc = lua::gettop(L);
|
||||
if (argc != 1 && argc != 2) {
|
||||
throw std::runtime_error("invalid arguments number (1 or 2 expected)");
|
||||
}
|
||||
auto quat = lua::toquat(L, 1);
|
||||
switch (argc) {
|
||||
case 1:
|
||||
return lua::pushmat4(L, glm::toMat4(quat));
|
||||
case 2:
|
||||
return lua::setmat4(L, 2, glm::toMat4(quat));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_tostring(lua::State* L) {
|
||||
auto matrix = lua::tomat4(L, 1);
|
||||
bool multiline = lua::toboolean(L, 2);
|
||||
@@ -266,6 +285,7 @@ const luaL_Reg mat4lib [] = {
|
||||
{"determinant", lua::wrap<l_determinant>},
|
||||
{"decompose", lua::wrap<l_decompose>},
|
||||
{"look_at", lua::wrap<l_look_at>},
|
||||
{"from_quat", lua::wrap<l_from_quat>},
|
||||
{"tostring", lua::wrap<l_tostring>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user