Phongo Clap RT  1.0
Simple Raytracing Renderer
Material.cpp
Go to the documentation of this file.
1 
4 #include "Material.h"
5 #include <ngl/Colour.h>
6 
8 
9 Material::Material(ngl::Colour _c)
10 {
11  m_colour1 = _c;
12  m_isChecker = false;
13 }
14 
15 Material::Material(ngl::Colour _c1, ngl::Colour _c2 )
16 {
17  m_colour1 = _c1;
18  m_colour2 = _c2;
19  m_isChecker = true;
20 }
21 
23 {
24  return m_isReflective;
25 }
26 
28 {
29  return m_isRefractive;
30 }
31 
32 void Material::setHardness(float _highlight_size)
33 {
34  m_spec_hardness = _highlight_size;
35 }
36 
37 void Material::setReflection(float _refl_intensity, float _diffuse_intensity)
38 {
39  m_isReflective = true;
40  m_refl_intensity = _refl_intensity;
41  m_diffuse_intensity = _diffuse_intensity;
42 }
43 
44 void Material::setRefraction(float _ior, float _transparency, float _diffuse_intensity)
45 {
46  m_isRefractive = true;
47  m_ior = _ior;
48  m_transparency = _transparency;
49  m_diffuse_intensity = _diffuse_intensity;
50 }
51 
53 {
54  return m_refl_intensity;
55 }
56 
58 {
59  return m_ior;
60 }
61 
63 {
64  return m_transparency;
65 }
66 
68 {
69  return m_diffuse_intensity;
70 }
71 
72 ngl::Colour Material::objColour()
73 {
74  return m_colour1;
75 }
76 
77 ngl::Colour Material::objColour(ngl::Vec3 &_isect)
78 {
79  /* This will floor the z and x position of a plane and for each integer value modulus operation will be performed
80  * after that, depending on whether the remainder is 0 or 1 we apply one colour or another.*/
81 
82  if(m_isChecker)
83  {
84  int index_x = (int)(floor(_isect.m_x)) % 2;
85  int index_z = (int)(floor(_isect.m_z)) % 2;
86 
87  if (((bool)index_x && (bool)index_z) || ((bool)index_x == 0 && (bool)index_z == 0))
88  {
89  return m_colour1;
90  }
91  else
92  {
93  return m_colour2;
94  }
95  }
96  else
97  {
98  return m_colour1;
99  }
100 }
Material()
Material constructor.
Definition: Material.cpp:7
bool m_isRefractive
Specifies whether object is transparent.
Definition: Material.h:96
float m_ior
Index of refraction.
Definition: Material.h:108
This will be used to return the colour when queried from the Shape derived classes.
void setHardness(float _highlight_size)
Sets the specular modulator for the specular contribution in the Phong shader.
Definition: Material.cpp:32
float getIOR()
Returns index of refraction.
Definition: Material.cpp:57
float m_refl_intensity
Amount of reflection.
Definition: Material.h:104
float getDiffuseIntensity()
Returns amount of diffuse contribution.
Definition: Material.cpp:67
float m_transparency
Amount of refraction, in other words 'transparency'.
Definition: Material.h:112
float m_spec_hardness
This will drive the spreadness of the specular highlights.
Definition: Material.h:116
bool m_isReflective
Tells whether the object is reflective.
Definition: Material.h:92
float getTransparency()
Returns transparency.
Definition: Material.cpp:62
ngl::Colour m_colour1
Colour of the object.
Definition: Material.h:121
float m_diffuse_intensity
Diffuse intensity, self-explanatory.
Definition: Material.h:100
bool isRefractive()
Returns whether the material is reflective or not.
Definition: Material.cpp:27
float getReflIntensity()
Returns amount of reflection.
Definition: Material.cpp:52
void setReflection(float _refl_intensity, float _diffuse_intensity)
Sets the reflection parameters.
Definition: Material.cpp:37
void setRefraction(float _ior, float _transparency, float _diffuse_intensity)
Sets the refraction settings.
Definition: Material.cpp:44
ngl::Colour m_colour2
For checker materials we will have colour1 and colour2, for plain ones just colour1.
Definition: Material.h:125
bool isReflective()
Returns whether the material is reflective or not.
Definition: Material.cpp:22
ngl::Colour objColour()
Returns the object colour.
Definition: Material.cpp:72
bool m_isChecker
Specifies whether it is checker or not.
Definition: Material.h:129