]> git.lizzy.rs Git - minetest.git/blobdiff - src/util/numeric.h
Initialize wield mesh colors when changing item. (#12254)
[minetest.git] / src / util / numeric.h
index bfdff84a0e878101fc066576a17b2ac0c77031e0..32a6f4312b04abc975a96021912fff965f8502de 100644 (file)
@@ -20,10 +20,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #pragma once
 
 #include "basic_macros.h"
+#include "constants.h"
 #include "irrlichttypes.h"
 #include "irr_v2d.h"
 #include "irr_v3d.h"
 #include "irr_aabb3d.h"
+#include "SColor.h"
+#include <matrix4.h>
 
 #define rangelim(d, min, max) ((d) < (min) ? (min) : ((d) > (max) ? (max) : (d)))
 #define myfloor(x) ((x) < 0.0 ? (int)(x) - 1 : (int)(x))
@@ -34,6 +37,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
        y = temp; \
 } while (0)
 
+// Maximum radius of a block.  The magic number is
+// sqrt(3.0) / 2.0 in literal form.
+static constexpr const f32 BLOCK_MAX_RADIUS = 0.866025403784f * MAP_BLOCKSIZE * BS;
 
 inline s16 getContainerPos(s16 p, s16 d)
 {
@@ -417,3 +423,26 @@ inline void wrappedApproachShortest(T &current, const T target, const T stepsize
                current = target;
        }
 }
+
+void setPitchYawRollRad(core::matrix4 &m, const v3f &rot);
+
+inline void setPitchYawRoll(core::matrix4 &m, const v3f &rot)
+{
+       setPitchYawRollRad(m, rot * core::DEGTORAD64);
+}
+
+v3f getPitchYawRollRad(const core::matrix4 &m);
+
+inline v3f getPitchYawRoll(const core::matrix4 &m)
+{
+       return getPitchYawRollRad(m) * core::RADTODEG64;
+}
+
+// Muliply the RGB value of a color linearly, and clamp to black/white
+inline irr::video::SColor multiplyColorValue(const irr::video::SColor &color, float mod)
+{
+       return irr::video::SColor(color.getAlpha(),
+                       core::clamp<u32>(color.getRed() * mod, 0, 255),
+                       core::clamp<u32>(color.getGreen() * mod, 0, 255),
+                       core::clamp<u32>(color.getBlue() * mod, 0, 255));
+}