-
Notifications
You must be signed in to change notification settings - Fork 0
/
Material.h
74 lines (69 loc) · 1.88 KB
/
Material.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Material.h
*
* Created on: 27 d�c. 2017
* Author: Ghassen_jlassi&Khalil_abid
*/
#ifndef MATERIAL_H_
#define MATERIAL_H_
class Material {
private:
float r_, g_,b_, shininess_;
public:
Material();
/*
@brief Material Constructor
@params red quantity , green quantity , blue quantity , shininess value
*/
Material(float r, float g, float b, float s);
/*
@brief getter of our class
*/
float getRed() const { return this->r_; }
float getGreen() const { return this->g_; }
float getBlue() const { return this->b_; }
float getShininess() const { return this->shininess_; }
/*
@brief setter of our class
*/
void setRed(double RValue) { r_ = RValue; }
void setGreen(double GValue) { g_ = GValue; }
void setBlue(double BValue) { b_ = BValue; }
void setShininess(double SValue) { shininess_ = SValue; }
public:
/*
@brief multiply the color by a given value
@params double scalar
*/
Material colorScalar(double scalar) {
return Material(r_*scalar, g_*scalar, b_*scalar, shininess_);
}
/*
@brief addition of two color
@params Material color
*/
Material colorAdd(Material color) {
return Material(r_ + color.getRed(), g_ + color.getGreen(), b_ + color.getBlue(), shininess_);
}
/*
@brief adjust the color of the light
@return the adjusted material
*/
Material clip() {
double alllight = r_ + g_ + b_;
double excesslight = alllight - 3;
if (excesslight > 0) {
r_ = r_ + excesslight*(r_ / alllight);
g_ = g_ + excesslight*(g_ / alllight);
b_ = b_ + excesslight*(b_ / alllight);
}
if (r_ > 1) { r_ = 1; }
if (g_ > 1) { g_ = 1; }
if (b_ > 1) { b_ = 1; }
if (r_ < 0) { r_ = 0; }
if (g_ < 0) { g_ = 0; }
if (b_ < 0) { b_ = 0; }
return Material(r_, g_, b_, shininess_);
}
};
#endif /* MATERIAL_H_ */