Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3085 in orxonox.OLD


Ignore:
Timestamp:
Dec 4, 2004, 5:26:18 PM (19 years ago)
Author:
bensch
Message:

orxonox/branches/images: bring order to Chaos

Location:
orxonox/branches/images/importer
Files:
2 edited

Legend:

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

    r3080 r3085  
    9393 
    9494}
    95 
    96 /**
    97    \brief Set the Name of the Material. (Important for searching)
    98    \param mtlName the Name of the Material to be set.
    99 */
    100 void Material::setName (char* mtlName)
    101 {
    102   //  if (verbose >= 3)
    103     printf("setting Material Name to %s.\n", mtlName);
    104   name = new char [strlen(mtlName)];
    105   strcpy(name, mtlName);
    106   //  printf ("adding new Material: %s, %p\n", this->getName(), this);
    107 
    108 }
    109 /**
    110    \returns The Name of The Material
    111 */
    112 char* Material::getName (void)
    113 {
    114   return name;
    115 }
    116 
    117 /**
    118    \brief Sets the Material Illumination Model.
    119    \brief illu illumination Model in int form
    120 */
    121 void Material::setIllum (int illum)
    122 {
    123   if (verbose >= 3)
    124     printf("setting illumModel of Material %s to %i", name, illum);
    125   illumModel = illum;
    126   //  printf ("setting illumModel to: %i\n", illumModel);
    127 }
    128 /**
    129    \brief Sets the Material Illumination Model.
    130    \brief illu illumination Model in char* form
    131 */void Material::setIllum (char* illum)
    132 {
    133   setIllum (atoi(illum));
    134 }
    135 
    136 /**
    137    \brief Sets the Material Diffuse Color.
    138    \param r Red Color Channel.
    139    \param g Green Color Channel.
    140    \param b Blue Color Channel.
    141 */
    142 void Material::setDiffuse (float r, float g, float b)
    143 {
    144   if (verbose >= 3)
    145     printf ("setting Diffuse Color of Material %s to r=%f g=%f b=%f.\n", name, r, g, b);
    146   diffuse[0] = r;
    147   diffuse[1] = g;
    148   diffuse[2] = b; 
    149   diffuse[3] = 1.0;
    150 
    151 }
    152 /**
    153    \brief Sets the Material Diffuse Color.
    154    \param rgb The red, green, blue channel in char format (with spaces between them)
    155 */
    156 void Material::setDiffuse (char* rgb)
    157 {
    158   char r[20],g[20],b[20];
    159   sscanf (rgb, "%s %s %s", r, g, b);
    160   setDiffuse (atof(r), atof(g), atof(b));
    161 }
    162 
    163 /**
    164    \brief Sets the Material Ambient Color.
    165    \param r Red Color Channel.
    166    \param g Green Color Channel.
    167    \param b Blue Color Channel.
    168 */
    169 void Material::setAmbient (float r, float g, float b)
    170 {
    171   if (verbose >=3)
    172     printf ("setting Ambient Color of Material %s to r=%f g=%f b=%f.\n", name, r, g, b);
    173   ambient[0] = r;
    174   ambient[1] = g;
    175   ambient[2] = b;
    176   ambient[3] = 1.0;
    177 }
    178 /**
    179    \brief Sets the Material Ambient Color.
    180    \param rgb The red, green, blue channel in char format (with spaces between them)
    181 */
    182 void Material::setAmbient (char* rgb)
    183 {
    184   char r[20],g[20],b[20];
    185   sscanf (rgb, "%s %s %s", r, g, b);
    186   setAmbient (atof(r), atof(g), atof(b));
    187 }
    188 
    189 /**
    190    \brief Sets the Material Specular Color.
    191    \param r Red Color Channel.
    192    \param g Green Color Channel.
    193    \param b Blue Color Channel.
    194 */
    195 void Material::setSpecular (float r, float g, float b)
    196 {
    197   if (verbose >= 3)
    198     printf ("setting Specular Color of Material %s to r=%f g=%f b=%f.\n", name, r, g, b);
    199   specular[0] = r;
    200   specular[1] = g;
    201   specular[2] = b;
    202   specular[3] = 1.0;
    203  }
    204 /**
    205    \brief Sets the Material Specular Color.
    206    \param rgb The red, green, blue channel in char format (with spaces between them)
    207 */
    208 void Material::setSpecular (char* rgb)
    209 {
    210   char r[20],g[20],b[20];
    211   sscanf (rgb, "%s %s %s", r, g, b);
    212   setSpecular (atof(r), atof(g), atof(b));
    213 }
    214 
    215 /**
    216    \brief Sets the Material Shininess.
    217    \param shini stes the Shininess from float.
    218 */
    219 void Material::setShininess (float shini)
    220 {
    221   shininess = shini;
    222 }
    223 /**
    224    \brief Sets the Material Shininess.
    225    \param shini stes the Shininess from char*.
    226 */
    227 void Material::setShininess (char* shini)
    228 {
    229   setShininess (atof(shini));
    230 }
    231 
    232 /**
    233    \brief Sets the Material Transparency.
    234    \param trans stes the Transparency from int.
    235 */
    236 void Material::setTransparency (float trans)
    237 {
    238   if (verbose >= 3)
    239     printf ("setting Transparency of Material %s to %f.\n", name, trans);
    240   transparency = trans;
    241 }
    242 /**
    243    \brief Sets the Material Transparency.
    244    \param trans stes the Transparency from char*.
    245 */
    246 void Material::setTransparency (char* trans)
    247 {
    248   char tr[20];
    249   sscanf (trans, "%s", tr);
    250   setTransparency (atof(tr));
    251 }
    252 
    253 // MAPPING //
    254 
    255 /**
    256    \brief Sets the Materials Diffuse Map
    257    \param dMap the Name of the Image to Use
    258 */
    259 void Material::setDiffuseMap(char* dMap)
    260 {
    261   if (verbose>=2)
    262     printf ("setting Diffuse Map %s\n", dMap);
    263 
    264   diffuseTextureSet = loadBMP(dMap, &diffuseTexture);
    265 
    266 }
    267 
    268 /**
    269    \brief Sets the Materials Ambient Map
    270    \param aMap the Name of the Image to Use
    271 */
    272 void Material::setAmbientMap(char* aMap)
    273 {
    274   SDL_Surface* ambientMap;
    275 
    276 }
    277 
    278 /**
    279    \brief Sets the Materials Specular Map
    280    \param sMap the Name of the Image to Use
    281 */
    282 void Material::setSpecularMap(char* sMap)
    283 {
    284   SDL_Surface* specularMap;
    285 
    286 }
    287 
    288 /**
    289    \brief Sets the Materials Bumpiness
    290    \param bump the Name of the Image to Use
    291 */
    292 void Material::setBump(char* bump)
    293 {
    294 
    295 }
    296 
    297 /**
    298    \brief reads in a Windows BMP-file, and imports it to openGL.
    299    \param bmpName The name of the Image to load.
    300    \param texture A pointer to the Texture which should be read to.
    301 */
    302 bool Material::loadBMP (char* bmpName, GLuint* texture)
    303 {
    304   SDL_Surface* map;
    305   if (map = SDL_LoadBMP(bmpName))
    306     {
    307 
    308       glGenTextures( 1, texture );
    309       /* Typical Texture Generation Using Data From The Bitmap */
    310       glBindTexture( GL_TEXTURE_2D, *texture );
    311      
    312       /* Generate The Texture */
    313       glTexImage2D( GL_TEXTURE_2D, 0, 3, map->w,
    314                     map->h, 0, GL_BGR,
    315                     GL_UNSIGNED_BYTE, map->pixels );
    316      
    317       /* Linear Filtering */
    318       glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    319       glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    320       if ( map )
    321         SDL_FreeSurface( map );
    322 
    323       return true;
    324     }
    325   else
    326     return false;
    327 }
    328 
    329 
    330 
    33195
    33296/**
     
    385149 
    386150}
     151
     152
     153/**
     154   \brief Set the Name of the Material. (Important for searching)
     155   \param mtlName the Name of the Material to be set.
     156*/
     157void Material::setName (char* mtlName)
     158{
     159  //  if (verbose >= 3)
     160    printf("setting Material Name to %s.\n", mtlName);
     161  name = new char [strlen(mtlName)];
     162  strcpy(name, mtlName);
     163  //  printf ("adding new Material: %s, %p\n", this->getName(), this);
     164
     165}
     166/**
     167   \returns The Name of The Material
     168*/
     169char* Material::getName (void)
     170{
     171  return name;
     172}
     173
     174/**
     175   \brief Sets the Material Illumination Model.
     176   \brief illu illumination Model in int form
     177*/
     178void Material::setIllum (int illum)
     179{
     180  if (verbose >= 3)
     181    printf("setting illumModel of Material %s to %i", name, illum);
     182  illumModel = illum;
     183  //  printf ("setting illumModel to: %i\n", illumModel);
     184}
     185/**
     186   \brief Sets the Material Illumination Model.
     187   \brief illu illumination Model in char* form
     188*/void Material::setIllum (char* illum)
     189{
     190  setIllum (atoi(illum));
     191}
     192
     193/**
     194   \brief Sets the Material Diffuse Color.
     195   \param r Red Color Channel.
     196   \param g Green Color Channel.
     197   \param b Blue Color Channel.
     198*/
     199void Material::setDiffuse (float r, float g, float b)
     200{
     201  if (verbose >= 3)
     202    printf ("setting Diffuse Color of Material %s to r=%f g=%f b=%f.\n", name, r, g, b);
     203  diffuse[0] = r;
     204  diffuse[1] = g;
     205  diffuse[2] = b; 
     206  diffuse[3] = 1.0;
     207
     208}
     209/**
     210   \brief Sets the Material Diffuse Color.
     211   \param rgb The red, green, blue channel in char format (with spaces between them)
     212*/
     213void Material::setDiffuse (char* rgb)
     214{
     215  char r[20],g[20],b[20];
     216  sscanf (rgb, "%s %s %s", r, g, b);
     217  setDiffuse (atof(r), atof(g), atof(b));
     218}
     219
     220/**
     221   \brief Sets the Material Ambient Color.
     222   \param r Red Color Channel.
     223   \param g Green Color Channel.
     224   \param b Blue Color Channel.
     225*/
     226void Material::setAmbient (float r, float g, float b)
     227{
     228  if (verbose >=3)
     229    printf ("setting Ambient Color of Material %s to r=%f g=%f b=%f.\n", name, r, g, b);
     230  ambient[0] = r;
     231  ambient[1] = g;
     232  ambient[2] = b;
     233  ambient[3] = 1.0;
     234}
     235/**
     236   \brief Sets the Material Ambient Color.
     237   \param rgb The red, green, blue channel in char format (with spaces between them)
     238*/
     239void Material::setAmbient (char* rgb)
     240{
     241  char r[20],g[20],b[20];
     242  sscanf (rgb, "%s %s %s", r, g, b);
     243  setAmbient (atof(r), atof(g), atof(b));
     244}
     245
     246/**
     247   \brief Sets the Material Specular Color.
     248   \param r Red Color Channel.
     249   \param g Green Color Channel.
     250   \param b Blue Color Channel.
     251*/
     252void Material::setSpecular (float r, float g, float b)
     253{
     254  if (verbose >= 3)
     255    printf ("setting Specular Color of Material %s to r=%f g=%f b=%f.\n", name, r, g, b);
     256  specular[0] = r;
     257  specular[1] = g;
     258  specular[2] = b;
     259  specular[3] = 1.0;
     260 }
     261/**
     262   \brief Sets the Material Specular Color.
     263   \param rgb The red, green, blue channel in char format (with spaces between them)
     264*/
     265void Material::setSpecular (char* rgb)
     266{
     267  char r[20],g[20],b[20];
     268  sscanf (rgb, "%s %s %s", r, g, b);
     269  setSpecular (atof(r), atof(g), atof(b));
     270}
     271
     272/**
     273   \brief Sets the Material Shininess.
     274   \param shini stes the Shininess from float.
     275*/
     276void Material::setShininess (float shini)
     277{
     278  shininess = shini;
     279}
     280/**
     281   \brief Sets the Material Shininess.
     282   \param shini stes the Shininess from char*.
     283*/
     284void Material::setShininess (char* shini)
     285{
     286  setShininess (atof(shini));
     287}
     288
     289/**
     290   \brief Sets the Material Transparency.
     291   \param trans stes the Transparency from int.
     292*/
     293void Material::setTransparency (float trans)
     294{
     295  if (verbose >= 3)
     296    printf ("setting Transparency of Material %s to %f.\n", name, trans);
     297  transparency = trans;
     298}
     299/**
     300   \brief Sets the Material Transparency.
     301   \param trans stes the Transparency from char*.
     302*/
     303void Material::setTransparency (char* trans)
     304{
     305  char tr[20];
     306  sscanf (trans, "%s", tr);
     307  setTransparency (atof(tr));
     308}
     309
     310// MAPPING //
     311
     312/**
     313   \brief Sets the Materials Diffuse Map
     314   \param dMap the Name of the Image to Use
     315*/
     316void Material::setDiffuseMap(char* dMap)
     317{
     318  if (verbose>=2)
     319    printf ("setting Diffuse Map %s\n", dMap);
     320
     321  diffuseTextureSet = loadBMP(dMap, &diffuseTexture);
     322
     323}
     324
     325/**
     326   \brief Sets the Materials Ambient Map
     327   \param aMap the Name of the Image to Use
     328*/
     329void Material::setAmbientMap(char* aMap)
     330{
     331  SDL_Surface* ambientMap;
     332
     333}
     334
     335/**
     336   \brief Sets the Materials Specular Map
     337   \param sMap the Name of the Image to Use
     338*/
     339void Material::setSpecularMap(char* sMap)
     340{
     341  SDL_Surface* specularMap;
     342
     343}
     344
     345/**
     346   \brief Sets the Materials Bumpiness
     347   \param bump the Name of the Image to Use
     348*/
     349void Material::setBump(char* bump)
     350{
     351
     352}
     353
     354/**
     355   \brief reads in a Windows BMP-file, and imports it to openGL.
     356   \param bmpName The name of the Image to load.
     357   \param texture A pointer to the Texture which should be read to.
     358*/
     359bool Material::loadBMP (char* bmpName, GLuint* texture)
     360{
     361  SDL_Surface* map;
     362  if (map = SDL_LoadBMP(bmpName))
     363    {
     364
     365      glGenTextures( 1, texture );
     366      /* Typical Texture Generation Using Data From The Bitmap */
     367      glBindTexture( GL_TEXTURE_2D, *texture );
     368     
     369      /* Generate The Texture */
     370      glTexImage2D( GL_TEXTURE_2D, 0, 3, map->w,
     371                    map->h, 0, GL_BGR,
     372                    GL_UNSIGNED_BYTE, map->pixels );
     373     
     374      /* Linear Filtering */
     375      glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
     376      glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
     377      if ( map )
     378        SDL_FreeSurface( map );
     379
     380      return true;
     381    }
     382  else
     383    return false;
     384}
     385
     386
     387
     388
  • orxonox/branches/images/importer/material.h

    r3070 r3085  
    1515#include <fstream>
    1616
     17// IMAGE LIBS //
     18#include <jpeglib.h>
     19
    1720//! Class to handle Materials.
    1821class Material
     
    2225  Material (char* mtlName);
    2326  Material* addMaterial(char* mtlName);
     27  ~Material ();
     28  void init(void);
    2429
    25   void init(void);
    26   ~Material ();
     30  Material* search (char* mtlName);
     31  bool select (void);
    2732
    2833  GLuint diffuseTexture;
     
    4954  void setTransparency (char* trans);
    5055
     56
     57
     58
    5159  // MAPPING //
    5260  void setDiffuseMap(char* dMap);
     
    5563  void setBump(char* bump);
    5664
     65  // TEXTURING
    5766  bool loadBMP (char* bmpName, GLuint* texture);
    58 
    59 
    60   Material* search (char* mtlName);
    61 
    62   bool select (void);
    63 
    64   Material* nextMat; //!< pointer to the Next Material of the List. NULL if no next exists.
    6567
    6668 private:
     
    7274  float shininess;
    7375  float transparency;
     76  Material* nextMat; //!< pointer to the Next Material of the List. NULL if no next exists.
    7477
    7578};
Note: See TracChangeset for help on using the changeset viewer.