added util/Color module, updated Light and PointLight

git-svn-id: svn://anubis/fart/trunk@49 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2009-01-26 20:08:42 +00:00
parent 072bf75c04
commit e0d545a6b7
6 changed files with 76 additions and 7 deletions

View File

@ -2,7 +2,7 @@
#include "Light.h" #include "Light.h"
#include "util/Vector.h" #include "util/Vector.h"
Light::Light(const Vector & position) Light::Light(const Vector & position, const Color & color)
{ {
m_position = position; m_position = position;
} }

View File

@ -3,14 +3,15 @@
#define LIGHT_H LIGHT_H #define LIGHT_H LIGHT_H
#include "util/Vector.h" #include "util/Vector.h"
#include "util/Color.h"
class Light class Light
{ {
public: public:
Light(const Vector & position); Light(const Vector & position, const Color & color = Color::white);
const Vector & getPosition() const { return m_position; } const Vector & getPosition() const { return m_position; }
private: protected:
Vector m_position; Vector m_position;
}; };

View File

@ -1,7 +1,7 @@
#include "PointLight.h" #include "PointLight.h"
PointLight::PointLight(const Vector & position) PointLight::PointLight(const Vector & position, const Color & color)
: Light(position) : Light(position, color)
{ {
} }

View File

@ -3,13 +3,14 @@
#define POINTLIGHT_H POINTLIGHT_H #define POINTLIGHT_H POINTLIGHT_H
#include "Light.h" #include "Light.h"
#include "util/Color.h"
class PointLight : public Light class PointLight : public Light
{ {
public: public:
PointLight(const Vector & position); PointLight(const Vector & position, const Color & color = Color::white);
private: protected:
}; };
#endif #endif

40
util/Color.cc Normal file
View File

@ -0,0 +1,40 @@
#include "Color.h"
const Color Color::black = Color(0, 0, 0);
const Color Color::white = Color(1, 1, 1);
const Color Color::red = Color(1, 0, 0);
const Color Color::green = Color(0, 1, 0);
const Color Color::blue = Color(0, 0, 1);
Color::Color()
{
r = g = b = 1.0;
}
Color::Color(double r, double g, double b)
{
this->r = r;
this->g = g;
this->b = b;
}
Color Color::operator*(double scale)
{
return Color(r * scale, g * scale, b * scale);
}
Color Color::operator/(double scale)
{
return Color(r / scale, g / scale, b / scale);
}
Color operator+(const Color & c1, const Color & c2)
{
return Color(c1.r + c2.r, c1.g + c2.g, c1.b + c2.b);
}
Color operator-(const Color & c1, const Color & c2)
{
return Color(c1.r - c2.r, c1.g - c2.g, c1.b - c2.b);
}

27
util/Color.h Executable file
View File

@ -0,0 +1,27 @@
#ifndef COLOR_H
#define COLOR_H COLOR_H
class Color
{
public:
double r, g, b;
Color();
Color(double r, double g, double b);
Color operator*(double scale);
Color operator/(double scale);
static const Color black;
static const Color white;
static const Color red;
static const Color green;
static const Color blue;
};
Color operator+(const Color & c1, const Color & c2);
Color operator-(const Color & c1, const Color & c2);
#endif