metaforce/Runtime/Graphics/CLight.hpp

138 lines
3.7 KiB
C++
Raw Normal View History

2016-02-13 09:02:47 +00:00
#ifndef __PSHAG_CLIGHT_HPP__
#define __PSHAG_CLIGHT_HPP__
2015-08-21 00:06:39 +00:00
2016-03-04 23:04:53 +00:00
#include "zeus/CVector3f.hpp"
#include "zeus/CColor.hpp"
2016-03-16 20:49:35 +00:00
#include "RetroTypes.hpp"
2016-03-04 23:04:53 +00:00
namespace urde
{
enum class ELightType
{
2016-03-16 20:49:35 +00:00
Spot = 0,
Point = 1,
Directional = 2,
LocalAmbient = 3,
Custom = 4,
2016-03-04 23:04:53 +00:00
};
enum class EFalloffType
{
Constant,
Linear,
Quadratic
};
2015-08-21 00:06:39 +00:00
class CLight
{
2016-03-16 20:49:35 +00:00
friend class CGuiLight;
zeus::CVector3f x0_pos;
zeus::CVector3f xc_dir;
zeus::CColor x18_color;
ELightType x1c_type;
float x20_spotCutoff;
float x24_distC;
float x28_distL;
float x2c_distQ;
float x30_angleC;
float x34_angleL;
float x38_angleQ;
u32 x3c_ = 0;
u32 x40_loadedIdx = 0;
float x44_cachedRadius;
float x48_cachedIntensity;
bool x4c_24_intensityDirty : 1;
bool x4c_25_radiusDirty : 1;
float CalculateLightRadius() const;
2016-03-04 23:04:53 +00:00
public:
2016-03-16 20:49:35 +00:00
CLight(const zeus::CVector3f& pos,
const zeus::CVector3f& dir,
const zeus::CColor& color,
float distC, float distL, float distQ,
float angleC, float angleL, float angleQ)
: x0_pos(pos), xc_dir(dir), x18_color(color),
x1c_type(ELightType::Custom), x20_spotCutoff(0.f),
x24_distC(distC), x28_distL(distL), x2c_distQ(distQ),
x30_angleC(angleC), x34_angleL(angleL), x38_angleQ(angleQ),
x44_cachedRadius(0.f), x48_cachedIntensity(0.f),
x4c_24_intensityDirty(true), x4c_25_radiusDirty(true)
{}
CLight(ELightType type,
const zeus::CVector3f& pos,
const zeus::CVector3f& dir,
const zeus::CColor& color,
float cutoff)
: x0_pos(pos), xc_dir(dir), x18_color(color),
x1c_type(type), x20_spotCutoff(cutoff),
x24_distC(0.f), x28_distL(1.f), x2c_distQ(0.f),
x30_angleC(0.f), x34_angleL(1.f), x38_angleQ(0.f),
x44_cachedRadius(0.f), x48_cachedIntensity(0.f),
x4c_24_intensityDirty(true), x4c_25_radiusDirty(true)
{}
void SetPosition(const zeus::CVector3f& pos)
{
x0_pos = pos;
}
void SetDirection(const zeus::CVector3f& dir)
{
xc_dir = dir;
}
void SetColor(const zeus::CColor& col)
{
x18_color = col;
x4c_24_intensityDirty = true;
x4c_25_radiusDirty = true;
}
void SetAttenuation(float constant, float linear, float quadratic)
{
x24_distC = constant;
x28_distL = linear;
x2c_distQ = quadratic;
x4c_24_intensityDirty = true;
x4c_25_radiusDirty = true;
}
void SetAngleAttenuation(float constant, float linear, float quadratic)
{
x30_angleC = constant;
x34_angleL = linear;
x38_angleQ = quadratic;
x4c_24_intensityDirty = true;
x4c_25_radiusDirty = true;
}
float GetRadius() const
{
if (x4c_25_radiusDirty)
{
((CLight*)this)->x44_cachedRadius = CalculateLightRadius();
((CLight*)this)->x4c_25_radiusDirty = false;
}
return x44_cachedRadius;
}
float GetIntensity() const;
2016-03-04 23:04:53 +00:00
static CLight BuildDirectional(const zeus::CVector3f& dir, const zeus::CColor& color);
static CLight BuildSpot(const zeus::CVector3f& pos, const zeus::CVector3f& dir,
const zeus::CColor& color, float angle);
2016-03-16 20:49:35 +00:00
static CLight BuildPoint(const zeus::CVector3f& pos, const zeus::CColor& color);
2016-03-04 23:04:53 +00:00
static CLight BuildCustom(const zeus::CVector3f& pos, const zeus::CVector3f& dir,
2016-03-16 20:49:35 +00:00
const zeus::CColor& color,
float distC, float distL, float distQ,
float angleC, float angleL, float angleQ);
static CLight BuildLocalAmbient(const zeus::CVector3f& pos, const zeus::CColor& color);
2015-08-21 00:06:39 +00:00
};
2016-03-04 23:04:53 +00:00
}
2016-02-13 09:02:47 +00:00
#endif // __PSHAG_CLIGHT_HPP__