-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLight.h
More file actions
130 lines (108 loc) · 3.93 KB
/
Light.h
File metadata and controls
130 lines (108 loc) · 3.93 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
// *********************************************************
// Light Class
// Author : Tamy Boubekeur (boubek@gmail.com).
// Copyright (C) 2010 Tamy Boubekeur.
// All rights reserved.
// *********************************************************
#ifndef LIGHT_H
#define LIGHT_H
#include <iostream>
#include <vector>
#include <random>
#include <ctime>
#include "Vec3D.h"
#include "ParameterHandler.h"
#define PI 3.14159265358979323846
class Light {
public:
inline Light () : color (Vec3Df (1.0f, 1.0f, 1.0f)), intensity (1.0f) {}
inline Light (const Vec3Df & pos, const Vec3Df & color, float intensity)
: pos (pos), color (color), intensity (intensity) {}
virtual ~Light () {}
inline const Vec3Df & getPos () const { return pos; }
inline const Vec3Df & getColor () const { return color; }
inline float getIntensity () const { return intensity; }
inline void setPos (const Vec3Df & p) { pos = p; }
inline void setColor (const Vec3Df & c) { color = c; }
inline void setIntensity (float i) { intensity = i; }
inline void getSamples (
const float& iRadius,
const unsigned int& iNumSamples,
const Vec3Df& iNormal,
std::vector< Light >& oSamples
) const {
if (
( iRadius <= 0.0f )
|| ( iNumSamples <= 1u )
) {
oSamples.push_back (
*this
);
} else {
std::default_random_engine generator ( time ( NULL ) );
std::uniform_real_distribution<float> distRadius ( 0.0f, iRadius );
std::uniform_real_distribution<float> distTheta ( 0.0f, 2 * PI );
Vec3Df xAxis, yAxis;
iNormal.getTwoOrthogonals ( xAxis, yAxis );
xAxis.normalize ();
yAxis.normalize ();
float sampleIntensity = getIntensity () / ( (float) iNumSamples );
for ( unsigned int s = 0; s < iNumSamples; s++ ) {
float radius = distRadius ( generator );
float theta = distTheta ( generator );
float x = radius * cos ( theta );
float y = radius * sin ( theta );
oSamples.push_back (
Light (
getPos () + x * xAxis + y * yAxis,
getColor (),
sampleIntensity
)
);
}
}
}
inline void getSamples (
const float& iRadius,
const unsigned int& iNumSamples,
const Vec3Df& iNormal,
std::vector< Vec3Df >& oSamples
) const {
if (
( iRadius <= 0.0f )
|| ( iNumSamples <= 1u )
) {
oSamples.push_back (
getPos ()
);
} else {
std::default_random_engine generator ( rand () );// ( time ( NULL ) );
std::uniform_real_distribution<float> distRadius ( 0.0f, iRadius );
std::uniform_real_distribution<float> distTheta ( 0.0f, 2 * PI );
Vec3Df xAxis, yAxis;
iNormal.getTwoOrthogonals ( xAxis, yAxis );
xAxis.normalize ();
yAxis.normalize ();
for ( unsigned int s = 0; s < iNumSamples; s++ ) {
float radius = distRadius ( generator );
float theta = distTheta ( generator );
float x = radius * cos ( theta );
float y = radius * sin ( theta );
oSamples.push_back (
getPos () + x * xAxis + y * yAxis
);
}
}
}
private:
Vec3Df pos;
Vec3Df color;
float intensity;
};
#endif // LIGHT_H
// Some Emacs-Hints -- please don't remove:
//
// Local Variables:
// mode:C++
// tab-width:4
// End: