-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaterial.cpp
More file actions
executable file
·125 lines (106 loc) · 2.39 KB
/
Material.cpp
File metadata and controls
executable file
·125 lines (106 loc) · 2.39 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
/*
* Material.cpp
*
*
* Created by Donald House on 9/8/08.
* Copyright 2008 Clemson University. All rights reserved.
*
*/
#include "Material.h"
Material::Material(char *mname){
name = NULL;
setName(mname);
amap = dmap = smap = NULL;
alpha = n = 1.0;
illum_model = 1;
setProperties(0.2, 0.8, 0, 1);
}
Material::Material(const Color &ambient, const Color &diffuse, const Color &specular,
double spexp){
name = NULL;
amap = dmap = smap = NULL;
alpha = n = 1.0;
illum_model = 1;
setProperties(ambient, diffuse, specular, spexp);
}
void Material::setName(char *mname){
delete name;
if(mname == NULL)
name = NULL;
else{
name = new char[strlen(mname) + 1];
strcpy(name, mname);
}
}
bool Material::isNamed(char *mname){
if(name == NULL || mname == NULL)
return false;
return strcmp(mname, name) == 0;
}
void Material::setProperties(const Color &ambient, const Color &diffuse, const Color &specular,
double spexp){
a = ambient;
d = diffuse;
s = specular;
exp = spexp;
}
void Material::setProperties(double ambient, double diffuse, double specular,
double spexp){
Color ca, cd, cs;
ca.set(ambient, ambient, ambient);
cd.set(diffuse, diffuse, diffuse);
cs.set(specular, specular, specular);
setProperties(ca, cd, cs, spexp);
}
void Material::setK(int k, const Color &c){
switch(k){
case 0:
a = c;
break;
case 1:
d = c;
break;
case 2:
s = c;
break;
}
}
void Material::setTransmission(const Color &c){
t = c;
}
void Material::setExp(double spexp){
exp = spexp;
}
void Material::setAlpha(double alfa){
alpha = alfa;
}
void Material::setIOR(double ior){
n = ior;
}
void Material::setIllum(int i){
illum_model = i;
}
void Material::setMap(int mtype, Pixmap *p){
switch(mtype){
case 0:
amap = p;
break;
case 1:
dmap = p;
break;
case 2:
smap = p;
break;
}
}
ostream& operator<< (ostream& os, const Material& m){
os << "[material " << m.name << ": a = " << m.a << ", d = " << m.d <<
", s = " << m.s << ", exp = " << m.exp << "\n";
os << " alpha = " << m.alpha << ", t = " << m.t <<
", illum model = " << m.illum_model << "\n";
os << " textures: (" << (m.amap? "ambient": "no ambient") << ", " <<
(m.dmap? "diffuse": "no diffuse") << ", " <<
(m.smap? "specular": "no specular") << ")";
os << "]";
return os;
}