From eb052e3df5bcf0e84f9ab8f311f120ddb1e46c7e Mon Sep 17 00:00:00 2001 From: Alexsandro Percy Date: Sun, 25 Jun 2023 19:19:28 -0300 Subject: [PATCH] added method to update head position for the pilot --- lib_planes/entities.lua | 8 +++++++- lib_planes/utilities.lua | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib_planes/entities.lua b/lib_planes/entities.lua index 39d9475..24d36ba 100644 --- a/lib_planes/entities.lua +++ b/lib_planes/entities.lua @@ -229,7 +229,7 @@ function airutils.logic(self) --is an stall, force a recover if longit_speed < (self._min_speed+0.5) and climb_rate < -1.5 and is_flying then if player and self.driver_name then - minetest.chat_send_player(self.driver_name,core.colorize('#ff0000', " >>> STALL")) + --minetest.chat_send_player(self.driver_name,core.colorize('#ff0000', " >>> STALL")) end self._elevator_angle = 0 self._angle_of_attack = -1 @@ -419,6 +419,7 @@ function airutils.logic(self) local indicated_speed = longit_speed * 0.9 if indicated_speed < 0 then indicated_speed = 0 end self._indicated_speed = indicated_speed + local speed_angle = supercub.get_gauge_angle(indicated_speed, -45) --adjust power indicator local power_indicator_angle = airutils.get_gauge_angle(self._power_lever/10) @@ -440,6 +441,11 @@ function airutils.logic(self) newyaw = yaw + yaw_turn end + if player then + local new_eye_offset = airutils.camera_reposition(player, newpitch, math.rad(self._rudder_angle)) + player:set_eye_offset(new_eye_offset, {x = 0, y = 1, z = -30}) + end + --apply rotations self.object:set_rotation({x=newpitch,y=newyaw,z=newroll}) --end diff --git a/lib_planes/utilities.lua b/lib_planes/utilities.lua index a31ff92..dd02eb2 100644 --- a/lib_planes/utilities.lua +++ b/lib_planes/utilities.lua @@ -519,3 +519,23 @@ function airutils.add_destruction_effects(pos, radius) texture = "airutils_smoke.png", }) end + +function airutils.get_xz_from_hipotenuse(orig_x, orig_z, yaw, distance) + --cara, o minetest é bizarro, ele considera o eixo no sentido ANTI-HORÁRIO... Então pra equação funcionar, subtrair o angulo de 360 antes + yaw = math.rad(360) - yaw + local z = (math.cos(yaw)*distance) + orig_z + local x = (math.sin(yaw)*distance) + orig_x + return x, z +end + +function airutils.camera_reposition(player, pitch, roll) + local player_properties = player:get_properties() + local new_eye_offset = vector.new() + local z, y = airutils.get_xz_from_hipotenuse(0, player_properties.eye_height, pitch, player_properties.eye_height) + new_eye_offset.z = z + new_eye_offset.y = y + local x, _ = airutils.get_xz_from_hipotenuse(0, player_properties.eye_height, roll, player_properties.eye_height) + new_eye_offset.x = x*7 + return new_eye_offset +end +