-
Notifications
You must be signed in to change notification settings - Fork 0
/
Color.h
executable file
·49 lines (37 loc) · 1.68 KB
/
Color.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
////////////////////////////////////////
// Color.h
////////////////////////////////////////
#pragma once
#include <glm/glm.hpp>
////////////////////////////////////////////////////////////////////////////////
class Color {
public:
Color() {Red=Green=Blue=1.0;}
Color(float r,float g,float b) {Red=r; Green=g; Blue=b;}
void Set(float r,float g,float b) {Red=r; Green=g; Blue=b;}
void Add(const Color c) {Red+=c.Red; Green+=c.Green; Blue+=c.Blue;}
void AddScaled(const Color c,float s) {Red+=s*c.Red; Green+=s*c.Green; Blue+=s*c.Blue;}
void Scale(float s) {Red*=s; Green*=s; Blue*=s;}
void Scale(const Color c,float s) {Red=s*c.Red; Green=s*c.Green; Blue=s*c.Blue;}
void Multiply(const Color c) {Red*=c.Red; Green*=c.Green; Blue*=c.Blue;}
int ToInt() {
int r=(Red<0) ? 0 : ((Red>=1.0) ? 255 : int(Red*256.0f));
int g=(Green<0) ? 0 : ((Green>=1.0) ? 255 : int(Green*256.0f));
int b=(Blue<0) ? 0 : ((Blue>=1.0) ? 255 : int(Blue*256.0f));
return (r<<16) | (g<<8) | b;
}
void FromInt(int c) {Set(float((c>>16)&0xff)/255.0f,float((c>>8)&0xff)/255.0f,float(c&0xff)/255.0f);}
glm::vec3 ToVec(){ return glm::vec3(Red, Green, Blue); }
void FromVec(glm::vec3 c){ Red=c.r; Green=c.g; Blue=c.b; }
float getRed(){ return Red; }
float getGreen(){ return Green; }
float getBlue(){ return Blue; }
void setRed(float r){ Red = r; }
void setGreen(float g){ Green = g; }
void setBlue(float b){ Blue = b; }
static Color WHITE,GREY,BLACK;
static Color RED,YELLOW,BLUE,GREEN;
private:
float Red,Green,Blue;
};
////////////////////////////////////////////////////////////////////////////////