#include "dms/Material.h"

namespace dms
{

Material::Material(void)
    {
    ambient_.set(0.2, 0.2, 0.2, 1.0);
    diffuse_.set(0.8, 0.8, 0.8, 1.0);
    specular_.set(0, 0, 0, 1);
    emission_.set(0, 0, 0, 1);
    shininess_ = 0;
    }


Material::Material(const Vector4& color)
    {
    ambient_ = color;
    diffuse_ = color;
    specular_.set(0, 0, 0, 1);
    emission_.set(0, 0, 0, 1);
    shininess_ = 0;
    }


Material::Material(const Vector4& ambientAndDiffuse,
                   const Vector4& specular,GLfloat shininess)
    {
    ambient_ = ambientAndDiffuse;
    diffuse_ = ambientAndDiffuse;
    specular_ = specular;
    emission_.set(0, 0, 0, 1);
    shininess_ = shininess;
    }


void Material::apply(void)
    {
    glEnable(GL_LIGHTING);
    glMaterialfv(GL_FRONT, GL_AMBIENT, ambient_.vec);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse_.vec);
    glMaterialfv(GL_FRONT, GL_SPECULAR, specular_.vec);
    glMaterialfv(GL_FRONT, GL_EMISSION, emission_.vec);
    glMaterialf(GL_FRONT, GL_SHININESS, shininess_);
    }


void Material::disable(void)
    {
    glDisable(GL_LIGHTING);
    }


void Material::setAmbient(const Vector4& color)
    {
    ambient_ = color;
    }


void Material::setDiffuse(const Vector4& color)
    {
    diffuse_ = color;
    }


void Material::setAmbientAndDiffuse(const Vector4& color)
    {
    setAmbient(color);
    setDiffuse(color);
    }


void Material::setSpecular(const Vector4& color)
    {
    specular_ = color;
    }


void Material::setEmission(const Vector4& color)
    {
    emission_ = color;
    }


void Material::setShininess(GLfloat shininess)
    {
    shininess_ = shininess;
    }

}
