Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/importer/material.cc @ 5228

Last change on this file since 5228 was 4836, checked in by bensch, 19 years ago

orxonox/trunk: renamed all the \param → @param and so on in Doxygen tags.
Thanks a lot to the kDevelop team. this took since the last commit :)

File size: 7.3 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14
15*/
16
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER
18
19#include "material.h"
20
21#include "texture.h"
22#include "debug.h"
23#include "resource_manager.h"
24#include <stdlib.h>
25#include <string.h>
26
27//! @todo check if we are in RESOURCE MANAGER-mode
28#include "resource_manager.h"
29
30using namespace std;
31
32/**
33 *  creates a Material.
34 * @param mtlName Name of the Material to be added to the Material List
35*/
36Material::Material (const char* mtlName)
37{
38  PRINTF(4)("initializing new Material.\n");
39  this->setIllum(3);
40  this->setDiffuse(0,0,0);
41  this->setAmbient(0,0,0);
42  this->setSpecular(.5,.5,.5);
43  this->setShininess(2.0);
44  this->setTransparency(1.0);
45
46  this->diffuseTexture = NULL;
47  this->ambientTexture = NULL;
48  this->specularTexture = NULL;
49
50  this->setName(mtlName);
51}
52
53/**
54  *  deletes a Material
55*/
56Material::~Material()
57{
58  PRINTF(4)("delete Material %s.\n", this->getName());
59
60  if (this->diffuseTexture)
61    ResourceManager::getInstance()->unload(this->diffuseTexture);
62  if (this->ambientTexture)
63    ResourceManager::getInstance()->unload(this->ambientTexture);
64  if (this->specularTexture)
65    ResourceManager::getInstance()->unload(this->specularTexture);
66}
67
68/**
69 *  sets the material with which the following Faces will be painted
70*/
71bool Material::select ()
72{
73  // setting diffuse color
74  //  glColor3f (diffuse[0], diffuse[1], diffuse[2]);
75  glMaterialfv(GL_FRONT, GL_DIFFUSE, this->diffuse);
76
77  // setting ambient color
78  glMaterialfv(GL_FRONT, GL_AMBIENT, this->ambient);
79
80  // setting up Sprecular
81  glMaterialfv(GL_FRONT, GL_SPECULAR, this->specular);
82
83  // setting up Shininess
84  glMaterialf(GL_FRONT, GL_SHININESS, this->shininess);
85
86  // setting the transparency
87  if (this->transparency < 1.0)
88    {
89      glEnable(GL_BLEND);
90      glColor4f(1.0f, 1.0f, 1.0f, this->transparency);
91      glBlendFunc(GL_SRC_ALPHA, GL_ONE);
92    }
93  else
94    {
95      glDisable(GL_BLEND);
96      glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
97    }
98
99
100  // setting illumination Model
101  if (this->illumModel == 1) //! @todo make this work, if no vertex-normals are read.
102    glShadeModel(GL_FLAT);
103  else if (this->illumModel >= 2)
104    glShadeModel(GL_SMOOTH);
105
106  if (this->diffuseTexture)
107    {
108      glEnable(GL_TEXTURE_2D);
109      glBindTexture(GL_TEXTURE_2D, this->diffuseTexture->getTexture());
110
111      /* This allows alpha blending of 2D textures with the scene */
112      if (this->diffuseTexture->hasAlpha())
113        {
114          glEnable(GL_BLEND);
115          glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
116        }
117    }
118  else
119    {
120      glDisable(GL_TEXTURE_2D);
121      glBindTexture(GL_TEXTURE_2D, 0);
122    }
123}
124
125/**
126 *  Sets the Material Illumination Model.
127 *  illu illumination Model in int form
128*/
129void Material::setIllum (int illum)
130{
131  PRINTF(4)("setting illumModel of Material %s to %i\n", this->getName(), illum);
132  this->illumModel = illum;
133}
134/**
135 *  Sets the Material Illumination Model.
136 *  illu illumination Model in char* form
137*/void Material::setIllum (char* illum)
138{
139  this->setIllum (atoi(illum));
140}
141
142/**
143 *  Sets the Material Diffuse Color.
144 * @param r Red Color Channel.
145 * @param g Green Color Channel.
146 * @param b Blue Color Channel.
147*/
148void Material::setDiffuse (float r, float g, float b)
149{
150  PRINTF(4)("setting Diffuse Color of Material %s to r=%f g=%f b=%f.\n", this->getName(), r, g, b);
151  this->diffuse[0] = r;
152  this->diffuse[1] = g;
153  this->diffuse[2] = b;
154  this->diffuse[3] = 1.0;
155
156}
157/**
158 *  Sets the Material Diffuse Color.
159 * @param rgb The red, green, blue channel in char format (with spaces between them)
160*/
161void Material::setDiffuse (char* rgb)
162{
163  float r,g,b;
164  sscanf (rgb, "%f %f %f", &r, &g, &b);
165  this->setDiffuse (r, g, b);
166}
167
168/**
169 *  Sets the Material Ambient Color.
170 * @param r Red Color Channel.
171 * @param g Green Color Channel.
172 * @param b Blue Color Channel.
173*/
174void Material::setAmbient (float r, float g, float b)
175{
176  PRINTF(4)("setting Ambient Color of Material %s to r=%f g=%f b=%f.\n", this->getName(), r, g, b);
177  this->ambient[0] = r;
178  this->ambient[1] = g;
179  this->ambient[2] = b;
180  this->ambient[3] = 1.0;
181}
182/**
183 *  Sets the Material Ambient Color.
184 * @param rgb The red, green, blue channel in char format (with spaces between them)
185*/
186void Material::setAmbient (char* rgb)
187{
188  float r,g,b;
189  sscanf (rgb, "%f %f %f", &r, &g, &b);
190  this->setAmbient (r, g, b);
191}
192
193/**
194 *  Sets the Material Specular Color.
195 * @param r Red Color Channel.
196 * @param g Green Color Channel.
197 * @param b Blue Color Channel.
198*/
199void Material::setSpecular (float r, float g, float b)
200{
201  PRINTF(4)("setting Specular Color of Material %s to r=%f g=%f b=%f.\n", this->getName(), r, g, b);
202  this->specular[0] = r;
203  this->specular[1] = g;
204  this->specular[2] = b;
205  this->specular[3] = 1.0;
206 }
207/**
208 *  Sets the Material Specular Color.
209 * @param rgb The red, green, blue channel in char format (with spaces between them)
210*/
211void Material::setSpecular (char* rgb)
212{
213  float r,g,b;
214  sscanf (rgb, "%f %f %f", &r, &g, &b);
215  this->setSpecular (r, g, b);
216}
217
218/**
219 *  Sets the Material Shininess.
220 * @param shini stes the Shininess from float.
221*/
222void Material::setShininess (float shini)
223{
224  this->shininess = shini;
225}
226/**
227 *  Sets the Material Shininess.
228 * @param shini stes the Shininess from char*.
229*/
230void Material::setShininess (char* shini)
231{
232  this->setShininess (atof(shini));
233}
234
235/**
236 *  Sets the Material Transparency.
237 * @param trans stes the Transparency from int.
238*/
239void Material::setTransparency (float trans)
240{
241  PRINTF(4)("setting Transparency of Material %s to %f.\n", this->getName(), trans);
242  this->transparency = trans;
243}
244/**
245 *  Sets the Material Transparency.
246 * @param trans stes the Transparency from char*.
247*/
248void Material::setTransparency (char* trans)
249{
250  this->setTransparency (atof(trans));
251}
252
253/**
254 *  Adds a Texture Path to the List of already existing Paths
255 * @param pathName The Path to add.
256*/
257void Material::addTexturePath(const char* pathName)
258{
259  ResourceManager::getInstance()->addImageDir(pathName);
260}
261
262// MAPPING //
263
264/**
265 *  Sets the Materials Diffuse Map
266 * @param dMap the Name of the Image to Use
267*/
268void Material::setDiffuseMap(const char* dMap)
269{
270  PRINTF(4)("setting Diffuse Map %s\n", dMap);
271  if (this->diffuseTexture)
272    ResourceManager::getInstance()->unload(this->diffuseTexture);
273
274  //! @todo check if RESOURCE MANAGER is availiable
275  //! @todo Textures from .mtl-file need special care.
276  if (dMap!= NULL)
277    this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE);
278  else
279    this->diffuseTexture = NULL;
280}
281
282/**
283 *  Sets the Materials Ambient Map
284 * @param aMap the Name of the Image to Use
285   @todo implement this
286*/
287void Material::setAmbientMap(const char* aMap)
288{
289  SDL_Surface* ambientMap;
290
291}
292
293/**
294 *  Sets the Materials Specular Map
295 * @param sMap the Name of the Image to Use
296   @todo implement this
297*/
298void Material::setSpecularMap(const char* sMap)
299{
300  SDL_Surface* specularMap;
301
302}
303
304/**
305 *  Sets the Materials Bumpiness
306 * @param bump the Name of the Image to Use
307   @todo implemet this
308*/
309void Material::setBump(const char* bump)
310{
311
312}
Note: See TracBrowser for help on using the repository browser.