Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: TrackElement and Material are BaseObjects now

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