Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2778 in orxonox.OLD


Ignore:
Timestamp:
Nov 10, 2004, 3:54:08 AM (20 years ago)
Author:
bensch
Message:

orxonox/branches/importer: reimplemented class material. searcher works now, all options are really set.

Location:
orxonox/branches/importer/importer
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/importer/importer/material.cc

    r2776 r2778  
    11#include "material.h"
    2 
    3 Material* Material::firstMat = NULL;
    4 Material* Material::currentMat = NULL;
    52
    63Material::Material()
    74{
    85  init();
     6 
     7  setName ("");
    98}
    109
     
    1615}
    1716
     17Material* Material::addMaterial(char* mtlName)
     18{
     19  Material* newMat = new Material(mtlName);
     20  Material* tmpMat = this;
     21  while (tmpMat->nextMat != NULL)
     22    {
     23      tmpMat = tmpMat->nextMat;
     24    }
     25      tmpMat->nextMat = newMat;
     26      return newMat;
     27 
     28}
     29
    1830void Material::init(void)
    1931{
    20   if (firstMat == NULL)
    21     firstMat = this;
    22   else
    23     currentMat->nextMat = this;
    24   currentMat = this;
    2532  nextMat = NULL;
     33
     34  setIllum(1);
     35  setDiffuse(0,0,0);
     36  setAmbient(0,0,0);
     37  setSpecular(0,0,0);
     38  setTransparency(0.0);
    2639}
    2740
     
    2942void Material::setName (char* mtlName)
    3043{
    31   name = mtlName;
    32   //printf ("adding new Material: %s, %p\n", firstMat->name, firstMat);
     44  strcpy(name, mtlName);
     45  //  printf ("adding new Material: %s, %p\n", this->getName(), this);
    3346
     47}
     48char* Material::getName (void)
     49{
     50  return name;
    3451}
    3552
     
    5067  diffuse[1] = g;
    5168  diffuse[2] = b;
    52   printf ("setting Diffuse Color to r=%f g=%f b=%f\n", r, g, b);
     69  //  printf ("setting Diffuse Color to r=%f g=%f b=%f\n", r, g, b);
    5370}
    5471void Material::setDiffuse (char* rgb)
     
    6481  ambient[1] = g;
    6582  ambient[2] = b;
    66   printf ("setting Ambient Color to r=%f g=%f b=%f\n", r, g, b);
     83  //  printf ("setting Ambient Color to r=%f g=%f b=%f\n", r, g, b);
    6784}
    6885void Material::setAmbient (char* rgb)
     
    7895  specular[1] = g;
    7996  specular[2] = b;
    80   printf ("setting Specular Color to r=%f g=%f b=%f\n", r, g, b);
     97  //printf ("setting Specular Color to r=%f g=%f b=%f\n", r, g, b);
    8198}
    8299void Material::setSpecular (char* rgb)
     
    98115  setTransparency (atof(tr));
    99116}
     117
     118
     119Material* Material::search (char* mtlName)
     120{
     121  Material* searcher = this;
     122  while (searcher != NULL)
     123    {
     124      if (!strcmp (searcher->getName(), mtlName))
     125        return searcher;
     126      searcher = searcher->nextMat;
     127    }
     128  return NULL;
     129}
     130
     131bool Material::select (void)
     132{
     133  glColor3f (diffuse[0], diffuse[1], diffuse[2]);
     134}
  • orxonox/branches/importer/importer/material.h

    r2776 r2778  
    1111  Material ();
    1212  Material (char* mtlName);
     13  Material* addMaterial(char* mtlName);
     14
    1315  void init(void);
    1416  ~Material ();
    15  
     17
     18
    1619  void setName (char* mtlName);
     20  char* getName (void);
    1721  void setIllum (int illum);
    1822  void setIllum (char* illum);
     
    2630  void setTransparency (char* trans);
    2731
     32  Material* search (char* mtlName);
    2833
    2934  bool select (void);
    3035
     36  Material* nextMat;
     37
    3138 private:
    32   char* name;
     39  char name [50];
    3340  int illumModel;
    3441  float diffuse [3];
     
    3744  float transparency;
    3845
    39   Material* nextMat;
    40   static Material* firstMat;
    41   static Material* currentMat;
    4246};
    4347#endif
  • orxonox/branches/importer/importer/object.cc

    r2776 r2778  
    191191  vertices = new Array();
    192192  faces = new Array();
    193  
     193  material = new Material();
     194  Material* tmpMat = material;
    194195  while(!MTL_FILE->eof())
    195196    {
     
    201202      if (!strncmp(Buffer, "newmtl ", 2))
    202203        {
    203           material = new Material(Buffer+7);
     204          tmpMat = tmpMat->addMaterial(Buffer+7);
     205          printf ("%s, %p\n", tmpMat->getName(), tmpMat);
    204206        }
    205207      // setting a illumMode
    206208      else if (!strncmp(Buffer, "illum", 5))
    207209        {
    208           material->setIllum(Buffer+6);
     210          tmpMat->setIllum(Buffer+6);
     211
    209212        }
    210213      // setting Diffuse Color
    211214      else if (!strncmp(Buffer, "Kd", 2))
    212215        {
    213           material->setDiffuse(Buffer+3);
     216          tmpMat->setDiffuse(Buffer+3);
    214217        }
    215218      // setting Ambient Color
    216219      else if (!strncmp(Buffer, "Ka", 2))
    217220        {
    218           material->setAmbient(Buffer+3);
     221          tmpMat->setAmbient(Buffer+3);
    219222        }
    220223      // setting Specular Color
    221224      else if (!strncmp(Buffer, "Ks", 2))
    222225        {
    223           material->setSpecular(Buffer+3);
    224         }
    225      
    226 
    227 
     226          tmpMat->setSpecular(Buffer+3);
     227        }
    228228    }
    229229  return true;
Note: See TracChangeset for help on using the changeset viewer.