Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/physics/src/lib/graphics/importer/material.cc @ 4178

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

orxonox/branches/physics: merged the Trunk into the physics Branche again:
merged with command:
svn merge ../trunk physics -r 3953:HEAD
no important conflicts

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