Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/importer/material.cc @ 2836

Last change on this file since 2836 was 2836, checked in by bensch, 20 years ago

orxonox/trunk/importer: ability to read in specular shininess

File size: 4.1 KB
Line 
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: ...
14*/
15
16#include "material.h"
17
18Material::Material()
19{
20  init();
21 
22  setName ("");
23}
24
25Material::Material (char* mtlName)
26{
27  init();
28 
29  setName (mtlName);
30}
31
32Material* Material::addMaterial(char* mtlName)
33{
34  if (verbose >=2)
35    printf ("adding Material %s\n", mtlName);
36  Material* newMat = new Material(mtlName);
37  Material* tmpMat = this;
38  while (tmpMat->nextMat != NULL)
39    {
40      tmpMat = tmpMat->nextMat;
41    }
42      tmpMat->nextMat = newMat;
43      return newMat;
44 
45}
46
47void Material::init(void)
48{
49  if (verbose >= 3)
50    printf ("initializing new Material\n");
51  nextMat = NULL;
52
53  setIllum(1);
54  setDiffuse(0,0,0);
55  setAmbient(0,0,0);
56  setSpecular(0,0,0);
57  setShininess(0.0);
58  setTransparency(0.0);
59 
60}
61
62
63void Material::setName (char* mtlName)
64{
65  if (verbose >= 3)
66    printf("setting Material Name to %s", mtlName);
67  strcpy(name, mtlName);
68  //  printf ("adding new Material: %s, %p\n", this->getName(), this);
69
70}
71char* Material::getName (void)
72{
73  return name;
74}
75
76
77void Material::setIllum (int illum)
78{
79  if (verbose >= 3)
80    printf("setting illumModel of Material %s to %i", name, illum);
81  illumModel = illum;
82  //  printf ("setting illumModel to: %i\n", illumModel);
83}
84void Material::setIllum (char* illum)
85{
86  setIllum (atoi(illum));
87}
88
89void Material::setDiffuse (float r, float g, float b)
90{
91  if (verbose >= 3)
92    printf ("setting Diffuse Color of Material %s to r=%f g=%f b=%f\n", name, r, g, b);
93  diffuse[0] = r;
94  diffuse[1] = g;
95  diffuse[2] = b; 
96  diffuse[3] = 1.0;
97
98}
99void Material::setDiffuse (char* rgb)
100{
101  char r[20],g[20],b[20];
102  sscanf (rgb, "%s %s %s", r, g, b);
103  setDiffuse (atof(r), atof(g), atof(b));
104}
105
106void Material::setAmbient (float r, float g, float b)
107{
108  if (verbose >=3)
109    printf ("setting Ambient Color of Material %s to r=%f g=%f b=%f\n", name, r, g, b);
110  ambient[0] = r;
111  ambient[1] = g;
112  ambient[2] = b;
113  ambient[3] = 1.0;
114}
115void Material::setAmbient (char* rgb)
116{
117  char r[20],g[20],b[20];
118  sscanf (rgb, "%s %s %s", r, g, b);
119  setAmbient (atof(r), atof(g), atof(b));
120}
121
122void Material::setSpecular (float r, float g, float b)
123{
124  if (verbose >= 3)
125    printf ("setting Specular Color of Material %s to r=%f g=%f b=%f\n", name, r, g, b);
126  specular[0] = r;
127  specular[1] = g;
128  specular[2] = b;
129  specular[3] = 1.0;
130 }
131void Material::setSpecular (char* rgb)
132{
133  char r[20],g[20],b[20];
134  sscanf (rgb, "%s %s %s", r, g, b);
135  setSpecular (atof(r), atof(g), atof(b));
136}
137
138void Material::setShininess (float shini)
139{
140  shininess = shini;
141}
142void Material::setShininess (char* shini)
143{
144  setShininess (atof(shini));
145}
146
147void Material::setTransparency (float trans)
148{
149  if (verbose >= 3)
150    printf ("setting Transparency of Material %s to %f\n", name, trans);
151  transparency = trans;
152}
153void Material::setTransparency (char* trans)
154{
155  char tr[20];
156  sscanf (trans, "%s", tr);
157  setTransparency (atof(tr));
158}
159
160
161Material* Material::search (char* mtlName)
162{
163  if (verbose >=3)
164    printf ("Searching for material %s", mtlName);
165  Material* searcher = this;
166  while (searcher != NULL)
167    {
168      if (verbose >= 3)
169        printf (".");
170      if (!strcmp (searcher->getName(), mtlName))
171        {
172          if (verbose >= 3)
173            printf ("found.\n");
174          return searcher;
175        }
176      searcher = searcher->nextMat;
177    }
178  return NULL;
179}
180
181bool Material::select (void)
182{
183  // setting diffuse color
184  //  glColor3f (diffuse[0], diffuse[1], diffuse[2]);
185  glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
186
187  // setting ambient color
188  glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
189
190  // setting up Sprecular
191  glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
192
193  // setting up Shininess
194  glMaterialf(GL_FRONT, GL_SHININESS, shininess);
195 
196  // setting illumination Model
197  if (illumModel == 1)
198    glShadeModel(GL_FLAT);
199  else if (illumModel >= 2)
200    glShadeModel(GL_SMOOTH);
201}
Note: See TracBrowser for help on using the repository browser.