Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
Color.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
8
9class Color;
10
13
16{
17public:
19
21 Color() = default;
22 Color(const Color &inRHS) = default;
23 Color & operator = (const Color &inRHS) = default;
24 explicit constexpr Color(uint32 inColor) : mU32(inColor) { }
25 constexpr Color(uint8 inRed, uint8 inGreen, uint8 inBlue, uint8 inAlpha = 255) : r(inRed), g(inGreen), b(inBlue), a(inAlpha) { }
26 constexpr Color(ColorArg inRHS, uint8 inAlpha) : r(inRHS.r), g(inRHS.g), b(inRHS.b), a(inAlpha) { }
27
29 inline bool operator == (ColorArg inRHS) const { return mU32 == inRHS.mU32; }
30 inline bool operator != (ColorArg inRHS) const { return mU32 != inRHS.mU32; }
31
33 uint32 GetUInt32() const { return mU32; }
34
36 inline uint8 operator () (uint inIdx) const { JPH_ASSERT(inIdx < 4); return (&r)[inIdx]; }
37 inline uint8 & operator () (uint inIdx) { JPH_ASSERT(inIdx < 4); return (&r)[inIdx]; }
38
40 inline Color operator * (const Color &inRHS) const { return Color(uint8((uint32(r) * inRHS.r) >> 8), uint8((uint32(g) * inRHS.g) >> 8), uint8((uint32(b) * inRHS.b) >> 8), uint8((uint32(a) * inRHS.a) >> 8)); }
41
43 inline Color operator * (float inIntensity) const { return Color(uint8(r * inIntensity), uint8(g * inIntensity), uint8(b * inIntensity), a); }
44
46 inline Vec4 ToVec4() const { return Vec4(r, g, b, a) / 255.0f; }
47
49 inline uint8 GetIntensity() const { return uint8((uint32(r) * 54 + g * 183 + b * 19) >> 8); }
50
52 static Color sGetDistinctColor(int inIndex);
53
56 static Color sGreenRedGradient(float inValue)
57 {
58 if (inValue < 0.0f)
59 return Color::sGreen;
60 else if (inValue < 0.5f)
61 return Color(uint8(510.0f * inValue), 255, 0);
62 else if (inValue < 1.0f)
63 return Color(255, uint8(510.0f * (1.0f - inValue)), 0);
64 else
65 return Color::sRed;
66 }
67
69 static const Color sBlack;
70 static const Color sDarkRed;
71 static const Color sRed;
72 static const Color sDarkGreen;
73 static const Color sGreen;
74 static const Color sDarkBlue;
75 static const Color sBlue;
76 static const Color sYellow;
77 static const Color sPurple;
78 static const Color sCyan;
79 static const Color sOrange;
80 static const Color sDarkOrange;
81 static const Color sGrey;
82 static const Color sLightGrey;
83 static const Color sWhite;
84
85 union
86 {
88 struct
89 {
94 };
95 };
96};
97
98static_assert(std::is_trivially_default_constructible<Color>() && std::is_trivially_copyable<Color>(), "Is supposed to be a trivial type!");
99
std::uint8_t uint8
Definition Core.h:565
unsigned int uint
Definition Core.h:564
#define JPH_NAMESPACE_END
Definition Core.h:487
std::uint32_t uint32
Definition Core.h:567
#define JPH_EXPORT_GCC_BUG_WORKAROUND
Definition Core.h:310
#define JPH_NAMESPACE_BEGIN
Definition Core.h:481
DVec3 operator*(double inV1, DVec3Arg inV2)
Definition DVec3.inl:623
#define JPH_ASSERT(...)
Definition IssueReporting.h:28
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:51
Class that holds an RGBA color with 8-bits per component.
Definition Color.h:16
static Color sGreenRedGradient(float inValue)
Definition Color.h:56
static const Color sDarkRed
Definition Color.h:70
uint8 b
Blue channel.
Definition Color.h:92
static const Color sBlack
Predefined colors.
Definition Color.h:69
uint32 mU32
Combined value for red, green, blue and alpha.
Definition Color.h:87
static const Color sBlue
Definition Color.h:75
constexpr Color(ColorArg inRHS, uint8 inAlpha)
Definition Color.h:26
static const Color sPurple
Definition Color.h:77
static const Color sGreen
Definition Color.h:73
static const Color sWhite
Definition Color.h:83
uint8 a
Alpha channel.
Definition Color.h:93
constexpr Color(uint32 inColor)
Definition Color.h:24
static const Color sDarkOrange
Definition Color.h:80
uint8 g
Green channel.
Definition Color.h:91
static const Color sLightGrey
Definition Color.h:82
static const Color sOrange
Definition Color.h:79
static const Color sDarkBlue
Definition Color.h:74
JPH_OVERRIDE_NEW_DELETE Color()=default
Constructors.
Color(const Color &inRHS)=default
Vec4 ToVec4() const
Convert to Vec4 with range [0, 1].
Definition Color.h:46
uint8 r
Red channel.
Definition Color.h:90
static const Color sDarkGreen
Definition Color.h:72
static const Color sGrey
Definition Color.h:81
static const Color sCyan
Definition Color.h:78
uint32 GetUInt32() const
Convert to uint32.
Definition Color.h:33
static const Color sRed
Definition Color.h:71
static const Color sYellow
Definition Color.h:76
uint8 GetIntensity() const
Get grayscale intensity of color.
Definition Color.h:49
constexpr Color(uint8 inRed, uint8 inGreen, uint8 inBlue, uint8 inAlpha=255)
Definition Color.h:25
Definition Vec4.h:14