Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/importer/src/material.cc @ 2808

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

orxonox/branches/importer: importer includes into the source

File size: 2.8 KB
Line 
1#include "material.h"
2
3Material::Material()
4{
5  init();
6 
7  setName ("");
8}
9
10Material::Material (char* mtlName)
11{
12  init();
13 
14  setName (mtlName);
15}
16
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
30void Material::init(void)
31{
32  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);
39}
40
41
42void Material::setName (char* mtlName)
43{
44  strcpy(name, mtlName);
45  //  printf ("adding new Material: %s, %p\n", this->getName(), this);
46
47}
48char* Material::getName (void)
49{
50  return name;
51}
52
53
54void Material::setIllum (int illum)
55{
56  illumModel = illum;
57  //  printf ("setting illumModel to: %i\n", illumModel);
58}
59void Material::setIllum (char* illum)
60{
61  setIllum (atoi(illum));
62}
63
64void Material::setDiffuse (float r, float g, float b)
65{
66  diffuse[0] = r;
67  diffuse[1] = g;
68  diffuse[2] = b; 
69  diffuse[3] = 1.0;
70
71  //  printf ("setting Diffuse Color to r=%f g=%f b=%f\n", r, g, b);
72}
73void Material::setDiffuse (char* rgb)
74{
75  char r[20],g[20],b[20];
76  sscanf (rgb, "%s %s %s", r, g, b);
77  setDiffuse (atof(r), atof(g), atof(b));
78}
79
80void Material::setAmbient (float r, float g, float b)
81{
82  ambient[0] = r;
83  ambient[1] = g;
84  ambient[2] = b;
85  ambient[3] = 1.0;
86  //  printf ("setting Ambient Color to r=%f g=%f b=%f\n", r, g, b);
87}
88void Material::setAmbient (char* rgb)
89{
90  char r[20],g[20],b[20];
91  sscanf (rgb, "%s %s %s", r, g, b);
92  setAmbient (atof(r), atof(g), atof(b));
93}
94
95void Material::setSpecular (float r, float g, float b)
96{
97  specular[0] = r;
98  specular[1] = g;
99  specular[2] = b;
100  specular[3] = 1.0;
101  //printf ("setting Specular Color to r=%f g=%f b=%f\n", r, g, b);
102}
103void Material::setSpecular (char* rgb)
104{
105  char r[20],g[20],b[20];
106  sscanf (rgb, "%s %s %s", r, g, b);
107  setSpecular (atof(r), atof(g), atof(b));
108}
109
110
111void Material::setTransparency (float trans)
112{
113  transparency = trans;
114}
115void Material::setTransparency (char* trans)
116{
117  char tr[20];
118  sscanf (trans, "%s", tr);
119  setTransparency (atof(tr));
120}
121
122
123Material* Material::search (char* mtlName)
124{
125  Material* searcher = this;
126  while (searcher != NULL)
127    {
128      if (!strcmp (searcher->getName(), mtlName))
129        return searcher;
130      searcher = searcher->nextMat;
131    }
132  return NULL;
133}
134
135bool Material::select (void)
136{
137  // setting diffuse color
138  //  glColor3f (diffuse[0], diffuse[1], diffuse[2]);
139  glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
140
141  // setting ambient color
142  glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
143
144  // setting up Sprecular
145  glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
146 
147  // setting illumination Model
148  if (illumModel == 1)
149    glShadeModel(GL_FLAT);
150  else if (illumModel >= 2)
151    glShadeModel(GL_SMOOTH);
152}
Note: See TracBrowser for help on using the repository browser.