18template <
typename T,
typename T2,
typename T3>
20inline constexpr T
rangelim(
const T &d,
const T2 &min,
const T3 &max)
35 return (p >= 0 ? p : p - d + 1) / d;
74 container = (p >= 0 ? p : p - d + 1) / d;
94 p.X >= 0 && p.X < d &&
95 p.Y >= 0 && p.Y < d &&
103 p.X >= 0 && p.X < d &&
111 p.X >= 0 && p.X < d.X &&
112 p.Y >= 0 && p.Y < d.Y &&
113 p.Z >= 0 && p.Z < d.Z
121 std::swap(p1.X, p2.X);
123 std::swap(p1.Y, p2.Y);
125 std::swap(p1.Z, p2.Z);
130 const core::vector2d<T> &b)
132 return {std::min(a.X, b.X), std::min(a.Y, b.Y)};
137 const core::vector2d<T> &b)
139 return {std::max(a.X, b.X), std::max(a.Y, b.Y)};
144 const core::vector3d<T> &b)
146 return {std::min(a.X, b.X), std::min(a.Y, b.Y), std::min(a.Z, b.Z)};
151 const core::vector3d<T> &b)
153 return {std::max(a.X, b.X), std::max(a.Y, b.Y), std::max(a.Z, b.Z)};
212 return fmodf(f, 360.0f);
222 return value < 0 ? value + 360 : value;
237 value_v3f.X = value_v3f.X < 0 ? value_v3f.X + 360 : value_v3f.X;
238 value_v3f.Y = value_v3f.Y < 0 ? value_v3f.Y + 360 : value_v3f.Y;
239 value_v3f.Z = value_v3f.Z < 0 ? value_v3f.Z + 360 : value_v3f.Z;
258#define MYRAND_RANGE 0xffffffff
282 u32 mask = (1 << len) - 1;
283 return (
x >> pos) & mask;
288 u32 mask = (1 << len) - 1;
289 *
x &= ~(mask << pos);
290 *
x |= (val & mask) << pos;
299 return (0x6996 >> v) & 1;
321 const f32 camera_fov,
const f32 range, f32 *distance_ptr=
nullptr);
333 const f32 target_cos_sq,
const f32 adjdist,
const f32 range, f32 *distance_ptr);
353 const f32 target_cos = std::cos(camera_fov * 0.55f);
354 return target_cos * target_cos;
364 return (s32)(f < 0.f ? (f - 0.5f) : (f + 0.5f));
369inline constexpr T
sqr(T f)
381 (p.X + (p.X > 0 ? d / 2 : -d / 2)) / d,
382 (p.Y + (p.Y > 0 ? d / 2 : -d / 2)) / d,
383 (p.Z + (p.Z > 0 ? d / 2 : -d / 2)) / d);
393 (p.X + (p.X > 0 ? d / 2 : -d / 2)) / d,
394 (p.Y + (p.Y > 0 ? d / 2 : -d / 2)) / d,
395 (p.Z + (p.Z > 0 ? d / 2 : -d / 2)) / d);
404 return v3f::from(p) * d;
412 v3f::from(p) * d - 0.5f * d,
413 v3f::from(p) * d + 0.5f * d
429 bool step(
float dtime,
float wanted_interval)
444inline f32
damp(f32 a, f32 b, f32 lambda) {
445 return core::lerp(a, b, 1.0f - std::exp(-lambda));
450 return n != 0 && (n & (n - 1)) == 0;
473 unsigned s = b - a, l =
static_cast<unsigned>(maximum - b) + a + 1;
474 return std::min(s, l);
483 T delta = target - current;
487 if (delta > stepsize && maximum - delta > stepsize) {
488 current += (delta < maximum / 2) ? stepsize : -stepsize;
489 if (current >= maximum)
516 return video::SColor(color.getAlpha(),
517 core::clamp<u32>(color.getRed() * mod, 0, 255),
518 core::clamp<u32>(color.getGreen() * mod, 0, 255),
519 core::clamp<u32>(color.getBlue() * mod, 0, 255));
525 return v < 0 ? T(-v) : v;
531 return T(v < 0 ? -1 : (v == 0 ? 0 : 1));
535inline constexpr core::vector3d<T>
vecAbsolute(
const core::vector3d<T> &v)
545inline constexpr core::vector3d<T>
vecSign(
const core::vector3d<T> &v)
float m_accumulator
Definition numeric.h:439
IntervalLimiter()=default
bool step(float dtime, float wanted_interval)
Definition numeric.h:429
#define BS
Definition constants.h:61
#define MAP_BLOCKSIZE
Definition constants.h:64
core::aabbox3d< f32 > aabb3f
Definition irr_aabb3d.h:11
core::vector2d< s16 > v2s16
Definition irr_v2d.h:12
core::vector3d< double > v3d
Definition irr_v3d.h:12
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
core::vector3df v3f
Definition irr_v3d.h:11
v3f getPitchYawRollRad(const core::matrix4 &m)
Definition numeric.cpp:188
void mysrand(u64 seed)
Definition numeric.cpp:22
u64 murmur_hash_64_ua(const void *key, size_t len, unsigned int seed)
Calculate MurmurHash64A hash for an arbitrary block of data.
Definition numeric.cpp:49
bool isBlockInSightEx(const v3s16 blockpos_b, v3f camera_pos, v3f camera_dir, const f32 target_cos_sq, const f32 adjdist, f32 range, f32 *distance_ptr)
Definition numeric.cpp:95
void setPitchYawRollRad(core::matrix4 &m, v3f rot)
Definition numeric.cpp:167
u32 myrand()
Definition numeric.cpp:17
float adjustDist(float dist, float zoom_fov)
Definition numeric.cpp:150
bool isBlockInSight(const v3s16 blockpos_b, v3f camera_pos, v3f camera_dir, const f32 camera_fov, const f32 range, f32 *distance_ptr)
Definition numeric.cpp:89
float myrand_float()
Definition numeric.cpp:32
int myrand_range(int min, int max)
Definition numeric.cpp:38
void myrand_bytes(void *out, size_t len)
Definition numeric.cpp:27
constexpr core::vector3d< T > vecAbsolute(const core::vector3d< T > &v)
Definition numeric.h:535
s16 getContainerPos(s16 p, s16 d)
Definition numeric.h:33
constexpr core::vector2d< T > componentwise_min(const core::vector2d< T > &a, const core::vector2d< T > &b)
Definition numeric.h:129
constexpr T sqr(T f)
Definition numeric.h:369
bool isInArea(v3s16 p, s16 d)
Definition numeric.h:91
void wrappedApproachShortest(T ¤t, const T target, const T stepsize, const T maximum)
Definition numeric.h:480
v3s16 floatToInt(v3f p, f32 d)
Definition numeric.h:378
float wrapDegrees_0_360(float f)
Returns f wrapped to the range [0, 360].
Definition numeric.h:219
f32 damp(f32 a, f32 b, f32 lambda)
Definition numeric.h:444
constexpr core::vector3d< T > vecSign(const core::vector3d< T > &v)
Definition numeric.h:545
constexpr T numericAbsolute(T v)
Definition numeric.h:523
void setPitchYawRoll(core::matrix4 &m, v3f rot)
Definition numeric.h:500
void sortBoxVerticies(core::vector3d< T > &p1, core::vector3d< T > &p2)
Definition numeric.h:118
v3f getPitchYawRoll(const core::matrix4 &m)
Definition numeric.h:508
constexpr T rangelim(const T &d, const T2 &min, const T3 &max)
Definition numeric.h:20
v3f wrapDegrees_0_360_v3f(v3f v)
Returns v3f wrapped to the range [0, 360].
Definition numeric.h:229
void set_bits(u32 *x, u32 pos, u32 len, u32 val)
Definition numeric.h:286
constexpr core::vector2d< T > componentwise_max(const core::vector2d< T > &a, const core::vector2d< T > &b)
Definition numeric.h:136
f32 getFovAdj(f32 camera_fov)
Definition numeric.h:338
u32 myrand()
Definition numeric.cpp:17
v3f intToFloat(v3s16 p, f32 d)
Definition numeric.h:402
u32 get_bits(u32 x, u32 pos, u32 len)
Definition numeric.h:280
static constexpr const f32 BLOCK_MAX_RADIUS
Definition numeric.h:31
unsigned wrappedDifference(T a, T b, const T maximum)
Definition numeric.h:468
float modulo360f(float f)
Returns f wrapped to the range [-360, 360].
Definition numeric.h:210
v3s16 doubleToInt(v3d p, double d)
Definition numeric.h:390
#define MYRAND_RANGE
Definition numeric.h:258
float wrapDegrees_180(float f)
Returns f wrapped to the range [-180, 180].
Definition numeric.h:247
aabb3f getNodeBox(v3s16 p, float d)
Definition numeric.h:409
void getContainerPosWithOffset(s16 p, s16 d, s16 &container, s16 &offset)
Definition numeric.h:72
f32 getFovCosSq(f32 camera_fov)
Definition numeric.h:347
video::SColor multiplyColorValue(const video::SColor &color, float mod)
Definition numeric.h:514
constexpr bool is_power_of_two(u32 n)
Definition numeric.h:448
constexpr u32 npot2(u32 orig)
Definition numeric.h:455
s32 myround(f32 f)
Definition numeric.h:362
constexpr T numericSign(T v)
Definition numeric.h:529
u32 calc_parity(u32 v)
Definition numeric.h:293
Describes a grid with given step, originating at (0,0,0).
Definition numeric.h:157
bool isMeshPos(v3s16 &p) const
Returns true if p is an origin of a cell in the grid.
Definition numeric.h:187
v3s16 getMeshPos(v3s16 p) const
Returns coordinates of the origin of the grid cell containing p.
Definition numeric.h:181
u16 cell_size
Definition numeric.h:158
s16 getCellPos(s16 p) const
returns coordinate of mesh cell given coordinate of a map block
Definition numeric.h:163
u32 getCellVolume() const
Definition numeric.h:160
v3s16 getCellPos(v3s16 block_pos) const
returns position of mesh cell in the grid given position of a map block
Definition numeric.h:169
s16 getMeshPos(s16 p) const
returns closest step of the grid smaller than p
Definition numeric.h:175
u16 getOffsetIndex(v3s16 offset) const
Returns index of the given offset in a grid cell All offset coordinates must be smaller than the size...
Definition numeric.h:196
static constexpr result_type max()
Definition numeric.h:270
u32 result_type
Definition numeric.h:268
static constexpr result_type min()
Definition numeric.h:269
result_type operator()()
Definition numeric.h:271
constexpr v3f x
Definition test_irr_matrix4.cpp:18