Oolite
Loading...
Searching...
No Matches
OOBasicMaterial Class Reference

#include <OOBasicMaterial.h>

Inheritance diagram for OOBasicMaterial:
Collaboration diagram for OOBasicMaterial:

Instance Methods

(id) - initWithName:
(id) - initWithName:configuration:
(OOColor *) - diffuseColor
(void) - setDiffuseColor:
(void) - setAmbientAndDiffuseColor:
(OOColor *) - specularColor
(void) - setSpecularColor:
(OOColor *) - ambientColor
(void) - setAmbientColor:
(OOColor *) - emmisionColor
(void) - setEmissionColor:
(void) - getDiffuseComponents:
(void) - setDiffuseComponents:
(void) - setAmbientAndDiffuseComponents:
(void) - getSpecularComponents:
(void) - setSpecularComponents:
(void) - getAmbientComponents:
(void) - setAmbientComponents:
(void) - getEmissionComponents:
(void) - setEmissionComponents:
(void) - setDiffuseRed:green:blue:alpha:
(void) - setAmbientAndDiffuseRed:green:blue:alpha:
(void) - setSpecularRed:green:blue:alpha:
(void) - setAmbientRed:green:blue:alpha:
(void) - setEmissionRed:green:blue:alpha:
(uint8_t) - shininess
(void) - setShininess:
(BOOL) - permitSpecular
(void) - dealloc [implementation]
(NSString *) - name [implementation]
(BOOL) - doApply [implementation]
(void) - unapplyWithNext: [implementation]
Instance Methods inherited from OOMaterial
(void) - apply
(void) - ensureFinishedLoading
(BOOL) - isFinishedLoading
(void) - setBindingTarget:
(BOOL) - wantsNormalsAsTextureCoordinates
(NSString *) - descriptionComponents [implementation]
(void) - willDealloc

Private Attributes

NSString * materialName
GLfloat diffuse [4]
GLfloat specular [4]
GLfloat ambient [4]
GLfloat emission [4]
uint8_t shininess

Additional Inherited Members

Class Methods inherited from OOMaterial
(void) + setUp
(void) + applyNone
(OOMaterial *) + current
(OOMaterial *) + materialWithName:cacheKey:configuration:macros:bindingTarget:forSmoothedMesh:
(OOMaterial *) + materialWithName:cacheKey:materialDictionary:shadersDictionary:macros:bindingTarget:forSmoothedMesh:
(NSDictionary *) + synthesizeMaterialDictionaryWithName:configuration:macros: [implementation]
(OOMaterial *) + defaultShaderMaterialWithName:cacheKey:configuration:macros:bindingTarget: [implementation]

Detailed Description

Definition at line 36 of file OOBasicMaterial.h.

Method Documentation

◆ ambientColor

- (OOColor *) ambientColor

Definition at line 172 of file OOBasicMaterial.m.

173{
174 return [OOColor colorWithRed:ambient[0]
175 green:ambient[1]
176 blue:ambient[2]
177 alpha:ambient[3]];
178}
OOColor * colorWithRed:green:blue:alpha:(float red,[green] float green,[blue] float blue,[alpha] float alpha)
Definition OOColor.m:107

References ambientColor, and OOColor::colorWithRed:green:blue:alpha:.

Referenced by ambientColor.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dealloc

- (void) dealloc
implementation

Reimplemented from OOMaterial.

Reimplemented in OOSingleTextureMaterial.

Definition at line 94 of file OOBasicMaterial.m.

95{
96 [super willDealloc];
97 [materialName release];
98
99 [super dealloc];
100}

References dealloc, OOMaterial::dealloc, and OOMaterial::willDealloc.

Referenced by dealloc, and OOSingleTextureMaterial::dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ diffuseColor

- (OOColor *) diffuseColor

Definition at line 130 of file OOBasicMaterial.m.

131{
132 return [OOColor colorWithRed:diffuse[0]
133 green:diffuse[1]
134 blue:diffuse[2]
135 alpha:diffuse[3]];
136}

References OOColor::colorWithRed:green:blue:alpha:, and diffuseColor.

