Game Development Reference
In-Depth Information
class Material
{
D3DMATERIAL9 m_D3DMaterial;
public:
Material()
{
ZeroMemory( &m_D3DMaterial, sizeof( D3DMATERIAL9 ) );
m_D3DMaterial.Diffuse = g_White;
m_D3DMaterial.Ambient = Color(0.10f, 0.10f, 0.10f, 1.0f);
m_D3DMaterial.Specular = g_White;
m_D3DMaterial.Emissive = g_Black;
}
void SetAmbient(const Color &color)
{ m_D3DMaterial.Ambient = color; }
const Color GetAmbient() { return m_D3DMaterial.Ambient; }
void SetDiffuse(const Color &color)
{ m_D3DMaterial.Diffuse = color; }
const Color GetDiffuse() { return m_D3DMaterial.Diffuse; }
void SetSpecular(const Color &color, const float power)
{
m_D3DMaterial.Specular = color; m_D3DMaterial.Power = power;
}
void GetSpecular(Color &_color, float &_power)
{ _color = m_D3DMaterial.Specular; _power = m_D3DMaterial.Power; }
void SetEmissive(const Color &color)
{ m_D3DMaterial.Emissive = color; }
const Color GetEmissive() { return m_D3DMaterial.Emissive; }
void SetAlpha(const float alpha)
{ m_D3DMaterial.Diffuse.a = alpha; }
bool HasAlpha() const { return GetAlpha() != fOPAQUE; }
float GetAlpha() const { return m_D3DMaterial.Diffuse.a; }
};
The material has four different color components. Generally, you
ll set the ambient
and diffuse color to the same thing, but you might get a black object by mistake. If
you set an object
'
s diffuse and ambient material to 100% blue, and you put that
object in an environment with 100% red light, it will appear black. That
'
'
s because a
'
100% blue object doesn
t reflect any red light. Fix this by putting a little red in either
the diffuse or ambient color. The specular color is usually set to white or gray and
defines the color of the shininess the object takes on. Lastly, the emissive component
Search WWH ::




Custom Search