Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk/importer: now uses c++ lib <fstream>, and added the OrxOnoX Headers

File size: 3.9 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  setTransparency(0.0);
58}
59
60
61void Material::setName (char* mtlName)
62{
63  if (verbose >= 3)
64    printf("setting Material Name to %s", mtlName);
65  strcpy(name, mtlName);
66  //  printf ("adding new Material: %s, %p\n", this->getName(), this);
67
68}
69char* Material::getName (void)
70{
71  return name;
72}
73
74
75void Material::setIllum (int illum)
76{
77  if (verbose >= 3)
78    printf("setting illumModel of Material %s to %i", name, illum);
79  illumModel = illum;
80  //  printf ("setting illumModel to: %i\n", illumModel);
81}
82void Material::setIllum (char* illum)
83{
84  setIllum (atoi(illum));
85}
86
87void Material::setDiffuse (float r, float g, float b)
88{
89  if (verbose >= 3)
90    printf ("setting Diffuse Color of Material %s to r=%f g=%f b=%f\n", name, r, g, b);
91  diffuse[0] = r;
92  diffuse[1] = g;
93  diffuse[2] = b; 
94  diffuse[3] = 1.0;
95
96}
97void Material::setDiffuse (char* rgb)
98{
99  char r[20],g[20],b[20];
100  sscanf (rgb, "%s %s %s", r, g, b);
101  setDiffuse (atof(r), atof(g), atof(b));
102}
103
104void Material::setAmbient (float r, float g, float b)
105{
106  if (verbose >=3)
107    printf ("setting Ambient Color of Material %s to r=%f g=%f b=%f\n", name, r, g, b);
108  ambient[0] = r;
109  ambient[1] = g;
110  ambient[2] = b;
111  ambient[3] = 1.0;
112}
113void Material::setAmbient (char* rgb)
114{
115  char r[20],g[20],b[20];
116  sscanf (rgb, "%s %s %s", r, g, b);
117  setAmbient (atof(r), atof(g), atof(b));
118}
119
120void Material::setSpecular (float r, float g, float b)
121{
122  if (verbose >= 3)
123    printf ("setting Specular Color of Material %s to r=%f g=%f b=%f\n", name, r, g, b);
124  specular[0] = r;
125  specular[1] = g;
126  specular[2] = b;
127  specular[3] = 1.0;
128 }
129void Material::setSpecular (char* rgb)
130{
131  char r[20],g[20],b[20];
132  sscanf (rgb, "%s %s %s", r, g, b);
133  setSpecular (atof(r), atof(g), atof(b));
134}
135
136
137void Material::setTransparency (float trans)
138{
139  if (verbose >= 3)
140    printf ("setting Transparency of Material %s to %f\n", name, trans);
141  transparency = trans;
142}
143void Material::setTransparency (char* trans)
144{
145  char tr[20];
146  sscanf (trans, "%s", tr);
147  setTransparency (atof(tr));
148}
149
150
151Material* Material::search (char* mtlName)
152{
153  if (verbose >=3)
154    printf ("Searching for material %s", mtlName);
155  Material* searcher = this;
156  while (searcher != NULL)
157    {
158      if (verbose >= 3)
159        printf (".");
160      if (!strcmp (searcher->getName(), mtlName))
161        {
162          if (verbose >= 3)
163            printf ("found.\n");
164          return searcher;
165        }
166      searcher = searcher->nextMat;
167    }
168  return NULL;
169}
170
171bool Material::select (void)
172{
173  // setting diffuse color
174  //  glColor3f (diffuse[0], diffuse[1], diffuse[2]);
175  glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
176
177  // setting ambient color
178  glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
179
180  // setting up Sprecular
181  glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
182 
183  // setting illumination Model
184  if (illumModel == 1)
185    glShadeModel(GL_FLAT);
186  else if (illumModel >= 2)
187    glShadeModel(GL_SMOOTH);
188}
Note: See TracBrowser for help on using the repository browser.