Phongo Clap RT  1.0
Simple Raytracing Renderer
Public Member Functions | Private Attributes | List of all members
geo::Plane Class Reference

Inherits from shape. Implements functionability for plane shape and its materials. and the ray-plane intersections algorithms. More...

#include <Plane.h>

Inheritance diagram for geo::Plane:
Inheritance graph
Collaboration diagram for geo::Plane:
Collaboration graph

Public Member Functions

 Plane ()
 Default constructor for the plane. If no arguments passed it will be initialised with distance(5) n(1,1,1) More...
 
 ~Plane ()
 Default destructor. More...
 
 Plane (float _distance, ngl::Vec3 _n, ngl::Colour _c)
 This constructor reads some arguments and pass them to the private interface. More...
 
 Plane (float _distance, ngl::Vec3 _n, ngl::Colour _c1, ngl::Colour _c2)
 This constructor reads some arguments and pass them to the private interface. For checkerboard planes. More...
 
virtual float getIntersection (geo::Ray &_ray)
 Virtual method that implements the ray-plane intersection. More...
 
virtual ngl::Vec3 getNormalAt (ngl::Vec3 _p)
 Simple getter that returns the normal of the plane. More...
 
virtual ngl::Colour getColour ()
 Returns the colour for plain objects, in other words for non-checkerboard planes. More...
 
virtual ngl::Colour getColour (ngl::Vec3 &_isect)
 Returns the colour for checker-board planes. This will imply passing an intersection point in world space so that we can make the right calculations to see whether we must return the colour1 or colour2. More...
 
- Public Member Functions inherited from geo::Shape
 Shape ()
 Default constructor. More...
 
 ~Shape ()
 Frees any memory grabbed from the heap. More...
 
void hasRefraction (float _ior, float _transparency, float _diffuse_intensity)
 Sets parameters related to refraction, this will be given to the Material class. More...
 
void hasReflection (float _refl_intensity, float _diffuse_intensity)
 Sets reflection attributes. More...
 
MaterialgetMaterial ()
 Returns the material attached to a shape object. This is useful for querying or changing private interface, that's why it is not const. More...
 
char getType ()
 Derived classes will be Spheres or Planes, I will store the type of geometry in this attribute. More...
 

Private Attributes

float m_distance
 Distance from the origin the plane is located at. More...
 
ngl::Vec3 m_n
 Normal of the plane. More...
 

Additional Inherited Members

- Protected Attributes inherited from geo::Shape
char m_type
 Type of geometric object it is. More...
 
ngl::Colour m_colour
 Colour of the shape. More...
 
Materialm_material
 Material attached to the Shape object. More...
 

Detailed Description

Inherits from shape. Implements functionability for plane shape and its materials. and the ray-plane intersections algorithms.

Author
Ramon Blanquer
Todo:
Implement new ways to instanciate a plane, ie specifying three points, or one point and a normal.

Definition at line 22 of file Plane.h.

Constructor & Destructor Documentation

geo::Plane::Plane ( )

Default constructor for the plane. If no arguments passed it will be initialised with distance(5) n(1,1,1)

Definition at line 11 of file Plane.cpp.

References geo::Shape::m_colour, geo::Shape::m_material, and geo::Shape::m_type.

11  : 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 }
Material * m_material
Material attached to the Shape object.
Definition: Shape.h:96
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
char m_type
Type of geometric object it is.
Definition: Shape.h:88
ngl::Vec3 m_n
Normal of the plane.
Definition: Plane.h:80
geo::Plane::~Plane ( )

Default destructor.

geo::Plane::Plane ( float  _distance,
ngl::Vec3  _n,
ngl::Colour  _c 
)

This constructor reads some arguments and pass them to the private interface.

Parameters
[in]_distanceDistance from the origin the plane is located at.
[in]_nNormal of the plane.
[in]_cPlain colour of the plane.

Definition at line 19 of file Plane.cpp.