Referenced by diffuseColor, and initWithName:configuration:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doApply

- (BOOL) doApply
implementation

Reimplemented from OOMaterial.

Reimplemented in OOSingleTextureMaterial.

Definition at line 107 of file OOBasicMaterial.m.

108{
109 OOGL(glMaterialfv(FACE, GL_DIFFUSE, diffuse));
110 OOGL(glMaterialfv(FACE, GL_SPECULAR, specular));
111 OOGL(glMaterialfv(FACE, GL_AMBIENT, ambient));
112 OOGL(glMaterialfv(FACE, GL_EMISSION, emission));
113 OOGL(glMateriali(FACE, GL_SHININESS, shininess));
114 if ([self isMemberOfClass:[OOBasicMaterial class]]) {
116 }
117
118 return YES;
119}
#define FACE
#define OOGL(statement)
Definition OOOpenGL.h:262
GLfloat emission[4]
GLfloat specular[4]
void applyNone()
Definition OOTexture.m:263

References ambient, OOTexture::applyNone, diffuse, doApply, emission, FACE, OOGL, shininess, and specular.

Referenced by doApply, and unapplyWithNext:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ emmisionColor

- (OOColor *) emmisionColor

Definition at line 190 of file OOBasicMaterial.m.

191{
192 return [OOColor colorWithRed:emission[0]
193 green:emission[1]
194 blue:emission[2]
195 alpha:emission[3]];
196}

References OOColor::colorWithRed:green:blue:alpha:, and emmisionColor.

Referenced by emmisionColor.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAmbientComponents:

- (void) getAmbientComponents: (GLfloat[4]) outComponents

Definition at line 234 of file OOBasicMaterial.m.

234 :(GLfloat[4])outComponents
235{
236 memcpy(outComponents, ambient, 4 * sizeof *outComponents);
237}

References ambient.

◆ getDiffuseComponents:

- (void) getDiffuseComponents: (GLfloat[4]) outComponents

Definition at line 208 of file OOBasicMaterial.m.

208 :(GLfloat[4])outComponents
209{
210 memcpy(outComponents, diffuse, 4 * sizeof *outComponents);
211}

References diffuse.

◆ getEmissionComponents:

- (void) getEmissionComponents: (GLfloat[4]) outComponents

Definition at line 244 of file OOBasicMaterial.m.

244 :(GLfloat[4])outComponents
245{
246 memcpy(outComponents, emission, 4 * sizeof *outComponents);
247}

References emission.

◆ getSpecularComponents:

- (void) getSpecularComponents: (GLfloat[4]) outComponents

Definition at line 224 of file OOBasicMaterial.m.

224 :(GLfloat[4])outComponents
225{
226 memcpy(outComponents, specular, 4 * sizeof *outComponents);
227}

References specular.

◆ initWithName:

- (id) initWithName: (NSString*) name

Definition at line 41 of file OOBasicMaterial.m.

41 :(NSString*)name
42{
43 self = [super init];
44 if (EXPECT_NOT(self == nil))
45 return nil;
46
47 materialName = [name copy];
48
49 [self setDiffuseRed:1.0f green:1.0f blue:1.0f alpha:1.0f];
50 [self setAmbientRed:1.0f green:1.0f blue:1.0f alpha:1.0f];
51 specular[3] = 1.0;
52 emission[3] = 1.0;
53
54 return self;
55}
#define EXPECT_NOT(x)
return nil
NSString * materialName

References emission, EXPECT_NOT, materialName, nil, setAmbientRed:green:blue:alpha:, setDiffuseRed:green:blue:alpha:, and specular.

Referenced by initWithName:configuration:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initWithName:configuration:

- (id) initWithName: (NSString*) name
configuration: (NSDictionary*) configuration 

Reimplemented in OOSingleTextureMaterial.

Definition at line 57 of file OOBasicMaterial.m.

