Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Sphers Rendered around the Turret-Power-Up (this looks really bad)

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