Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: renamed all the \param → @param and so on in Doxygen tags.
Thanks a lot to the kDevelop team. this took since the last commit :)

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