Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/importer/material.cc @ 3415

Last change on this file since 3415 was 3396, checked in by bensch, 20 years ago

orxonox/trunk: splitted obj-loader out of the model-class: this will enable different kinds of Filetypes to be included with the importer.
Althought there is a name-field error, the Model gets loaded and unloaded as good as previously

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