57 :(NSString*)name configuration:(NSDictionary*)configuration
58{
59 id colorDesc = nil;
60 int specularExponent;
61
62 self = [self initWithName:name];
63 if (EXPECT_NOT(self == nil))
64 return nil;
65
66 if (configuration == nil)
67 configuration = [NSDictionary dictionary];
68
69 colorDesc = [configuration oo_diffuseColor];
70 if (colorDesc != nil)
71 [self setDiffuseColor:[OOColor colorWithDescription:colorDesc]];
72
73 colorDesc = [configuration oo_ambientColor];
74 if (colorDesc != nil)
75 [self setAmbientColor:[OOColor colorWithDescription:colorDesc]];
76 else
77 [self setAmbientColor:[self diffuseColor]];
78
79 colorDesc = [configuration oo_emissionColor];
80 if (colorDesc != nil)
81 [self setEmissionColor:[OOColor colorWithDescription:colorDesc]];
82
83 specularExponent = [configuration oo_specularExponent];
84 if (specularExponent != 0 && [self permitSpecular]) {
85 colorDesc = [configuration oo_specularColor];
86 [self setShininess:specularExponent];
87 if (colorDesc != nil)
88 [self setSpecularColor:[OOColor colorWithDescription:colorDesc]];
89 }
90
91 return self;
92}
OOColor * colorWithDescription:(id description)
Definition OOColor.m:135

References OOColor::colorWithDescription:, diffuseColor, EXPECT_NOT, initWithName:, nil, permitSpecular, setAmbientColor:, setDiffuseColor:, setEmissionColor:, setShininess:, and setSpecularColor:.

Referenced by OOSingleTextureMaterial::initWithName:texture:configuration:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ name

- (NSString *) name
implementation

Reimplemented from OOMaterial.

Definition at line 102 of file OOBasicMaterial.m.

103{
104 return materialName;
105}

References materialName, and name.

Referenced by OOSingleTextureMaterial::initWithName:configuration:, OOSingleTextureMaterial::initWithName:texture:configuration:, and name.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ permitSpecular

- (BOOL) permitSpecular

Definition at line 302 of file OOBasicMaterial.m.

303{
304 return ![UNIVERSE reducedDetail];
305}

References permitSpecular.

Referenced by initWithName:configuration:, permitSpecular, and shininess.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setAmbientAndDiffuseColor:

- (void) setAmbientAndDiffuseColor: (OOColor*) color

Definition at line 148 of file OOBasicMaterial.m.

148 :(OOColor*)color
149{
150 [self setAmbientColor:color];
151 [self setDiffuseColor:color];
152}

References setAmbientColor:, and setDiffuseColor:.

Here is the call graph for this function:

◆ setAmbientAndDiffuseComponents:

- (void) setAmbientAndDiffuseComponents: (const GLfloat[4]) components

Definition at line 218 of file OOBasicMaterial.m.

218 :(const GLfloat[4])components
219{
220 [self setAmbientComponents:components];
221 [self setDiffuseComponents:components];
222}

References setAmbientComponents:, and setDiffuseComponents:.

Here is the call graph for this function:

◆ setAmbientAndDiffuseRed:green:blue:alpha:

- (void) setAmbientAndDiffuseRed: (GLfloat) r
green: (GLfloat) g
blue: (GLfloat) b
alpha: (GLfloat) a 

Definition at line 262 of file OOBasicMaterial.m.

262 :(GLfloat)r green:(GLfloat)g blue:(GLfloat)b alpha:(GLfloat)a
263{
264 [self setAmbientRed:r green:g blue:b alpha:a];
265 [self setDiffuseRed:r green:g blue:b alpha:a];
266}

References setAmbientRed:green:blue:alpha:, and setDiffuseRed:green:blue:alpha:.

Here is the call graph for this function:

◆ setAmbientColor:

- (void) setAmbientColor: (OOColor*) color

Definition at line 180 of file OOBasicMaterial.m.

180 :(OOColor*)color
181{
182 if (color != nil) {
183 [self setAmbientRed:[color redComponent]
184 green:[color greenComponent]
185 blue:[color blueComponent]
186 alpha:[color alphaComponent]];
187 }
188}
float alphaComponent()
Definition OOColor.m:442
float blueComponent()
Definition OOColor.m:339
float redComponent()
Definition OOColor.m:329
float greenComponent()
Definition OOColor.m:334

