mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 14:01:49 +00:00
fix gimbal lock
This commit is contained in:
parent
a8ec87bdea
commit
dbe1dfd380
1 changed files with 12 additions and 8 deletions
|
|
@ -13,14 +13,18 @@ local function calculate_item_drop_dir(pid)
|
||||||
if not hud.is_inventory_open() and not hud.is_player_inventory_open() then
|
if not hud.is_inventory_open() and not hud.is_player_inventory_open() then
|
||||||
mpos = {0, 0}
|
mpos = {0, 0}
|
||||||
end
|
end
|
||||||
pitch = math.clamp(pitch - mpos[2]*DROP_MAX_ITEM_DIR_SHIFT_DEGREES*2, -90, 90)
|
|
||||||
yaw = math.rad(yaw + 90 -mpos[1]*DROP_MAX_ITEM_DIR_SHIFT_DEGREES*2)
|
local q_yaw = quat.from_euler({0, yaw, 0})
|
||||||
pitch = math.rad(pitch)
|
local q_pitch = quat.from_euler({pitch, 0, 0})
|
||||||
return vec3.normalize({
|
local q_rotation = quat.mul(q_yaw, q_pitch)
|
||||||
math.cos(yaw) * math.cos(pitch),
|
|
||||||
math.sin(pitch),
|
local q_shift = quat.from_euler({
|
||||||
-math.sin(yaw) * math.cos(pitch)
|
-mpos[2]*DROP_MAX_ITEM_DIR_SHIFT_DEGREES*2,
|
||||||
})
|
-mpos[1]*DROP_MAX_ITEM_DIR_SHIFT_DEGREES*2,
|
||||||
|
0,
|
||||||
|
})
|
||||||
|
quat.mul(q_rotation, q_shift, q_rotation)
|
||||||
|
return quat.mul_vec3(q_rotation, {0, 0, -1})
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param mode integer 0 - whole stack, 1 - single item, 2 - dupe whole stack
|
---@param mode integer 0 - whole stack, 1 - single item, 2 - dupe whole stack
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue