-
Notifications
You must be signed in to change notification settings - Fork 0
/
material.h
58 lines (54 loc) · 1.21 KB
/
material.h
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
#pragma once
#include <vector>
struct material {
float b;
float lambda;
float C;
float p; // density
float k0, k1; // exponential transmittance coefficient of glass
float a;
private:
std::vector<float*> data;
inline void fill_data() {
data.push_back(&b);
data.push_back(&lambda);
data.push_back(&C);
data.push_back(&p);
data.push_back(&k0);
data.push_back(&k1);
data.push_back(&a);
}
public:
material() : b(0), lambda(0), C(0), p(0), k0(0), k1(0), a(0) {
fill_data();
};
material(int i) {
fill_data();
for (int i = 0; i < data.size(); ++i) *(data[i]) = i;
}
material(float b_, float lambda_, float C_, float p_, float k0_, float k1_) : b(b_), lambda(lambda_), C(C_), p(p_), k0(k0_), k1(k1_) {
a = lambda / (C*p);
fill_data();
}
bool is_correct() {
return lambda && C && p;
}
float* operator[](int i) {
if (i >= 0 && i < data.size()) return data[i];
}
void clear() {
for (int i = 0; i < data.size(); ++i) *(data[i]) = 0;
}
material& operator=(const material& other) {
if (this != &other) {
this->b = other.b;
this->lambda = other.lambda;
this->C = other.C;
this->p = other.p;
this->k0 = other.k0;
this->k1 = other.k1;
this->a = other.a;
}
return *this;
}
};