1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Make getting bone overrides return the "same" euler angles (#15007)

This commit is contained in:
Lars Müller 2024-08-26 21:22:38 +02:00 committed by GitHub
parent 5583831c40
commit 21ed680b10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 37 additions and 10 deletions

View file

@ -562,8 +562,10 @@ int ObjectRef::l_set_bone_position(lua_State *L)
BoneOverride props;
if (!lua_isnoneornil(L, 3))
props.position.vector = check_v3f(L, 3);
if (!lua_isnoneornil(L, 4))
props.rotation.next = core::quaternion(check_v3f(L, 4) * core::DEGTORAD);
if (!lua_isnoneornil(L, 4)) {
props.rotation.next_radians = check_v3f(L, 4) * core::DEGTORAD;
props.rotation.next = core::quaternion(props.rotation.next_radians);
}
props.position.absolute = true;
props.rotation.absolute = true;
sao->setBoneOverride(bone, props);
@ -585,9 +587,9 @@ int ObjectRef::l_get_bone_position(lua_State *L)
std::string bone = readParam<std::string>(L, 2, "");
BoneOverride props = sao->getBoneOverride(bone);
push_v3f(L, props.position.vector);
v3f euler_rot;
props.rotation.next.toEuler(euler_rot);
push_v3f(L, euler_rot * core::RADTODEG);
// In order to give modders back the euler angles they passed in,
// this **must not** compute equivalent euler angles from the quaternion
push_v3f(L, props.rotation.next_radians * core::RADTODEG);
return 2;
}
@ -633,8 +635,10 @@ int ObjectRef::l_set_bone_override(lua_State *L)
lua_getfield(L, 3, "rotation");
if (!lua_isnil(L, -1)) {
lua_getfield(L, -1, "vec");
if (!lua_isnil(L, -1))
props.rotation.next = core::quaternion(check_v3f(L, -1));
if (!lua_isnil(L, -1)) {
props.rotation.next_radians = check_v3f(L, -1);
props.rotation.next = core::quaternion(props.rotation.next_radians);
}
lua_pop(L, 1);
read_prop_attrs(props.rotation);
@ -672,9 +676,9 @@ static void push_bone_override(lua_State *L, const BoneOverride &props)
push_prop("position", props.position, props.position.vector);
v3f euler_rot;
props.rotation.next.toEuler(euler_rot);
push_prop("rotation", props.rotation, euler_rot);
// In order to give modders back the euler angles they passed in,
// this **must not** compute equivalent euler angles from the quaternion
push_prop("rotation", props.rotation, props.rotation.next_radians);
push_prop("scale", props.scale, props.scale.vector);