summaryrefslogtreecommitdiff
path: root/hw6/include/intersectionPoint.h
blob: a1a4c3c0e0f4db53a5b5cd0775e2143925edb822 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/******************************************************************/
/* This file is part of the homework assignments for CSCI-427/527 */
/* at The College of William & Mary and authored by Pieter Peers. */
/* No part of this file, whether altered or in original form, can */
/* be distributed or used outside the context of CSCI-427/527     */
/* without consent of either the College of William & Mary or     */
/* Pieter Peers.                                                  */
/******************************************************************/
#ifndef _INTERSECTIONPOINT_H_
#define _INTERSECTIONPOINT_H_

#include <memory>
#include <ostream>

#include "ray.h"
#include "vec3d.h"
#include "vec2d.h"
#include "color.h"
#include "constants.h"
#include "brdfSample.h"
#include "lightSample.h"
#include "transformation3d.h"
#include "shaderProperties.h"
#include "coordinateTransform.h"


class intersectionPoint 
{
 public:
  /////////////////
  // Constructor //
  /////////////////
  intersectionPoint(void);
  intersectionPoint(const ray& r, float rayParameter=+LARGE, const std::shared_ptr<const class shader_base>& shader=nullptr, const vec3d& normal=vec3d(0.0f, 0.0f, 1.0f), const vec3d& axis=vec3d(1.0f, 0.0f, 0.0f), const vec2d& textureCoordinate=vec2d(0.0f, 0.0f));
  intersectionPoint(const intersectionPoint& ip);

  ///////////////
  // Operators //
  ///////////////
  intersectionPoint& operator=(const intersectionPoint& ip);

  bool operator<(const intersectionPoint& ip) const;
  bool operator>(const intersectionPoint& ip) const;
  bool operator<(const lightSample& ls) const;
  bool operator>(const lightSample& ls) const;

  ////////////////
  // Inspectors //
  ////////////////
  bool isHit(void) const;
  bool hasShader(void) const;
  shaderProperties getShaderProperties(void) const;
  float distance(const intersectionPoint& ip) const;
  const vec3d& position(void) const;
  const vec3d& direction(void) const;
  const vec2d& textureCoordinate(void) const;
  const vec3d& normal(void) const;
  coordinateTransformation shadingFrame(void) const;

  //////////////
  // Mutators //
  //////////////
  void transform(const transformation3d& t);
  void inverseTransform(const transformation3d& t);

  void transformShadingFrame(const transformation3d& sft);
  void inverseTransformShadingFrame(const transformation3d& sft);

  void setShader(const std::shared_ptr<const class shader_base>& shader);

  /////////////
  // Methods //
  /////////////
  color shade(const vec3d& out) const;
  color shade(const lightSample& ls) const;

  float reflectivity(void) const;
  color reflectance(const vec3d& out) const;
  brdfSample sample(float r1, float r2) const;
  color emittance(void) const;

  /////////////
  // Friends //
  /////////////
  friend void swap(intersectionPoint& a, intersectionPoint& b) { a._swap(b); }

  friend bool operator<(const lightSample& ls, const intersectionPoint& ip) { return (ip > ls); }
  friend bool operator>(const lightSample& ls, const intersectionPoint& ip) { return (ip < ls); }

  friend std::ostream& operator<<(std::ostream& s, const intersectionPoint& ip)
  {
    if(ip._hit) s << "IntersectionPoint: ray=" << ip._ray << ", position=" << ip._position << " (parameter=" << ip._rayParameter << ", normal=" << ip._normal << ", shading axis=" << ip._axis << ", texture coordinate=" << ip._textureCoordinate;
    else s << "IntersectionPoint: empty";
    return s;
  }

 private:
  /////////////////////
  // Private Methods //
  /////////////////////
  void _assign(const intersectionPoint& ip);
  void _swap(intersectionPoint& ip);

  //////////////////
  // Data Members //
  //////////////////
  ray _ray;
  bool _hit;
  float _rayParameter;
  vec3d _position;
  vec3d _normal, _axis;
  vec2d _textureCoordinate;
  std::shared_ptr<const class shader_base> _shader;
};

#endif /* _INTERSECTIONPOINT_H_ */