summaryrefslogtreecommitdiff
path: root/hw6/src/surfaceSample.cpp
blob: 464c969211326326cf26a81d321de677510db91e (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
117
118
/******************************************************************/
/* 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.                                                  */
/******************************************************************/
#include <cmath>
#include "surfaceSample.h"

//////////////////
// Constructors //
//////////////////
surfaceSample::surfaceSample(void)
{
  _position = vec3d();
  _normal = vec3d();
  _pdf = 0.0f;
}


surfaceSample::surfaceSample(const vec3d& position, const vec3d& normal, const float pdf)
{
  _position = position;
  _normal = normal;
  _pdf = std::max(pdf, 0.0f);
}


surfaceSample::surfaceSample(const surfaceSample& ss)
{
  _position = ss._position;
  _normal = ss._normal;
  _pdf = ss._pdf;
}


///////////////
// Operators //
///////////////
surfaceSample& surfaceSample::operator=(const surfaceSample& ss)
{
  _assign(ss);
  return *this;
}
  

surfaceSample surfaceSample::operator*(float pdf) const
{
  return surfaceSample(_position, _normal, _pdf * pdf);
}


surfaceSample& surfaceSample::operator*=(float pdf)
{
  _pdf *= pdf;
  return *this;
}


////////////////
// Inspectors //
////////////////
const vec3d& surfaceSample::position(void) const
{
  return _position;
}


const vec3d& surfaceSample::normal(void) const
{
  return _normal;
}


float surfaceSample::pdf(void) const
{
  return _pdf;
}


/////////////
// Methods //
/////////////
surfaceSample& surfaceSample::transform(const transformation3d& t)
{
  _position = t.transformPoint(_position);
  _normal = t.transformNormal(_normal);
  return *this;
}


surfaceSample& surfaceSample::inverseTransform(const transformation3d& t)
{
  _position = t.inverseTransformPoint(_position);
  _normal = t.inverseTransformNormal(_normal);
  return *this;
}


/////////////////////
// Private Methods //
/////////////////////
void surfaceSample::_swap(surfaceSample& s)
{
  swap(_position, s._position);
  swap(_normal, s._normal);
  std::swap(_pdf, s._pdf);
}


void surfaceSample::_assign(const surfaceSample& s)
{
  _position = s._position;
  _normal = s._normal;
  _pdf = s._pdf;
}