NGL  6.5
The NCCA Graphics Library
Colour.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Jon Macey
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received m_a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include "Colour.h"
18 //----------------------------------------------------------------------------------------------------------------------
21 //----------------------------------------------------------------------------------------------------------------------
22 namespace ngl
23 {
24 
25 
26 //----------------------------------------------------------------------------------------------------------------------
27 void Colour ::add(const Colour& _src, const Colour& _refl ) noexcept
28 { // add the product of source color and reflection coefficient
29  m_r += _src.m_r * _refl.m_r;
30  m_g += _src.m_g * _refl.m_g;
31  m_b += _src.m_b * _refl.m_b;
32  m_a += _src.m_a * _refl.m_a;
33 }
34 
35 //----------------------------------------------------------------------------------------------------------------------
36 Colour Colour::operator +( const Colour &_c ) const noexcept
37 {
38  return Colour( m_r + _c.m_r,
39  m_g + _c.m_g,
40  m_b + _c.m_b,
41  m_a + _c.m_a );
42 }
43 
44 //----------------------------------------------------------------------------------------------------------------------
45 Colour Colour::operator -( const Colour& _c ) const noexcept
46 {
47  return Colour( m_r - _c.m_r,
48  m_g - _c.m_g,
49  m_b - _c.m_b,
50  m_a - _c.m_a );
51 }
52 
53 //----------------------------------------------------------------------------------------------------------------------
54 const Colour& Colour::operator +=( const Colour& _c ) noexcept
55 {
56  m_r+=_c.m_r;
57  m_g+=_c.m_g;
58  m_b+=_c.m_b;
59  m_a+=_c.m_a;
60  return *this;
61 }
62 //----------------------------------------------------------------------------------------------------------------------
63 Colour Colour::operator *( const Colour &_c ) const noexcept
64 {
65  return Colour(
66  m_r * _c.m_r,
67  m_g * _c.m_g,
68  m_b * _c.m_b,
69  m_a * _c.m_a
70  );
71 }
72 //----------------------------------------------------------------------------------------------------------------------
73 Colour Colour::operator *(const Real _c ) const noexcept
74 {
75  return Colour(
76  m_r * _c,
77  m_g * _c,
78  m_b * _c,
79  m_a * _c
80  );
81 }
82 //----------------------------------------------------------------------------------------------------------------------
83 const Colour& Colour::operator *=( const Colour& _c ) noexcept
84 {
85  m_r*=_c.m_r;
86  m_g*=_c.m_g;
87  m_b*=_c.m_b;
88  m_a*=_c.m_a;
89  return *this;
90 }
91 
92 //----------------------------------------------------------------------------------------------------------------------
93 const Colour& Colour::operator *=(Real _c ) noexcept
94 {
95  m_r*=_c;
96  m_g*=_c;
97  m_b*=_c;
98  m_a*=_c;
99  return *this;
100 }
101 
102 //----------------------------------------------------------------------------------------------------------------------
103 
104 void Colour::clamp(Real _min, Real _max ) noexcept
105 {
106  m_r<_min ? m_r = _min : m_r;
107  m_r>_max ? m_r = _max : m_r;
108 
109  m_g<_min ? m_g = _min : m_g;
110  m_g>_max ? m_g = _max : m_g;
111 
112  m_b<_min ? m_b = _min : m_b;
113  m_b>_max ? m_b = _max : m_b;
114 
115  m_a<_min ? m_a = _min : m_a;
116  m_a>_max ? m_a = _max : m_a;
117 }
118 
119 
120 
121 } // end namespace ngl
122 
123 
124 
simple class to hold colour information and set the basic opengl colour state. also has overloaded me...
Definition: Colour.h:40
Real m_r
red component of the colour tuple
Definition: Colour.h:160
a simple colour class for RGBA colour
implementation files for RibExport class
Definition: AABB.cpp:22
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
Definition: Types.h:127
Colour operator*(const Colour &_c) const noexcept
operator to multiply colours
Definition: Colour.cpp:63
const Colour & operator+=(const Colour &_c) noexcept
operator to add rhs to current colour
Definition: Colour.cpp:54
const Colour & operator*=(const Colour &_c) noexcept
operator to multiply = by a colour
Definition: Colour.cpp:83
void clamp(Real _min, Real _max) noexcept
clamp the colour to the given range from Eduard Zell MSc 2010 the input values >0 < 1...
Definition: Colour.cpp:104
void add(const Colour &_src, const Colour &_refl) noexcept
Definition: Colour.cpp:27
Colour operator-(const Colour &_c) const noexcept
operator to subtract colours
Definition: Colour.cpp:45
Colour operator+(const Colour &_c) const noexcept
operator to add two colours
Definition: Colour.cpp:36