V-ART
material.cpp
Go to the documentation of this file.
1 
5 #include "vart/material.h"
6 
7 #ifdef WIN32
8 #include <windows.h>
9 #endif
10 #ifdef VART_OGL
11 #include <GL/gl.h>
12 #endif
13 
15  : shininess(0)
16 {
17 }
18 
20 {
21  this->operator=(m);
22 }
23 
25 {
26  SetPlasticColor(c);
27 }
28 
30  : texture(t)
31  , shininess(0)
32 {
33 }
34 
35 VART::Material::Material(const VART::Color& c, float spc, float amb, float ems, float shi)
36 {
37  color = c;
38  c.GetScaled(ems, &emissive);
39  c.GetScaled(amb, &ambient);
40  c.GetScaled(spc, &specular);
41  shininess = shi;
42 }
43 
45 {
46  color = m.color;
47  emissive = m.emissive;
48  ambient = m.ambient;
49  specular = m.specular;
50  shininess = m.shininess;
51  texture = m.texture;
52  return *this;
53 }
54 
56 {
57  color = c;
58  c.GetScaled(0.0001f, &emissive);
59  c.GetScaled(0.3f, &ambient);
60  c.GetScaled(0.1f, &specular);
61  shininess = 0.01f;
62 }
63 
65 {
66  static const VART::Material lpGray(VART::Color(204,204,220));
67  return lpGray;
68 }
69 
71 {
72  static const VART::Material dpGray(VART::Color(127,127,127));
73  return dpGray;
74 }
75 
77 {
78  static const VART::Material pWhite(VART::Color::WHITE());
79  return pWhite;
80 }
81 
83 {
84  static const VART::Material pRed(VART::Color::RED());
85  return pRed;
86 }
87 
89 {
90  static const VART::Material pGreen(VART::Color::GREEN());
91  return pGreen;
92 }
93 
95 {
96  static const VART::Material pBlue(VART::Color::BLUE());
97  return pBlue;
98 }
99 
101 {
102  static const VART::Material pBlack(VART::Color::BLACK());
103  return pBlack;
104 }
105 
107 {
108  texture = t;
109 }
110 
112 {
113 #ifdef VART_OGL
114  float fVec[4];
115 
116  texture.DrawOGL();
117  color.Get(fVec);
118  glColor4fv(fVec);
119  glMaterialfv(GL_FRONT, GL_DIFFUSE, fVec);
120  ambient.Get(fVec);
121  glMaterialfv(GL_FRONT, GL_AMBIENT, fVec);
122  specular.Get(fVec);
123  glMaterialfv(GL_FRONT, GL_SPECULAR, fVec);
124  emissive.Get(fVec);
125  glMaterialfv(GL_FRONT, GL_EMISSION, fVec);
126  glMaterialf(GL_FRONT, GL_SHININESS, shininess);
127  return true;
128 #else
129  return false;
130 #endif
131 }
Material & operator=(const Material &m)
Copies all texture data from one to another.
Definition: material.cpp:44
static const Color & RED()
Red opaque color.
Definition: color.cpp:75
static const Color & BLUE()
Blue opaque color.
Definition: color.cpp:85
Header file for V-ART class "Material".
void SetPlasticColor(const VART::Color &c)
Makes the material to have a plastic-looking of given color.
Definition: material.cpp:55
static const Color & GREEN()
Green opaque color.
Definition: color.cpp:80
static const Material & PLASTIC_BLUE()
Definition: material.cpp:94
static const Material & DARK_PLASTIC_GRAY()
Definition: material.cpp:70
RGBA color representation.
Definition: color.h:24
static const Material & PLASTIC_WHITE()
Definition: material.cpp:76
void SetTexture(const Texture &t)
Sets the texture of material.
Definition: material.cpp:106
static const Material & LIGHT_PLASTIC_GRAY()
Definition: material.cpp:64
static const Material & PLASTIC_BLACK()
Definition: material.cpp:100
2D image to use as texture.
Definition: texture.h:48
void GetScaled(float escalar, float result[4]) const
Multiplies RGB components, keeps A component.
Definition: color.cpp:178
Material properties for graphical objects.
Definition: material.h:16
static const Color & BLACK()
Black opaque color.
Definition: color.cpp:70
static const Material & PLASTIC_RED()
Definition: material.cpp:82
bool DrawOGL() const
Draws the material using OpenGL engine.
Definition: material.cpp:111
static const Color & WHITE()
White opaque color.
Definition: color.cpp:105
static const Material & PLASTIC_GREEN()
Definition: material.cpp:88