Initialize vec3 from mat4

Rotation and scaling is lost, only position is extracted from mat4.
This commit is contained in:
Josip Miskovic 2020-06-28 11:49:43 +03:00
parent c4e0ace182
commit c314824304
1 changed files with 9 additions and 2 deletions

View File

@ -488,8 +488,15 @@ int l_lovrVec3Set(lua_State* L) {
float x = luax_optfloat(L, 2, 0.f);
vec3_set(v, x, luax_optfloat(L, 3, x), luax_optfloat(L, 4, x));
} else {
vec3 u = luax_checkvector(L, 2, V_VEC3, "vec3 or number");
vec3_init(v, u);
VectorType t;
float* p = luax_tovector(L, 2, &t);
if (p && t == V_VEC3) {
vec3_init(v, p);
} else if (p && t == V_MAT4) {
vec3_set(v, p[12], p[13], p[14]);
} else{
luaL_typerror(L, 2, "vec3, mat4, or number");
}
}
lua_settop(L, 1);
return 1;