Files
Cubed/include/glm/gtx/fast_trigonometry.inl
zhenyan121 def311c7dd feature: hud (#37)
* 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
2026-07-23 14:07:11 +08:00

143 lines
4.1 KiB
C++

/// @ref gtx_fast_trigonometry
namespace glm{
namespace detail
{
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, T, Q> taylorCos(vec<L, T, Q> const& x)
{
return static_cast<T>(1)
- (x * x) * (1.f / 2.f)
+ ((x * x) * (x * x)) * (1.f / 24.f)
- (((x * x) * (x * x)) * (x * x)) * (1.f / 720.f)
+ (((x * x) * (x * x)) * ((x * x) * (x * x))) * (1.f / 40320.f);
}
template<typename T>
GLM_FUNC_QUALIFIER T cos_52s(T x)
{
T const xx(x * x);
return (T(0.9999932946) + xx * (T(-0.4999124376) + xx * (T(0.0414877472) + xx * T(-0.0012712095))));
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, T, Q> cos_52s(vec<L, T, Q> const& x)
{
return detail::functor1<vec, L, T, T, Q>::call(cos_52s, x);
}
}//namespace detail
// wrapAngle
template<typename T>
GLM_FUNC_QUALIFIER T wrapAngle(T angle)
{
return abs<T>(mod<T>(angle, two_pi<T>()));
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, T, Q> wrapAngle(vec<L, T, Q> const& x)
{
return detail::functor1<vec, L, T, T, Q>::call(wrapAngle, x);
}
// cos
template<typename T>
GLM_FUNC_QUALIFIER T fastCos(T x)
{
T const angle(wrapAngle<T>(x));
if(angle < half_pi<T>())
return detail::cos_52s(angle);
if(angle < pi<T>())
return -detail::cos_52s(pi<T>() - angle);
if(angle < (T(3) * half_pi<T>()))
return -detail::cos_52s(angle - pi<T>());
return detail::cos_52s(two_pi<T>() - angle);
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, T, Q> fastCos(vec<L, T, Q> const& x)
{
return detail::functor1<vec, L, T, T, Q>::call(fastCos, x);
}
// sin
template<typename T>
GLM_FUNC_QUALIFIER T fastSin(T x)
{
return fastCos<T>(half_pi<T>() - x);
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, T, Q> fastSin(vec<L, T, Q> const& x)
{
return detail::functor1<vec, L, T, T, Q>::call(fastSin, x);
}
// tan
template<typename T>
GLM_FUNC_QUALIFIER T fastTan(T x)
{
return x + (x * x * x * T(0.3333333333)) + (x * x * x * x * x * T(0.1333333333333)) + (x * x * x * x * x * x * x * T(0.0539682539));
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, T, Q> fastTan(vec<L, T, Q> const& x)
{
return detail::functor1<vec, L, T, T, Q>::call(fastTan, x);
}
// asin
template<typename T>
GLM_FUNC_QUALIFIER T fastAsin(T x)
{
return x + (x * x * x * T(0.166666667)) + (x * x * x * x * x * T(0.075)) + (x * x * x * x * x * x * x * T(0.0446428571)) + (x * x * x * x * x * x * x * x * x * T(0.0303819444));// + (x * x * x * x * x * x * x * x * x * x * x * T(0.022372159));
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, T, Q> fastAsin(vec<L, T, Q> const& x)
{
return detail::functor1<vec, L, T, T, Q>::call(fastAsin, x);
}
// acos
template<typename T>
GLM_FUNC_QUALIFIER T fastAcos(T x)
{
return T(1.5707963267948966192313216916398) - fastAsin(x); //(PI / 2)
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, T, Q> fastAcos(vec<L, T, Q> const& x)
{
return detail::functor1<vec, L, T, T, Q>::call(fastAcos, x);
}
// atan
template<typename T>
GLM_FUNC_QUALIFIER T fastAtan(T y, T x)
{
T sgn = sign(y) * sign(x);
return abs(fastAtan(y / x)) * sgn;
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, T, Q> fastAtan(vec<L, T, Q> const& y, vec<L, T, Q> const& x)
{
return detail::functor2<vec, L, T, Q>::call(fastAtan, y, x);
}
template<typename T>
GLM_FUNC_QUALIFIER T fastAtan(T x)
{
return x - (x * x * x * T(0.333333333333)) + (x * x * x * x * x * T(0.2)) - (x * x * x * x * x * x * x * T(0.1428571429)) + (x * x * x * x * x * x * x * x * x * T(0.111111111111)) - (x * x * x * x * x * x * x * x * x * x * x * T(0.0909090909));
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, T, Q> fastAtan(vec<L, T, Q> const& x)
{
return detail::functor1<vec, L, T, T, Q>::call(fastAtan, x);
}
}//namespace glm