References geo::Shape::m_colour, m_distance, geo::Shape::m_material, m_n, and geo::Shape::m_type.

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 }
Material * m_material
Material attached to the Shape object.
Definition: Shape.h:96
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
char m_type
Type of geometric object it is.
Definition: Shape.h:88
ngl::Vec3 m_n
Normal of the plane.
Definition: Plane.h:80
geo::Plane::Plane ( float  _distance,
ngl::Vec3  _n,
ngl::Colour  _c1,
ngl::Colour  _c2 
)

This constructor reads some arguments and pass them to the private interface. For checkerboard planes.

Parameters
[in]_distanceDistance from the origin the plane is located at.
[in]_nPrimary colour of the checkerboard.
[in]_c1Secondary colour of the checkerboard.

Definition at line 39 of file Plane.cpp.

References geo::Shape::m_colour, m_distance, geo::Shape::m_material, m_n, and geo::Shape::m_type.

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 }
Material * m_material
Material attached to the Shape object.
Definition: Shape.h:96
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
char m_type
Type of geometric object it is.
Definition: Shape.h:88
ngl::Vec3 m_n
Normal of the plane.
Definition: Plane.h:80

Member Function Documentation

ngl::Colour geo::Plane::getColour ( )
virtual

Returns the colour for plain objects, in other words for non-checkerboard planes.

Returns
The colour of the plane

Implements geo::Shape.

Definition at line 82 of file Plane.cpp.

References geo::Shape::m_material, and Material::objColour().

83 {
84  return m_material->objColour();
85 }
Material * m_material
Material attached to the Shape object.
Definition: Shape.h:96
ngl::Colour objColour()
Returns the object colour.
Definition: Material.cpp:72

Here is the call graph for this function:

ngl::Colour geo::Plane::getColour ( ngl::Vec3 &  _isect)
virtual

Returns the colour for checker-board planes. This will imply passing an intersection point in world space so that we can make the right calculations to see whether we must return the colour1 or colour2.

Parameters
[in]_isectPosition in world space of the intersecting point.
Returns
The colour of the plane at the intersection point

Implements geo::Shape.

Definition at line 87 of file Plane.cpp.

References Material::m_isChecker, geo::Shape::m_material, and Material::objColour().

88 {
90  {
91  return m_material->objColour(_isect);
92  }
93  else
94  {
95  return m_material->objColour();
96  }
97 }
Material * m_material
Material attached to the Shape object.
Definition: Shape.h:96
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

Here is the call graph for this function:

float geo::Plane::getIntersection ( geo::Ray _ray)
virtual

Virtual method that implements the ray-plane intersection.

Parameters
[in]_rayRay that will be used to solve the equation for finding the "t" parameter of the ray that satisfies that this point is shared by both ray and plane aka intersection point.
Returns
The **'t'** parameter from the R = O + t * d equation form of the line, thus the intersection point.

Implements geo::Shape.

Definition at line 59 of file Plane.cpp.

References geo::Ray::getDirection(), geo::Ray::getOrigin(), m_distance, and m_n.

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 }
ngl::Vec3 getOrigin()
Getter method for the origin.
Definition: Ray.cpp:39
float m_distance
Distance from the origin the plane is located at.
Definition: Plane.h:76
ngl::Vec3 m_n
Normal of the plane.
Definition: Plane.h:80
ngl::Vec3 getDirection()
Getter method for the direction.
Definition: Ray.cpp:44

Here is the call graph for this function:

ngl::Vec3 geo::Plane::getNormalAt ( ngl::Vec3  _p)
virtual

Simple getter that returns the normal of the plane.

Returns
The normal of the plane

Implements geo::Shape.

Definition at line 77 of file Plane.cpp.

References m_n.

78 {
79  return m_n;
80 }
ngl::Vec3 m_n
Normal of the plane.
Definition: Plane.h:80

Member Data Documentation

float geo::Plane::m_distance
private

Distance from the origin the plane is located at.

Definition at line 76 of file Plane.h.

ngl::Vec3 geo::Plane::m_n
private

Normal of the plane.

Definition at line 80 of file Plane.h.


The documentation for this class was generated from the following files: