1 //****************************************************************************//
2 // corematerial.cpp //
3 // Copyright (C) 2001, 2002 Bruno 'Beosil' Heidelberger //
4 //****************************************************************************//
5 // This library is free software; you can redistribute it and/or modify it //
6 // under the terms of the GNU Lesser General Public License as published by //
7 // the Free Software Foundation; either version 2.1 of the License, or (at //
8 // your option) any later version. //
9 //****************************************************************************//
10
11 #ifdef HAVE_CONFIG_H
12 #include "config.h"
13 #endif
14
15
16 #include "cal3d/error.h"
17 #include "cal3d/corematerial.h"
18
19
CalCoreMaterial()20 CalCoreMaterial::CalCoreMaterial()
21 : m_userData(0)
22 {
23 }
24
25
26 /*****************************************************************************/
27 /** Returns the ambient color.
28 *
29 * This function returns the ambient color of the core material instance.
30 *
31 * @return A reference to the ambient color.
32 *****************************************************************************/
33
getAmbientColor()34 CalCoreMaterial::Color& CalCoreMaterial::getAmbientColor()
35 {
36 return m_ambientColor;
37 }
38
39 /*****************************************************************************/
40 /** Returns the diffuse color.
41 *
42 * This function returns the diffuse color of the core material instance.
43 *
44 * @return A reference to the diffuse color.
45 *****************************************************************************/
46
getDiffuseColor()47 CalCoreMaterial::Color& CalCoreMaterial::getDiffuseColor()
48 {
49 return m_diffuseColor;
50 }
51
52 /*****************************************************************************/
53 /** Returns the number of maps.
54 *
55 * This function returns the number of mapss in the core material instance.
56 *
57 * @return The number of maps.
58 *****************************************************************************/
59
getMapCount() const60 int CalCoreMaterial::getMapCount() const
61 {
62 return m_vectorMap.size();
63 }
64
65 /*****************************************************************************/
66 /** Returns a specified map texture filename.
67 *
68 * This function returns the texture filename for a specified map ID of the
69 * core material instance.
70 *
71 * @param mapId The ID of the map.
72 *
73 * @return One of the following values:
74 * \li the filename of the map texture
75 * \li an empty string if an error happend
76 *****************************************************************************/
77
getMapFilename(int mapId) const78 const std::string& CalCoreMaterial::getMapFilename(int mapId) const
79 {
80 // check if the map id is valid
81 if((mapId < 0) || (mapId >= (int)m_vectorMap.size()))
82 {
83 CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__);
84 static const std::string strNull;
85 return strNull;
86 }
87
88 return m_vectorMap[mapId].strFilename;
89 }
90
91 /*****************************************************************************/
92 /** Provides access to a specified map user data.
93 *
94 * This function returns the user data stored in the specified map of the core
95 * material instance.
96 *
97 * @param mapId The ID of the map.
98 *
99 * @return One of the following values:
100 * \li the user data stored in the specified map
101 * \li \b 0 if an error happend
102 *****************************************************************************/
103
getMapUserData(int mapId)104 Cal::UserData CalCoreMaterial::getMapUserData(int mapId)
105 {
106 // check if the map id is valid
107 if((mapId < 0) || (mapId >= (int)m_vectorMap.size()))
108 {
109 CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__);
110 return 0;
111 }
112
113 return m_vectorMap[mapId].userData;
114 }
115
116 /*****************************************************************************/
117 /** Returns the shininess factor.
118 *
119 * This function returns the shininess factor of the core material instance.
120 *
121 * @return The shininess factor.
122 *****************************************************************************/
123
getShininess() const124 float CalCoreMaterial::getShininess() const
125 {
126 return m_shininess;
127 }
128
129 /*****************************************************************************/
130 /** Returns the specular color.
131 *
132 * This function returns the specular color of the core material instance.
133 *
134 * @return A reference to the specular color.
135 *****************************************************************************/
136
getSpecularColor()137 CalCoreMaterial::Color& CalCoreMaterial::getSpecularColor()
138 {
139 return m_specularColor;
140 }
141
142 /*****************************************************************************/
143 /** Provides access to the user data.
144 *
145 * This function returns the user data stored in the core material instance.
146 *
147 * @return The user data stored in the core material instance.
148 *****************************************************************************/
149
getUserData()150 Cal::UserData CalCoreMaterial::getUserData()
151 {
152 return m_userData;
153 }
154
155 /*****************************************************************************/
156 /** Returns the map vector.
157 *
158 * This function returns the vector that contains all maps of the core material
159 * instance.
160 *
161 * @return A reference to the map vector.
162 *****************************************************************************/
163
getVectorMap()164 std::vector<CalCoreMaterial::Map>& CalCoreMaterial::getVectorMap()
165 {
166 return m_vectorMap;
167 }
168
169 /*****************************************************************************/
170 /** Reserves memory for the maps.
171 *
172 * This function reserves memory for the maps of the core material instance.
173 *
174 * @param mapCount The number of maps that this core material instance should
175 * be able to hold.
176 *
177 * @return One of the following values:
178 * \li \b true if successful
179 * \li \b false if an error happend
180 *****************************************************************************/
181
reserve(int mapCount)182 bool CalCoreMaterial::reserve(int mapCount)
183 {
184 // reserve the space needed in all the vectors
185 m_vectorMap.reserve(mapCount);
186 m_vectorMap.resize(mapCount);
187
188 return true;
189 }
190
191 /*****************************************************************************/
192 /** Sets the ambient color.
193 *
194 * This function sets the ambient color of the core material instance.
195 *
196 * @param ambientColor The ambient color that should be set.
197 *****************************************************************************/
198
setAmbientColor(const CalCoreMaterial::Color & ambientColor)199 void CalCoreMaterial::setAmbientColor(const CalCoreMaterial::Color& ambientColor)
200 {
201 m_ambientColor = ambientColor;
202 }
203
204 /*****************************************************************************/
205 /** Sets the diffuse color.
206 *
207 * This function sets the diffuse color of the core material instance.
208 *
209 * @param ambientColor The diffuse color that should be set.
210 *****************************************************************************/
211
setDiffuseColor(const CalCoreMaterial::Color & diffuseColor)212 void CalCoreMaterial::setDiffuseColor(const CalCoreMaterial::Color& diffuseColor)
213 {
214 m_diffuseColor = diffuseColor;
215 }
216
217 /*****************************************************************************/
218 /** Sets a specified map.
219 *
220 * This function sets a specified map in the core material instance.
221 *
222 * @param mapId The ID of the map.
223 * @param map The map that should be set.
224 *
225 * @return One of the following values:
226 * \li \b true if successful
227 * \li \b false if an error happend
228 *****************************************************************************/
229
setMap(int mapId,const Map & map)230 bool CalCoreMaterial::setMap(int mapId, const Map& map)
231 {
232 if((mapId < 0) || (mapId >= (int)m_vectorMap.size())) return false;
233
234 m_vectorMap[mapId] = map;
235
236 return true;
237 }
238
239 /*****************************************************************************/
240 /** Stores specified map user data.
241 *
242 * This function stores user data in a specified map of the core material
243 * instance.
244 *
245 * @param mapId The ID of the map.
246 * @param userData The user data that should be stored.
247 *
248 * @return One of the following values:
249 * \li \b true if successful
250 * \li \b false if an error happend
251 *****************************************************************************/
252
setMapUserData(int mapId,Cal::UserData userData)253 bool CalCoreMaterial::setMapUserData(int mapId, Cal::UserData userData)
254 {
255 if((mapId < 0) || (mapId >= (int)m_vectorMap.size())) return false;
256
257 m_vectorMap[mapId].userData = userData;
258
259 return true;
260 }
261
262 /*****************************************************************************/
263 /** Sets the shininess factor.
264 *
265 * This function sets the shininess factor of the core material instance.
266 *
267 * @param shininess The shininess factor that should be set.
268 *****************************************************************************/
269
setShininess(float shininess)270 void CalCoreMaterial::setShininess(float shininess)
271 {
272 m_shininess = shininess;
273 }
274
275 /*****************************************************************************/
276 /** Sets the specular color.
277 *
278 * This function sets the specular color of the core material instance.
279 *
280 * @param ambientColor The specular color that should be set.
281 *****************************************************************************/
282
setSpecularColor(const CalCoreMaterial::Color & specularColor)283 void CalCoreMaterial::setSpecularColor(const CalCoreMaterial::Color& specularColor)
284 {
285 m_specularColor = specularColor;
286 }
287
288
289 /*****************************************************************************/
290 /**
291 * Set the name of the file in which the core material is stored, if any.
292 *
293 * @param filename The path of the file.
294 *****************************************************************************/
295
setFilename(const std::string & filename)296 void CalCoreMaterial::setFilename(const std::string& filename)
297 {
298 m_filename = filename;
299 }
300
301 /*****************************************************************************/
302 /**
303 * Get the name of the file in which the core material is stored, if any.
304 *
305 * @return One of the following values:
306 * \li \b empty string if the material was not stored in a file
307 * \li \b the path of the file
308 *
309 *****************************************************************************/
310
getFilename(void) const311 const std::string& CalCoreMaterial::getFilename(void) const
312 {
313 return m_filename;
314 }
315
316 /*****************************************************************************/
317 /**
318 * Set the symbolic name of the core material.
319 *
320 * @param name A symbolic name.
321 *****************************************************************************/
322
setName(const std::string & name)323 void CalCoreMaterial::setName(const std::string& name)
324 {
325 m_name = name;
326 }
327
328 /*****************************************************************************/
329 /**
330 * Get the symbolic name the core material.
331 *
332 * @return One of the following values:
333 * \li \b empty string if the material was no associated to a symbolic name
334 * \li \b the symbolic name
335 *
336 *****************************************************************************/
337
getName(void) const338 const std::string& CalCoreMaterial::getName(void) const
339 {
340 return m_name;
341 }
342
343 /*****************************************************************************/
344 /** Stores user data.
345 *
346 * This function stores user data in the core material instance.
347 *
348 * @param userData The user data that should be stored.
349 *****************************************************************************/
350
setUserData(Cal::UserData userData)351 void CalCoreMaterial::setUserData(Cal::UserData userData)
352 {
353 m_userData = userData;
354 }
355