Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4054 was 3966, checked in by bensch, 20 years ago

orxonox/trunk: merged branches/particleEngine into the trunk, because of the new vector class
merged with command:
svn merge -r 3922:HEAD particleEngine/ ../trunk/

not merged src/story_entities/world.cc. will do this at a later time (do not forget)

File size: 7.8 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   \brief 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->name = NULL;
40  this->setIllum(3);
41  this->setDiffuse(0,0,0);
42  this->setAmbient(0,0,0);
43  this->setSpecular(.5,.5,.5);
44  this->setShininess(2.0);
45  this->setTransparency(1.0);
46
47
48  this->diffuseTexture = NULL;
49  this->ambientTexture = NULL;
50  this->specularTexture = NULL;
51
52  this->diffuseTextureSet = false;
53  this->ambientTextureSet = false;
54  this->specularTextureSet = false;
55
56  this->setName(mtlName);
57}
58
59/**
60    \brief deletes a Material
61*/
62Material::~Material()
63{
64  PRINTF(4)("delete Material %s.\n", this->name);
65  if (this->name)
66    delete []this->name;
67  if (this->diffuseTexture)
68    ResourceManager::getInstance()->unload(this->diffuseTexture);
69}
70
71/**
72   \brief sets the material with which the following Faces will be painted
73*/
74bool Material::select (void)
75{
76  // setting diffuse color
77  //  glColor3f (diffuse[0], diffuse[1], diffuse[2]);
78  glMaterialfv(GL_FRONT, GL_DIFFUSE, this->diffuse);
79
80  // setting ambient color
81  glMaterialfv(GL_FRONT, GL_AMBIENT, this->ambient);
82
83  // setting up Sprecular
84  glMaterialfv(GL_FRONT, GL_SPECULAR, this->specular);
85
86  // setting up Shininess
87  glMaterialf(GL_FRONT, GL_SHININESS, this->shininess);
88 
89  // setting the transparency
90  if (this->transparency < 1.0)
91    {
92      glEnable(GL_BLEND);
93      glColor4f(1.0f, 1.0f, 1.0f, this->transparency);
94      glBlendFunc(GL_SRC_ALPHA, GL_ONE);
95    }
96  else
97    {
98      glDisable(GL_BLEND);
99      glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
100    }
101
102
103  // setting illumination Model
104  if (this->illumModel == 1) //! \todo make this work, if no vertex-normals are read.
105    glShadeModel(GL_FLAT);
106  else if (this->illumModel >= 2)
107    glShadeModel(GL_SMOOTH);
108
109  if (this->diffuseTextureSet)
110    {
111      glEnable(GL_TEXTURE_2D);
112      glBindTexture(GL_TEXTURE_2D, this->diffuseTexture->getTexture());
113
114      /* This allows alpha blending of 2D textures with the scene */
115      if (this->diffuseTexture->hasAlpha())
116        {
117          glEnable(GL_BLEND);
118          glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
119        }
120    }
121  else
122    {
123      glDisable(GL_TEXTURE_2D);
124      glBindTexture(GL_TEXTURE_2D, 0);
125    }
126}
127
128/**
129   \brief Set the Name of the Material. (Important for searching)
130   \param mtlName the Name of the Material to be set.
131*/ 
132void Material::setName (const char* mtlName)
133{
134  if (this->name)
135    delete this->name;
136  if (mtlName)
137    {
138      this->name = new char [strlen(mtlName)+1];
139      strcpy(this->name, mtlName);
140    }
141  else
142    {
143      this->name = new char[2];
144      strcpy(this->name, "");
145    }
146}
147
148/**
149   \returns The Name of The Material
150*/
151char* Material::getName (void)
152{
153  return this->name;
154}
155
156/**
157   \brief Sets the Material Illumination Model.
158   \brief illu illumination Model in int form
159*/
160void Material::setIllum (int illum)
161{
162  PRINTF(4)("setting illumModel of Material %s to %i\n", this->name, illum);
163  this->illumModel = illum;
164}
165/**
166   \brief Sets the Material Illumination Model.
167   \brief illu illumination Model in char* form
168*/void Material::setIllum (char* illum)
169{
170  this->setIllum (atoi(illum));
171}
172
173/**
174   \brief Sets the Material Diffuse Color.
175   \param r Red Color Channel.
176   \param g Green Color Channel.
177   \param b Blue Color Channel.
178*/
179void Material::setDiffuse (float r, float g, float b)
180{
181  PRINTF(4)("setting Diffuse Color of Material %s to r=%f g=%f b=%f.\n", this->name, r, g, b);
182  this->diffuse[0] = r;
183  this->diffuse[1] = g;
184  this->diffuse[2] = b; 
185  this->diffuse[3] = 1.0;
186
187}
188/**
189   \brief Sets the Material Diffuse Color.
190   \param rgb The red, green, blue channel in char format (with spaces between them)
191*/
192void Material::setDiffuse (char* rgb)
193{
194  float r,g,b;
195  sscanf (rgb, "%f %f %f", &r, &g, &b);
196  this->setDiffuse (r, g, b);
197}
198
199/**
200   \brief Sets the Material Ambient Color.
201   \param r Red Color Channel.
202   \param g Green Color Channel.
203   \param b Blue Color Channel.
204*/
205void Material::setAmbient (float r, float g, float b)
206{
207  PRINTF(4)("setting Ambient Color of Material %s to r=%f g=%f b=%f.\n", this->name, r, g, b);
208  this->ambient[0] = r;
209  this->ambient[1] = g;
210  this->ambient[2] = b;
211  this->ambient[3] = 1.0;
212}
213/**
214   \brief Sets the Material Ambient Color.
215   \param rgb The red, green, blue channel in char format (with spaces between them)
216*/
217void Material::setAmbient (char* rgb)
218{
219  float r,g,b;
220  sscanf (rgb, "%f %f %f", &r, &g, &b);
221  this->setAmbient (r, g, b);
222}
223
224/**
225   \brief Sets the Material Specular Color.
226   \param r Red Color Channel.
227   \param g Green Color Channel.
228   \param b Blue Color Channel.
229*/
230void Material::setSpecular (float r, float g, float b)
231{
232  PRINTF(4)("setting Specular Color of Material %s to r=%f g=%f b=%f.\n", this->name, r, g, b);
233  this->specular[0] = r;
234  this->specular[1] = g;
235  this->specular[2] = b;
236  this->specular[3] = 1.0;
237 }
238/**
239   \brief Sets the Material Specular Color.
240   \param rgb The red, green, blue channel in char format (with spaces between them)
241*/
242void Material::setSpecular (char* rgb)
243{
244  float r,g,b;
245  sscanf (rgb, "%f %f %f", &r, &g, &b);
246  this->setSpecular (r, g, b);
247}
248
249/**
250   \brief Sets the Material Shininess.
251   \param shini stes the Shininess from float.
252*/
253void Material::setShininess (float shini)
254{
255  this->shininess = shini;
256}
257/**
258   \brief Sets the Material Shininess.
259   \param shini stes the Shininess from char*.
260*/
261void Material::setShininess (char* shini)
262{
263  this->setShininess (atof(shini));
264}
265
266/**
267   \brief Sets the Material Transparency.
268   \param trans stes the Transparency from int.
269*/
270void Material::setTransparency (float trans)
271{
272  PRINTF(4)("setting Transparency of Material %s to %f.\n", this->name, trans);
273  this->transparency = trans;
274}
275/**
276   \brief Sets the Material Transparency.
277   \param trans stes the Transparency from char*.
278*/
279void Material::setTransparency (char* trans)
280{
281  this->setTransparency (atof(trans));
282}
283
284/**
285   \brief Adds a Texture Path to the List of already existing Paths
286   \param pathName The Path to add.
287*/
288void Material::addTexturePath(char* pathName)
289{
290  ResourceManager::getInstance()->addImageDir(pathName);
291}
292
293// MAPPING //
294
295/**
296   \brief Sets the Materials Diffuse Map
297   \param dMap the Name of the Image to Use
298*/
299void Material::setDiffuseMap(const char* dMap)
300{
301  PRINTF(4)("setting Diffuse Map %s\n", dMap);
302  //    diffuseTexture = new Texture();
303  //    this->diffuseTextureSet = diffuseTexture->loadImage(dMap);
304
305  //! \todo check if RESOURCE MANAGER is availiable
306  //! \todo Textures from .mtl-file need special care.
307  this->diffuseTextureSet = this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE);
308}
309
310/**
311   \brief Sets the Materials Ambient Map
312   \param aMap the Name of the Image to Use
313   \todo implement this
314*/
315void Material::setAmbientMap(const char* aMap)
316{
317  SDL_Surface* ambientMap;
318
319}
320
321/**
322   \brief Sets the Materials Specular Map
323   \param sMap the Name of the Image to Use
324   \todo implement this
325*/
326void Material::setSpecularMap(const char* sMap)
327{
328  SDL_Surface* specularMap;
329
330}
331
332/**
333   \brief Sets the Materials Bumpiness
334   \param bump the Name of the Image to Use
335   \todo implemet this
336*/
337void Material::setBump(const char* bump)
338{
339
340}
Note: See TracBrowser for help on using the repository browser.