mirror of https://github.com/AxioDL/zeus.git
Add toRGBA and toRGB5A3 to CColor
This commit is contained in:
parent
8e4dfb022a
commit
8410394d4b
|
@ -43,15 +43,12 @@ public:
|
|||
|
||||
constexpr CColor(float r, float g, float b, float a = 1.0f) : mSimd(r, g, b, a) {}
|
||||
|
||||
constexpr CColor(Comp32 rgba) : mSimd(((COLOR(rgba) >> 0) & 0xff) * OneOver255,
|
||||
((COLOR(rgba) >> 8) & 0xff) * OneOver255,
|
||||
((COLOR(rgba) >> 16) & 0xff) * OneOver255,
|
||||
((COLOR(rgba) >> 24) & 0xff) * OneOver255) {}
|
||||
constexpr CColor(Comp32 rgba)
|
||||
: mSimd(((COLOR(rgba) >> 0) & 0xff) * OneOver255, ((COLOR(rgba) >> 8) & 0xff) * OneOver255,
|
||||
((COLOR(rgba) >> 16) & 0xff) * OneOver255, ((COLOR(rgba) >> 24) & 0xff) * OneOver255) {}
|
||||
|
||||
constexpr CColor(const Comp8* rgba) : mSimd(rgba[0] * OneOver255,
|
||||
rgba[1] * OneOver255,
|
||||
rgba[2] * OneOver255,
|
||||
rgba[3] * OneOver255) {}
|
||||
constexpr CColor(const Comp8* rgba)
|
||||
: mSimd(rgba[0] * OneOver255, rgba[1] * OneOver255, rgba[2] * OneOver255, rgba[3] * OneOver255) {}
|
||||
|
||||
constexpr CColor(const CVector4f& other) : mSimd(other.mSimd) {}
|
||||
|
||||
|
@ -248,6 +245,28 @@ public:
|
|||
ao = Comp8(a() * 255);
|
||||
}
|
||||
|
||||
Comp32 toRGBA() const {
|
||||
RGBA32 ret;
|
||||
ret.r = r() * 255;
|
||||
ret.g = g() * 255;
|
||||
ret.b = b() * 255;
|
||||
ret.a = a() * 255;
|
||||
return ret.rgba;
|
||||
}
|
||||
|
||||
[[nodiscard]] unsigned short toRGB5A3() const {
|
||||
Comp8 r;
|
||||
Comp8 g;
|
||||
Comp8 b;
|
||||
Comp8 a;
|
||||
toRGBA8(r, g, b, a);
|
||||
if (a == 255) {
|
||||
return static_cast<unsigned short>((r & 0xf8) << 7 | (g & 0xf8) << 2 | b >> 3 | 0x8000);
|
||||
}
|
||||
|
||||
return static_cast<unsigned short>((r & 0xf0) << 4 | (g & 0xf0) | b >> 4 | (a & 0xe0) << 7);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Assigns rgba from hsv
|
||||
* @param h[0-1] The hue percentage of the color.
|
||||
|
@ -340,4 +359,4 @@ struct hash<zeus::CColor> {
|
|||
return ret;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace std
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
mSimd[3] = nd * mag;
|
||||
}
|
||||
|
||||
[[nodiscard]] float pointToPlaneDist(const CVector3f& pos) const { return pos.dot(normal()) - d(); }
|
||||
[[nodiscard]] float pointToPlaneDist(const CVector3f& pos) const { return normal().dot(pos) - d(); }
|
||||
|
||||
[[nodiscard]] bool rayPlaneIntersection(const CVector3f& from, const CVector3f& to, CVector3f& point) const;
|
||||
|
||||
|
|
|
@ -184,10 +184,10 @@ template <typename E>
|
|||
[[nodiscard]] bool close_enough(const CVector2f& a, const CVector2f& b, float epsilon = FLT_EPSILON);
|
||||
|
||||
[[nodiscard]] inline bool close_enough(float a, float b, double epsilon = FLT_EPSILON) {
|
||||
return std::fabs(a - b) < epsilon;
|
||||
return std::fabs(a - b) <= epsilon;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline bool close_enough(double a, double b, double epsilon = FLT_EPSILON) {
|
||||
return std::fabs(a - b) < epsilon;
|
||||
return std::fabs(a - b) <= epsilon;
|
||||
}
|
||||
} // namespace zeus
|
||||
|
|
|
@ -272,11 +272,11 @@ CVector3f baryToWorld(const CVector3f& p0, const CVector3f& p1, const CVector3f&
|
|||
}
|
||||
|
||||
bool close_enough(const CVector3f& a, const CVector3f& b, float epsilon) {
|
||||
return std::fabs(a.x() - b.x()) < epsilon && std::fabs(a.y() - b.y()) < epsilon && std::fabs(a.z() - b.z()) < epsilon;
|
||||
return std::fabs(a.x() - b.x()) <= epsilon && std::fabs(a.y() - b.y()) <= epsilon && std::fabs(a.z() - b.z()) <= epsilon;
|
||||
}
|
||||
|
||||
bool close_enough(const CVector2f& a, const CVector2f& b, float epsilon) {
|
||||
return std::fabs(a.x() - b.x()) < epsilon && std::fabs(a.y() - b.y()) < epsilon;
|
||||
return std::fabs(a.x() - b.x()) <= epsilon && std::fabs(a.y() - b.y()) <= epsilon;
|
||||
}
|
||||
|
||||
template <>
|
||||
|
|
Loading…
Reference in New Issue