Phongo Clap RT  1.0
Simple Raytracing Renderer
Plane.cpp
Go to the documentation of this file.
1 
4 #include <ngl/Vec3.h>
5 #include "Plane.h"
6 #include "Ray.h"
7 #include "Material.h"
8 
9 namespace geo
10 {
11 Plane::Plane() : m_distance(5.0f), m_n(ngl::Vec3(1,1,1))
12 {
13  m_colour = ngl::Colour(1,0,0);
14  m_type='p';
15  Material* mat = new Material(ngl::Colour(1,1,1,1), ngl::Colour(0,0,0,1));
16  m_material = mat;
17 }
18 
19 Plane::Plane(float _distance, ngl::Vec3 _n, ngl::Colour _c)
20 {
21  m_distance = _distance;
22  m_colour = _c;
23  m_type='p';
24 
25  Material* mat = new Material(_c);
26  m_material = mat;
27 
28  if(_n.length() > 1.01 || _n.length() < 0.99)
29  {
30  _n.normalize();
31  m_n = _n;
32  }
33  else
34  {
35  m_n = _n;
36  }
37 }
38 
39 Plane::Plane(float _distance, ngl::Vec3 _n, ngl::Colour _c1, ngl::Colour _c2)
40 {
41  m_distance = _distance;
42  m_colour = _c1;
43  m_type='p';
44 
45  Material* mat = new Material(_c1, _c2);
46  m_material = mat;
47 
48  if(_n.length() > 1.01 || _n.length() < 0.99)
49  {
50  _n.normalize();
51  m_n = _n;
52  }
53  else
54  {
55  m_n = _n;
56  }
57 }
58 
60 {
61  ngl::Vec3 ray_dir = _ray.getDirection();
62 
63  float a = ray_dir.dot(m_n);
64 
65  if(a == 0)
66  {
67  // ray is paralel
68  return -1;
69  }
70  else
71  {
72  double b = m_n.dot(_ray.getOrigin() + (-(m_distance*m_n)));
73  return -1*b/a;
74  }
75 }
76 
77 ngl::Vec3 Plane::getNormalAt(ngl::Vec3 _p)
78 {
79  return m_n;
80 }
81 
82 ngl::Colour Plane::getColour()
83 {
84  return m_material->objColour();
85 }
86 
87 ngl::Colour Plane::getColour(ngl::Vec3 &_isect)
88 {
90  {
91  return m_material->objColour(_isect);
92  }
93  else
94  {
95  return m_material->objColour();
96  }
97 }
98 }
Material * m_material
Material attached to the Shape object.
Definition: Shape.h:96
ngl::Vec3 getOrigin()
Getter method for the origin.
Definition: Ray.cpp:39
This will be used to return the colour when queried from the Shape derived classes.
Implements the interface for creating a plane shape and the methods for finding its intersections...
Plane()
Default constructor for the plane. If no arguments passed it will be initialised with distance(5) n(1...
Definition: Plane.cpp:11
Definition: Ray.h:17
float m_distance
Distance from the origin the plane is located at.
Definition: Plane.h:76
ngl::Colour m_colour
Colour of the shape.
Definition: Shape.h:92
virtual ngl::Colour getColour()
Returns the colour for plain objects, in other words for non-checkerboard planes. ...
Definition: Plane.cpp:82
virtual float getIntersection(geo::Ray &_ray)
Virtual method that implements the ray-plane intersection.
Definition: Plane.cpp:59
virtual ngl::Vec3 getNormalAt(ngl::Vec3 _p)
Simple getter that returns the normal of the plane.
Definition: Plane.cpp:77
char m_type
Type of geometric object it is.
Definition: Shape.h:88
This class handles the implementation of ray: an object with an origin and a direction.
Definition: Plane.cpp:9
ngl::Vec3 m_n
Normal of the plane.
Definition: Plane.h:80
ngl::Colour objColour()
Returns the object colour.
Definition: Material.cpp:72
ngl::Vec3 getDirection()
Getter method for the direction.
Definition: Ray.cpp:44
bool m_isChecker
Specifies whether it is checker or not.
Definition: Material.h:129