Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4677 was 4584, checked in by bensch, 19 years ago

orxonox/trunk: TrackElement and Material are BaseObjects now

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