Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/physics/src/lib/graphics/importer/material.cc @ 3953

Last change on this file since 3953 was 3953, checked in by patrick, 19 years ago

orxonox/branches/physics: merged with trunk - with command svn merge -r 3866:HEAD

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