Ray Tracer Common Project
Image rendering program based on the ray tracing technique.
element.hpp
1 
15 #pragma once
16 
17 #include "core/vector.hpp"
18 #include "core/matrix.hpp"
19 
20 namespace rt{
21 
22 class Geometry;
23 class Material;
24 
43 class element{
44 public:
50  element();
51 
61  element(const Geometry *g, const vector & position, const vector & normal, const vector & tangent);
62 
66  element(const element &);
67 
71  ~element();
72 
82  vector uv() const;
83 
89  inline const vector & position() const{
90  return _position;
91  }
92 
98  inline const vector & normal() const{
99  return _normal;
100  }
101 
107  inline const vector & tangent() const{
108  return _tangent;
109  }
110 
115  inline vector binormal() const{
116  return _normal^_tangent;
117  }
118 
124  inline const Geometry *geometry() const{
125  return _g;
126  }
127 
136  inline const Material *material() const{
137  return _m;
138  }
139 
148  inline void setMaterial(Material *m){
149  _m = m;
150  }
151 
158  const vector & globalPosition() const;
159 
166  const vector & globalNormal() const;
167 
174  const vector & globalTangent() const;
175 
180  inline vector globalBinormal() const{
181  return globalNormal()^globalTangent();
182  }
183 
188  element & operator=(const element &);
189 
190 private:
191  const Geometry *_g;
192  const Material *_m;
193 
194  vector _position;
195  vector _normal;
196  vector _tangent;
197 
198  mutable vector _global_position;
199  mutable vector _global_normal;
200  mutable vector _global_tangent;
201 
202  mutable bool _c_position, _c_normal, _c_tangent;
203 };
204 
205 }
Object material.
Definition: material.hpp:39
const vector & tangent() const
A tangent of the surface at this position.
Definition: element.hpp:107
void setMaterial(Material *m)
Attach a material to the element.
Definition: element.hpp:148
const vector & globalPosition() const
Global position of the surface element.
Definition: element.cpp:90
vector uv() const
Get uv mapping of the element.
Definition: element.cpp:65
Definition: bitmap.cpp:4
const vector & globalNormal() const
Global normal of the surface element.
Definition: element.cpp:82
const vector & position() const
Position of the element on the surface.
Definition: element.hpp:89
const vector & globalTangent() const
Global tangent of the surface element.
Definition: element.cpp:98
3D vector
Definition: vector.hpp:28
Geometric entity.
Definition: geometry.hpp:39
const Material * material() const
The surface material.
Definition: element.hpp:136
element & operator=(const element &)
operator =
Definition: element.cpp:49
Geometric surface element unit.
Definition: element.hpp:43
const vector & normal() const
Normal of the element on the surface.
Definition: element.hpp:98
vector globalBinormal() const
Global binormal of the surface element.
Definition: element.hpp:180
vector binormal() const
A binormal of the surface at this point.
Definition: element.hpp:115
element()
Default constructor.
Definition: element.cpp:7
~element()
Destructor.
Definition: element.cpp:40
const Geometry * geometry() const
The geometry owner.
Definition: element.hpp:124