References OOColor::alphaComponent, OOColor::blueComponent, OOColor::greenComponent, nil, OOColor::redComponent, and setAmbientRed:green:blue:alpha:.

Referenced by initWithName:configuration:, and setAmbientAndDiffuseColor:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setAmbientComponents:

- (void) setAmbientComponents: (const GLfloat[4]) components

Definition at line 239 of file OOBasicMaterial.m.

239 :(const GLfloat[4])components
240{
241 memcpy(ambient, components, 4 * sizeof *components);
242}

References ambient.

Referenced by setAmbientAndDiffuseComponents:.

Here is the caller graph for this function:

◆ setAmbientRed:green:blue:alpha:

- (void) setAmbientRed: (GLfloat) r
green: (GLfloat) g
blue: (GLfloat) b
alpha: (GLfloat) a 

Definition at line 276 of file OOBasicMaterial.m.

276 :(GLfloat)r green:(GLfloat)g blue:(GLfloat)b alpha:(GLfloat)a
277{
278 ambient[0] = r;
279 ambient[1] = g;
280 ambient[2] = b;
281 ambient[3] = a;
282}

References ambient.

Referenced by initWithName:, setAmbientAndDiffuseRed:green:blue:alpha:, and setAmbientColor:.

Here is the caller graph for this function:

◆ setDiffuseColor:

- (void) setDiffuseColor: (OOColor*) color

Definition at line 138 of file OOBasicMaterial.m.

138 :(OOColor*)color
139{
140 if (color != nil) {
141 [self setDiffuseRed:[color redComponent]
142 green:[color greenComponent]
143 blue:[color blueComponent]
144 alpha:[color alphaComponent]];
145 }
146}

References OOColor::alphaComponent, OOColor::blueComponent, OOColor::greenComponent, nil, OOColor::redComponent, and setDiffuseRed:green:blue:alpha:.

Referenced by initWithName:configuration:, and setAmbientAndDiffuseColor:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setDiffuseComponents:

- (void) setDiffuseComponents: (const GLfloat[4]) components

Definition at line 213 of file OOBasicMaterial.m.

213 :(const GLfloat[4])components
214{
215 memcpy(diffuse, components, 4 * sizeof *components);
216}

References diffuse.

Referenced by setAmbientAndDiffuseComponents:.

Here is the caller graph for this function:

◆ setDiffuseRed:green:blue:alpha:

- (void) setDiffuseRed: (GLfloat) r
green: (GLfloat) g
blue: (GLfloat) b
alpha: (GLfloat) a 

Definition at line 254 of file OOBasicMaterial.m.

254 :(GLfloat)r green:(GLfloat)g blue:(GLfloat)b alpha:(GLfloat)a
255{
256 diffuse[0] = r;
257 diffuse[1] = g;
258 diffuse[2] = b;
259 diffuse[3] = a;
260}

References diffuse.

Referenced by initWithName:, setAmbientAndDiffuseRed:green:blue:alpha:, and setDiffuseColor:.

Here is the caller graph for this function:

◆ setEmissionColor:

- (void) setEmissionColor: (OOColor*) color

Definition at line 198 of file OOBasicMaterial.m.

198 :(OOColor*)color
199{
200 if (color != nil) {
201 [self setEmissionRed:[color redComponent]
202 green:[color greenComponent]
203 blue:[color blueComponent]
204 alpha:[color alphaComponent]];
205 }
206}

References OOColor::alphaComponent, OOColor::blueComponent, OOColor::greenComponent, nil, OOColor::redComponent, and setEmissionRed:green:blue:alpha:.

Referenced by initWithName:configuration:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setEmissionComponents:

- (void) setEmissionComponents: (const GLfloat[4]) components

Definition at line 249 of file OOBasicMaterial.m.

249 :(const GLfloat[4])components
250{
251 memcpy(emission, components, 4 * sizeof *components);
252}

References emission.

◆ setEmissionRed:green:blue:alpha:

