Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/parenting/src/importer/material.cc @ 3340

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

orxonox/branches/parenting: :importer: moved code from textures into new file texture.h/cc

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