Files
XCEngine/engine/src/Math/Color.cpp
ssdfasd 7c54a62f9e feat: 添加Math库和Google Test测试框架
- 新增Math库: Vector2/3/4, Matrix3/4, Quaternion, Transform, Color等
- 新增测试框架: Google Test (gtest)
- 新增140个单元测试,覆盖Vector, Matrix, Quaternion, Geometry
- VolumeRenderer支持vcpkg的NanoVDB
- 添加TESTING.md测试文档
2026-03-13 18:43:14 +08:00

50 lines
1.3 KiB
C++

#include "Math/Color.h"
namespace XCEngine {
namespace Math {
Color Color::Lerp(const Color& a, const Color& b, float t) {
t = std::clamp(t, 0.0f, 1.0f);
return Color(
a.r + (b.r - a.r) * t,
a.g + (b.g - a.g) * t,
a.b + (b.b - a.b) * t,
a.a + (b.a - a.a) * t
);
}
uint32_t Color::ToRGBA() const {
uint32_t r = static_cast<uint32_t>(std::clamp(r * 255.0f, 0.0f, 255.0f));
uint32_t g = static_cast<uint32_t>(std::clamp(g * 255.0f, 0.0f, 255.0f));
uint32_t b = static_cast<uint32_t>(std::clamp(b * 255.0f, 0.0f, 255.0f));
uint32_t a = static_cast<uint32_t>(std::clamp(a * 255.0f, 0.0f, 255.0f));
return (r << 24) | (g << 16) | (b << 8) | a;
}
Vector3 Color::ToVector3() const {
return Vector3(r, g, b);
}
Vector4 Color::ToVector4() const {
return Vector4(r, g, b, a);
}
Color Color::operator+(const Color& other) const {
return Color(r + other.r, g + other.g, b + other.b, a + other.a);
}
Color Color::operator-(const Color& other) const {
return Color(r - other.r, g - other.g, b - other.b, a - other.a);
}
Color Color::operator*(float scalar) const {
return Color(r * scalar, g * scalar, b * scalar, a * scalar);
}
Color Color::operator/(float scalar) const {
return Color(r / scalar, g / scalar, b / scalar, a / scalar);
}
} // namespace Math
} // namespace XCEngine