- (void) setEmissionRed: (GLfloat) r
green: (GLfloat) g
blue: (GLfloat) b
alpha: (GLfloat) a 

Definition at line 284 of file OOBasicMaterial.m.

284 :(GLfloat)r green:(GLfloat)g blue:(GLfloat)b alpha:(GLfloat)a
285{
286 emission[0] = r;
287 emission[1] = g;
288 emission[2] = b;
289 emission[3] = a;
290}

References emission.

Referenced by setEmissionColor:.

Here is the caller graph for this function:

◆ setShininess:

- (void) setShininess: (uint8_t) value

Definition at line 297 of file OOBasicMaterial.m.

297 :(uint8_t)value
298{
299 shininess = MIN(value, 128);
300}
#define MIN(A, B)
Definition OOMaths.h:91

References MIN, and shininess.

Referenced by initWithName:configuration:.

Here is the caller graph for this function:

◆ setSpecularColor:

- (void) setSpecularColor: (OOColor*) color

Definition at line 162 of file OOBasicMaterial.m.

162 :(OOColor*)color
163{
164 if (color != nil) {
165 [self setSpecularRed:[color redComponent]
166 green:[color greenComponent]
167 blue:[color blueComponent]
168 alpha:[color alphaComponent]];
169 }
170}

References OOColor::alphaComponent, OOColor::blueComponent, OOColor::greenComponent, nil, OOColor::redComponent, and setSpecularRed:green:blue:alpha:.

Referenced by initWithName:configuration:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSpecularComponents:

- (void) setSpecularComponents: (const GLfloat[4]) components

Definition at line 229 of file OOBasicMaterial.m.

229 :(const GLfloat[4])components
230{
231 memcpy(specular, components, 4 * sizeof *components);
232}

References specular.

◆ setSpecularRed:green:blue:alpha:

- (void) setSpecularRed: (GLfloat) r
green: (GLfloat) g
blue: (GLfloat) b
alpha: (GLfloat) a 

Definition at line 268 of file OOBasicMaterial.m.

268 :(GLfloat)r green:(GLfloat)g blue:(GLfloat)b alpha:(GLfloat)a
269{
270 specular[0] = r;
271 specular[1] = g;
272 specular[2] = b;
273 specular[3] = a;
274}

References specular.

Referenced by setSpecularColor:.

Here is the caller graph for this function:

◆ shininess

- (uint8_t) shininess

References permitSpecular, and shininess.

Here is the call graph for this function:

◆ specularColor

- (OOColor *) specularColor

Definition at line 154 of file OOBasicMaterial.m.

155{
156 return [OOColor colorWithRed:specular[0]
157 green:specular[1]
158 blue:specular[2]
159 alpha:specular[3]];
160}

References OOColor::colorWithRed:green:blue:alpha:, and specularColor.

Referenced by specularColor.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unapplyWithNext:

- (void) unapplyWithNext: (OOMaterial*) next
implementation

Reimplemented from OOMaterial.

Reimplemented in OOSingleTextureMaterial.

Definition at line 121 of file OOBasicMaterial.m.

121 :(OOMaterial*)next
122{
123 if (![next isKindOfClass:[OOBasicMaterial class]]) {
125 sDefaultMaterial = [[OOBasicMaterial alloc] initWithName:@"<default material>"];
127 }
128}
static OOBasicMaterial * sDefaultMaterial

References doApply, EXPECT_NOT, nil, and sDefaultMaterial.

Referenced by OOSingleTextureMaterial::unapplyWithNext:.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ ambient

- (GLfloat ambient[4])
private

◆ diffuse

- (GLfloat diffuse[4])
private

◆ emission

- (GLfloat emission[4])
private

◆ materialName

- (NSString*) materialName
private

Definition at line 38 of file OOBasicMaterial.h.

Referenced by initWithName:, and name.

◆ shininess

- (uint8_t) shininess
private

Definition at line 292 of file OOBasicMaterial.m.

293{
294 return shininess;
295}

Referenced by doApply, setShininess:, and shininess.

◆ specular

- (GLfloat specular[4])
private

The documentation for this class was generated from the following files: