Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/levelloader/src/lib/graphics/importer/material.cc @ 3605

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

orxonox/trunk: merged trunk back to levelloader
merged with command:
svn merge -r 3499:HEAD trunk branches/levelloader

Conflicts in
C track_manager.h
C world_entities/player.cc
C world_entities/player.h
C world_entities/environment.h
C lib/coord/p_node.cc
C defs/debug.h
C track_manager.cc
C story_entities/campaign.h

solved in merge-favouring. It was quite easy because Chris only worked on the headers, and he didi it quite clean. Thats the spirit :)

Conflits in world.cc are a MESS: fix it

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