Clean up for Lights (and AmbientLights)
This commit is contained in:
parent
d085a192e8
commit
e1ded8a9ad
2 changed files with 80 additions and 122 deletions
143
src/light.cc
143
src/light.cc
|
@ -1,112 +1,77 @@
|
||||||
/* light.cc
|
/* light.cc
|
||||||
*
|
* vim: set tw=80:
|
||||||
* Lights light the scene.
|
|
||||||
*
|
|
||||||
* Eryn Wells <eryn@erynwells.me>
|
* Eryn Wells <eryn@erynwells.me>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "basics.h"
|
#include "light.hh"
|
||||||
#include "light.h"
|
|
||||||
#include "object.h"
|
|
||||||
|
|
||||||
#pragma mark - Ambient Lights
|
|
||||||
|
|
||||||
AmbientLight::AmbientLight()
|
using charles::basics::Color;
|
||||||
: AmbientLight(Color::White)
|
|
||||||
|
|
||||||
|
namespace charles {
|
||||||
|
|
||||||
|
Light::Light(const Color& color,
|
||||||
|
const Double& intensity)
|
||||||
|
: mColor(color),
|
||||||
|
mIntensity(ClampIntensity(intensity))
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
||||||
AmbientLight::AmbientLight(const Color &c)
|
Color&
|
||||||
: AmbientLight(c, 0.0)
|
Light::GetColor()
|
||||||
{ }
|
|
||||||
|
|
||||||
|
|
||||||
AmbientLight::AmbientLight(const Color &c, const float &i)
|
|
||||||
: color(c),
|
|
||||||
intensity(i)
|
|
||||||
{
|
{
|
||||||
_clamp_intensity();
|
return mColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const Color &
|
const Color&
|
||||||
AmbientLight::get_color()
|
Light::GetColor()
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
return color;
|
return mColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const float &
|
void
|
||||||
AmbientLight::get_intensity()
|
Light::SetColor(const Color& color)
|
||||||
|
{
|
||||||
|
mColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Double
|
||||||
|
Light::GetIntensity()
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
|
return mIntensity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Light::SetIntensity(const Double& intensity)
|
||||||
|
{
|
||||||
|
mIntensity = ClampIntensity(intensity);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Color&&
|
||||||
|
Light::Contribution()
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return mColor * mIntensity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Double
|
||||||
|
Light::ClampIntensity(const Double& intensity)
|
||||||
|
{
|
||||||
|
if (intensity < 0.0) {
|
||||||
|
return 0.0;
|
||||||
|
} else if (intensity > 1.0) {
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
return intensity;
|
return intensity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
} /* namespace charles */
|
||||||
AmbientLight::set_intensity(const float &i)
|
|
||||||
{
|
|
||||||
intensity = i;
|
|
||||||
_clamp_intensity();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Color
|
|
||||||
AmbientLight::compute_color_contribution()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return color * intensity;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
AmbientLight::_clamp_intensity()
|
|
||||||
{
|
|
||||||
if (intensity < 0.0) {
|
|
||||||
intensity = 0.0;
|
|
||||||
}
|
|
||||||
else if (intensity > 1.0) {
|
|
||||||
intensity = 1.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - Point Lights
|
|
||||||
|
|
||||||
PointLight::PointLight()
|
|
||||||
: PointLight(Vector3())
|
|
||||||
{ }
|
|
||||||
|
|
||||||
|
|
||||||
PointLight::PointLight(const Vector3 &o)
|
|
||||||
: PointLight(o, Color::White)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
|
|
||||||
PointLight::PointLight(const Vector3 &o,
|
|
||||||
const Color &c)
|
|
||||||
: PointLight(o, c, 1.0)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
|
|
||||||
PointLight::PointLight(const Vector3 &o,
|
|
||||||
const Color &c,
|
|
||||||
const float &i)
|
|
||||||
: AmbientLight(c, i),
|
|
||||||
mOrigin(o)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
|
|
||||||
const Vector3&
|
|
||||||
PointLight::GetOrigin()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return mOrigin;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
PointLight::SetOrigin(const Vector3& origin)
|
|
||||||
{
|
|
||||||
mOrigin = origin;
|
|
||||||
}
|
|
||||||
|
|
59
src/light.hh
59
src/light.hh
|
@ -1,53 +1,46 @@
|
||||||
/* light.h
|
/* light.hh
|
||||||
*
|
* vim: set tw=80:
|
||||||
* Lights light the scene.
|
|
||||||
*
|
|
||||||
* Eryn Wells <eryn@erynwells.me>
|
* Eryn Wells <eryn@erynwells.me>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __LIGHT_H__
|
#ifndef __LIGHT_H__
|
||||||
#define __LIGHT_H__
|
#define __LIGHT_H__
|
||||||
|
|
||||||
#include "basics.h"
|
#include "basics/basics.hh"
|
||||||
|
|
||||||
|
|
||||||
class AmbientLight
|
namespace charles {
|
||||||
|
|
||||||
|
struct Light
|
||||||
{
|
{
|
||||||
public:
|
Light(const basics::Color& color,
|
||||||
AmbientLight();
|
const Double& intensity = 1.0);
|
||||||
AmbientLight(const Color &c);
|
|
||||||
AmbientLight(const Color &c, const float &i);
|
|
||||||
|
|
||||||
const Color &get_color() const;
|
basics::Color& GetColor();
|
||||||
const float &get_intensity() const;
|
const basics::Color& GetColor() const;
|
||||||
void set_intensity(const float &i);
|
void SetColor(basics::Color& color);
|
||||||
|
|
||||||
Color compute_color_contribution() const;
|
Double GetIntensity() const;
|
||||||
|
void SetIntensity(const Double& intensity);
|
||||||
|
|
||||||
protected:
|
basics::Color&& Contribution() const;
|
||||||
Color color;
|
|
||||||
float intensity;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _clamp_intensity();
|
Double ClampIntensity(const Double& intensity);
|
||||||
|
|
||||||
|
/** The color of the light. */
|
||||||
|
basics::Color mColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The intensity of the light. Normal values range from 0.0 to 1.0, but
|
||||||
|
* they can be set higher.
|
||||||
|
*/
|
||||||
|
Double mIntensity;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class PointLight
|
typedef Light AmbientLight;
|
||||||
: public AmbientLight
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
PointLight();
|
|
||||||
|
|
||||||
PointLight(const Vector3 &o);
|
} /* namespace charles */
|
||||||
PointLight(const Vector3 &o, const Color &c);
|
|
||||||
PointLight(const Vector3 &o, const Color &c, const float &i);
|
|
||||||
|
|
||||||
const Vector3& GetOrigin() const;
|
|
||||||
void SetOrigin(const Vector3& origin);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Vector3 mOrigin;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue