mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
* build: replace FetchContent with direct includes for glm * build(deps): replace SOIL2 with stb for image and vorbis decoding * build: replace FetchContent with direct includes for toml++ * refactor(texture): bump block texture size to 512 and disable items tab * feat: add hotbar system with ItemStack and RowLayout * fix(ui): restrict Ctrl key handling to typing mode * feat(ui): add widget border support and highlight selected hotbar slot * fix(ui): update borders on scale change and correct Image width - Added update_border() calls in set_scale() for Button, ChatBox, Image, Label, and TextField. - Fixed Image::width() to multiply by width instead of height. - Added early return in Widget::update_border() if border is not supported. * feat(ui): add border visual feedback on slider drag * feat(ui): add ItemSlot widget and refactor hotbar to use it * feat(world_scene): add inventory UI and pause type enum * feat(ui): add item slot tooltip and make window size static * fix(ui label): account for background offset in width/height * refactor(ui): centralize item info label in inventory and add update * feat(ui): add hotbar interaction in inventory UI * fix(inventory-ui): correct row creation logic for first item The loop starting at index 0 created a new row on the first iteration (i % 10 == 0). Shift the loop to start at 1 and adjust modulus condition to create rows correctly every 10 items. * feat(block): add name_key for localized block names Add `name_key` field to all block TOML definitions, enabling per-block localization. Update `BlockData` struct and `BlockManager` with `local_name()` method that returns a localized string via the translation system. Add corresponding entries to `en_US.json` and `zh_CN.json`. Modify inventory UI to use the localized name when displaying block info, and fix a bug where emptying a hotbar slot did not clear the item locally. * fix(ui): change inventory item slot color from white to gray * fix(ui): add missing include for std::array
208 lines
7.4 KiB
C++
208 lines
7.4 KiB
C++
namespace glm
|
|
{
|
|
template<typename genType>
|
|
GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType identity()
|
|
{
|
|
return detail::init_gentype<genType, detail::genTypeTrait<genType>::GENTYPE>::identity();
|
|
}
|
|
|
|
template<typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER GLM_CONSTEXPR mat<4, 4, T, Q> translate(mat<4, 4, T, Q> const& m, vec<3, T, Q> const& v)
|
|
{
|
|
mat<4, 4, T, Q> Result(m);
|
|
Result[3] = m[0] * v[0] + m[1] * v[1] + m[2] * v[2] + m[3];
|
|
return Result;
|
|
}
|
|
|
|
template<typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER mat<4, 4, T, Q> rotate(mat<4, 4, T, Q> const& m, T angle, vec<3, T, Q> const& v)
|
|
{
|
|
T const a = angle;
|
|
T const c = cos(a);
|
|
T const s = sin(a);
|
|
|
|
vec<3, T, Q> axis(normalize(v));
|
|
vec<3, T, Q> temp((T(1) - c) * axis);
|
|
|
|
mat<4, 4, T, Q> Rotate;
|
|
Rotate[0][0] = c + temp[0] * axis[0];
|
|
Rotate[0][1] = temp[0] * axis[1] + s * axis[2];
|
|
Rotate[0][2] = temp[0] * axis[2] - s * axis[1];
|
|
|
|
Rotate[1][0] = temp[1] * axis[0] - s * axis[2];
|
|
Rotate[1][1] = c + temp[1] * axis[1];
|
|
Rotate[1][2] = temp[1] * axis[2] + s * axis[0];
|
|
|
|
Rotate[2][0] = temp[2] * axis[0] + s * axis[1];
|
|
Rotate[2][1] = temp[2] * axis[1] - s * axis[0];
|
|
Rotate[2][2] = c + temp[2] * axis[2];
|
|
|
|
mat<4, 4, T, Q> Result;
|
|
Result[0] = m[0] * Rotate[0][0] + m[1] * Rotate[0][1] + m[2] * Rotate[0][2];
|
|
Result[1] = m[0] * Rotate[1][0] + m[1] * Rotate[1][1] + m[2] * Rotate[1][2];
|
|
Result[2] = m[0] * Rotate[2][0] + m[1] * Rotate[2][1] + m[2] * Rotate[2][2];
|
|
Result[3] = m[3];
|
|
return Result;
|
|
}
|
|
|
|
template<typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER mat<4, 4, T, Q> rotate_slow(mat<4, 4, T, Q> const& m, T angle, vec<3, T, Q> const& v)
|
|
{
|
|
T const a = angle;
|
|
T const c = cos(a);
|
|
T const s = sin(a);
|
|
mat<4, 4, T, Q> Result;
|
|
|
|
vec<3, T, Q> axis = normalize(v);
|
|
|
|
Result[0][0] = c + (static_cast<T>(1) - c) * axis.x * axis.x;
|
|
Result[0][1] = (static_cast<T>(1) - c) * axis.x * axis.y + s * axis.z;
|
|
Result[0][2] = (static_cast<T>(1) - c) * axis.x * axis.z - s * axis.y;
|
|
Result[0][3] = static_cast<T>(0);
|
|
|
|
Result[1][0] = (static_cast<T>(1) - c) * axis.y * axis.x - s * axis.z;
|
|
Result[1][1] = c + (static_cast<T>(1) - c) * axis.y * axis.y;
|
|
Result[1][2] = (static_cast<T>(1) - c) * axis.y * axis.z + s * axis.x;
|
|
Result[1][3] = static_cast<T>(0);
|
|
|
|
Result[2][0] = (static_cast<T>(1) - c) * axis.z * axis.x + s * axis.y;
|
|
Result[2][1] = (static_cast<T>(1) - c) * axis.z * axis.y - s * axis.x;
|
|
Result[2][2] = c + (static_cast<T>(1) - c) * axis.z * axis.z;
|
|
Result[2][3] = static_cast<T>(0);
|
|
|
|
Result[3] = vec<4, T, Q>(0, 0, 0, 1);
|
|
return m * Result;
|
|
}
|
|
|
|
template<typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER mat<4, 4, T, Q> scale(mat<4, 4, T, Q> const& m, vec<3, T, Q> const& v)
|
|
{
|
|
mat<4, 4, T, Q> Result;
|
|
Result[0] = m[0] * v[0];
|
|
Result[1] = m[1] * v[1];
|
|
Result[2] = m[2] * v[2];
|
|
Result[3] = m[3];
|
|
return Result;
|
|
}
|
|
|
|
template<typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER mat<4, 4, T, Q> scale_slow(mat<4, 4, T, Q> const& m, vec<3, T, Q> const& v)
|
|
{
|
|
mat<4, 4, T, Q> Result(T(1));
|
|
Result[0][0] = v.x;
|
|
Result[1][1] = v.y;
|
|
Result[2][2] = v.z;
|
|
return m * Result;
|
|
}
|
|
|
|
template <typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER mat<4, 4, T, Q> shear(mat<4, 4, T, Q> const &m, vec<3, T, Q> const& p, vec<2, T, Q> const &l_x, vec<2, T, Q> const &l_y, vec<2, T, Q> const &l_z)
|
|
{
|
|
T const lambda_xy = l_x[0];
|
|
T const lambda_xz = l_x[1];
|
|
T const lambda_yx = l_y[0];
|
|
T const lambda_yz = l_y[1];
|
|
T const lambda_zx = l_z[0];
|
|
T const lambda_zy = l_z[1];
|
|
|
|
vec<3, T, Q> point_lambda = vec<3, T, Q>(
|
|
(lambda_xy + lambda_xz), (lambda_yx + lambda_yz), (lambda_zx + lambda_zy)
|
|
);
|
|
|
|
mat<4, 4, T, Q> Shear = mat<4, 4, T, Q>(
|
|
1 , lambda_yx , lambda_zx , 0,
|
|
lambda_xy , 1 , lambda_zy , 0,
|
|
lambda_xz , lambda_yz , 1 , 0,
|
|
-point_lambda[0] * p[0], -point_lambda[1] * p[1], -point_lambda[2] * p[2], 1
|
|
);
|
|
|
|
mat<4, 4, T, Q> Result;
|
|
Result[0] = m[0] * Shear[0][0] + m[1] * Shear[0][1] + m[2] * Shear[0][2] + m[3] * Shear[0][3];
|
|
Result[1] = m[0] * Shear[1][0] + m[1] * Shear[1][1] + m[2] * Shear[1][2] + m[3] * Shear[1][3];
|
|
Result[2] = m[0] * Shear[2][0] + m[1] * Shear[2][1] + m[2] * Shear[2][2] + m[3] * Shear[2][3];
|
|
Result[3] = m[0] * Shear[3][0] + m[1] * Shear[3][1] + m[2] * Shear[3][2] + m[3] * Shear[3][3];
|
|
return Result;
|
|
}
|
|
|
|
template <typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER mat<4, 4, T, Q> shear_slow(mat<4, 4, T, Q> const &m, vec<3, T, Q> const& p, vec<2, T, Q> const &l_x, vec<2, T, Q> const &l_y, vec<2, T, Q> const &l_z)
|
|
{
|
|
T const lambda_xy = static_cast<T>(l_x[0]);
|
|
T const lambda_xz = static_cast<T>(l_x[1]);
|
|
T const lambda_yx = static_cast<T>(l_y[0]);
|
|
T const lambda_yz = static_cast<T>(l_y[1]);
|
|
T const lambda_zx = static_cast<T>(l_z[0]);
|
|
T const lambda_zy = static_cast<T>(l_z[1]);
|
|
|
|
vec<3, T, Q> point_lambda = vec<3, T, Q>(
|
|
static_cast<T>(lambda_xy + lambda_xz),
|
|
static_cast<T>(lambda_yx + lambda_yz),
|
|
static_cast<T>(lambda_zx + lambda_zy)
|
|
);
|
|
|
|
mat<4, 4, T, Q> Shear = mat<4, 4, T, Q>(
|
|
1 , lambda_yx , lambda_zx , 0,
|
|
lambda_xy , 1 , lambda_zy , 0,
|
|
lambda_xz , lambda_yz , 1 , 0,
|
|
-point_lambda[0] * p[0], -point_lambda[1] * p[1], -point_lambda[2] * p[2], 1
|
|
);
|
|
return m * Shear;
|
|
}
|
|
|
|
template<typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER mat<4, 4, T, Q> lookAtRH(vec<3, T, Q> const& eye, vec<3, T, Q> const& center, vec<3, T, Q> const& up)
|
|
{
|
|
vec<3, T, Q> const f(normalize(center - eye));
|
|
vec<3, T, Q> const s(normalize(cross(f, up)));
|
|
vec<3, T, Q> const u(cross(s, f));
|
|
|
|
mat<4, 4, T, Q> Result(1);
|
|
Result[0][0] = s.x;
|
|
Result[1][0] = s.y;
|
|
Result[2][0] = s.z;
|
|
Result[0][1] = u.x;
|
|
Result[1][1] = u.y;
|
|
Result[2][1] = u.z;
|
|
Result[0][2] =-f.x;
|
|
Result[1][2] =-f.y;
|
|
Result[2][2] =-f.z;
|
|
Result[3][0] =-dot(s, eye);
|
|
Result[3][1] =-dot(u, eye);
|
|
Result[3][2] = dot(f, eye);
|
|
return Result;
|
|
}
|
|
|
|
template<typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER mat<4, 4, T, Q> lookAtLH(vec<3, T, Q> const& eye, vec<3, T, Q> const& center, vec<3, T, Q> const& up)
|
|
{
|
|
vec<3, T, Q> const f(normalize(center - eye));
|
|
vec<3, T, Q> const s(normalize(cross(up, f)));
|
|
vec<3, T, Q> const u(cross(f, s));
|
|
|
|
mat<4, 4, T, Q> Result(1);
|
|
Result[0][0] = s.x;
|
|
Result[1][0] = s.y;
|
|
Result[2][0] = s.z;
|
|
Result[0][1] = u.x;
|
|
Result[1][1] = u.y;
|
|
Result[2][1] = u.z;
|
|
Result[0][2] = f.x;
|
|
Result[1][2] = f.y;
|
|
Result[2][2] = f.z;
|
|
Result[3][0] = -dot(s, eye);
|
|
Result[3][1] = -dot(u, eye);
|
|
Result[3][2] = -dot(f, eye);
|
|
return Result;
|
|
}
|
|
|
|
template<typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER mat<4, 4, T, Q> lookAt(vec<3, T, Q> const& eye, vec<3, T, Q> const& center, vec<3, T, Q> const& up)
|
|
{
|
|
# if (GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT)
|
|
return lookAtLH(eye, center, up);
|
|
# else
|
|
return lookAtRH(eye, center, up);
|
|
# endif
|
|
}
|
|
}//namespace glm
|