2013-11-13 19:07:35 +00:00
|
|
|
#include "SurfaceMaterial.h"
|
|
|
|
|
|
|
|
#include "PackStream.h"
|
2015-08-19 17:14:59 +00:00
|
|
|
#include "Color.h"
|
2013-11-13 19:07:35 +00:00
|
|
|
|
2015-11-08 22:32:52 +00:00
|
|
|
static SurfaceMaterial DEFAULT;
|
|
|
|
|
2013-12-25 18:45:56 +00:00
|
|
|
SurfaceMaterial::SurfaceMaterial():
|
|
|
|
SurfaceMaterial(COLOR_BLACK)
|
2013-11-13 19:07:35 +00:00
|
|
|
{
|
2013-12-25 18:45:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceMaterial::SurfaceMaterial(const Color &color)
|
|
|
|
{
|
2015-08-19 17:14:59 +00:00
|
|
|
base = new Color(color);
|
2013-12-25 18:45:56 +00:00
|
|
|
hardness = 0.5;
|
|
|
|
reflection = 0.0;
|
|
|
|
shininess = 0.0;
|
|
|
|
receive_shadows = 1.0;
|
|
|
|
}
|
|
|
|
|
2015-10-18 15:26:19 +00:00
|
|
|
SurfaceMaterial::SurfaceMaterial(const SurfaceMaterial &other):
|
|
|
|
SurfaceMaterial(COLOR_BLACK)
|
|
|
|
{
|
|
|
|
other.copy(this);
|
|
|
|
}
|
|
|
|
|
2015-08-19 17:14:59 +00:00
|
|
|
SurfaceMaterial::~SurfaceMaterial()
|
|
|
|
{
|
|
|
|
delete base;
|
|
|
|
}
|
|
|
|
|
2015-11-08 22:32:52 +00:00
|
|
|
const SurfaceMaterial &SurfaceMaterial::getDefault()
|
|
|
|
{
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-08-19 17:14:59 +00:00
|
|
|
void SurfaceMaterial::setColor(double r, double g, double b, double a)
|
|
|
|
{
|
|
|
|
base->r = r;
|
|
|
|
base->g = g;
|
|
|
|
base->b = b;
|
|
|
|
base->a = a;
|
|
|
|
}
|
|
|
|
|
2013-12-25 18:45:56 +00:00
|
|
|
void SurfaceMaterial::save(PackStream* stream) const
|
|
|
|
{
|
2015-08-19 17:14:59 +00:00
|
|
|
base->save(stream);
|
2013-11-13 19:07:35 +00:00
|
|
|
|
2013-12-25 18:45:56 +00:00
|
|
|
stream->write(&hardness);
|
|
|
|
stream->write(&reflection);
|
|
|
|
stream->write(&shininess);
|
2013-11-13 19:07:35 +00:00
|
|
|
|
2013-12-25 18:45:56 +00:00
|
|
|
stream->write(&receive_shadows);
|
2013-11-13 19:07:35 +00:00
|
|
|
}
|
|
|
|
|
2013-12-25 18:45:56 +00:00
|
|
|
void SurfaceMaterial::load(PackStream* stream)
|
2013-11-13 19:07:35 +00:00
|
|
|
{
|
2015-08-19 17:14:59 +00:00
|
|
|
base->load(stream);
|
2013-11-13 19:07:35 +00:00
|
|
|
|
2013-12-25 18:45:56 +00:00
|
|
|
stream->read(&hardness);
|
|
|
|
stream->read(&reflection);
|
|
|
|
stream->read(&shininess);
|
2013-11-13 19:07:35 +00:00
|
|
|
|
2013-12-25 18:45:56 +00:00
|
|
|
stream->read(&receive_shadows);
|
2013-11-13 19:07:35 +00:00
|
|
|
}
|
|
|
|
|
2015-10-15 18:28:05 +00:00
|
|
|
void SurfaceMaterial::copy(SurfaceMaterial *destination) const
|
|
|
|
{
|
|
|
|
*destination->base = *base;
|
|
|
|
destination->hardness = hardness;
|
|
|
|
destination->reflection = reflection;
|
|
|
|
destination->shininess = shininess;
|
|
|
|
destination->receive_shadows = receive_shadows;
|
|
|
|
destination->validate();
|
|
|
|
}
|
|
|
|
|
2013-12-25 18:45:56 +00:00
|
|
|
void SurfaceMaterial::validate()
|
2013-11-13 19:07:35 +00:00
|
|
|
{
|
|
|
|
}
|