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

Allow setting custom third person front view camera offset (#13686)

Co-authored-by: Muhammad Rifqi Priyo Susanto <muhammadrifqipriyosusanto@gmail.com>
Co-authored-by: SmallJoker <SmallJoker@users.noreply.github.com>
This commit is contained in:
Gregor Parzefall 2023-10-02 13:44:03 +02:00 committed by GitHub
parent 3a4bf14c20
commit 33cc29bbda
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 41 additions and 22 deletions

View file

@ -435,7 +435,7 @@ int ObjectRef::l_get_local_animation(lua_State *L)
return 5;
}
// set_eye_offset(self, firstperson, thirdperson)
// set_eye_offset(self, firstperson, thirdperson_back, thirdperson_front)
int ObjectRef::l_set_eye_offset(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
@ -446,14 +446,19 @@ int ObjectRef::l_set_eye_offset(lua_State *L)
v3f offset_first = readParam<v3f>(L, 2, v3f(0, 0, 0));
v3f offset_third = readParam<v3f>(L, 3, v3f(0, 0, 0));
v3f offset_third_front = readParam<v3f>(L, 4, offset_third);
// Prevent abuse of offset values (keep player always visible)
offset_third.X = rangelim(offset_third.X,-10,10);
offset_third.Z = rangelim(offset_third.Z,-5,5);
/* TODO: if possible: improve the camera collision detection to allow Y <= -1.5) */
offset_third.Y = rangelim(offset_third.Y,-10,15); //1.5*BS
auto clamp_third = [] (v3f &vec) {
vec.X = rangelim(vec.X, -10, 10);
vec.Z = rangelim(vec.Z, -5, 5);
/* TODO: if possible: improve the camera collision detection to allow Y <= -1.5) */
vec.Y = rangelim(vec.Y, -10, 15); // 1.5 * BS
};
clamp_third(offset_third);
clamp_third(offset_third_front);
getServer(L)->setPlayerEyeOffset(player, offset_first, offset_third);
getServer(L)->setPlayerEyeOffset(player, offset_first, offset_third, offset_third_front);
return 0;
}
@ -468,7 +473,8 @@ int ObjectRef::l_get_eye_offset(lua_State *L)
push_v3f(L, player->eye_offset_first);
push_v3f(L, player->eye_offset_third);
return 2;
push_v3f(L, player->eye_offset_third_front);
return 3;
}
// send_mapblock(self, pos)