metaforce/Runtime/Graphics/CLight.hpp

147 lines
4.1 KiB
C++
Raw Normal View History

2016-04-13 06:07:23 +00:00
#ifndef __URDE_CLIGHT_HPP__
#define __URDE_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;
2016-04-04 02:32:57 +00:00
friend class CBooModel;
2016-07-28 04:55:06 +00:00
friend class CBooRenderer;
friend class CGameLight;
2016-03-16 20:49:35 +00:00
zeus::CVector3f x0_pos;
zeus::CVector3f xc_dir = zeus::CVector3f::skDown;
zeus::CColor x18_color = zeus::CColor::skClear;
ELightType x1c_type = ELightType::Custom;
float x20_spotCutoff = 0.f;
float x24_distC = 1.f;
float x28_distL = 0.f;
float x2c_distQ = 0.f;
float x30_angleC = 1.f;
float x34_angleL = 0.f;
float x38_angleQ = 0.f;
u32 x3c_priority = 0;
2017-06-03 06:03:07 +00:00
u32 x40_lightId = 0; // Serves as unique key
float x44_cachedRadius = 0.f;
float x48_cachedIntensity = 0.f;
2016-03-16 20:49:35 +00:00
bool x4c_24_intensityDirty : 1;
bool x4c_25_radiusDirty : 1;
float CalculateLightRadius() const;
2016-03-04 23:04:53 +00:00
public:
CLight()
{
x4c_24_intensityDirty = true;
x4c_25_radiusDirty = true;
}
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,
2016-04-04 02:32:57 +00:00
float angleC, float angleL, float angleQ);
2016-03-16 20:49:35 +00:00
CLight(ELightType type,
const zeus::CVector3f& pos,
const zeus::CVector3f& dir,
const zeus::CColor& color,
2016-04-04 02:32:57 +00:00
float cutoff);
2016-03-16 20:49:35 +00:00
void SetPosition(const zeus::CVector3f& pos)
{
x0_pos = pos;
}
const zeus::CVector3f& GetPosition() const { return x0_pos; }
2016-03-16 20:49:35 +00:00
void SetDirection(const zeus::CVector3f& dir)
{
xc_dir = dir;
}
const zeus::CVector3f& GetDirection() const { return xc_dir; }
2016-03-16 20:49:35 +00:00
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;
}
2017-04-13 19:28:31 +00:00
float GetAttenuationConstant() const { return x24_distC; }
float GetAttenuationLinear() const { return x28_distL; }
float GetAttenuationQuadratic() const { return x2c_distQ; }
2016-03-16 20:49:35 +00:00
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;
}
2017-04-13 19:28:31 +00:00
float GetAngleAttenuationConstant() const { return x30_angleC; }
float GetAngleAttenuationLinear() const { return x34_angleL; }
float GetAngleAttenuationQuadratic() const { return x38_angleQ; }
2016-03-16 20:49:35 +00:00
float GetRadius() const
{
if (x4c_25_radiusDirty)
{
2016-08-29 04:22:54 +00:00
const_cast<CLight*>(this)->x44_cachedRadius = CalculateLightRadius();
const_cast<CLight*>(this)->x4c_25_radiusDirty = false;
2016-03-16 20:49:35 +00:00
}
return x44_cachedRadius;
}
ELightType GetType() const { return x1c_type; }
2016-03-16 20:49:35 +00:00
float GetIntensity() const;
2016-08-21 00:04:50 +00:00
const zeus::CColor& GetColor() const { return x18_color; }
zeus::CColor GetNormalIndependentLightingAtPoint(const zeus::CVector3f& point) const;
2016-03-16 20:49:35 +00:00
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-04-13 06:07:23 +00:00
#endif // __URDE_CLIGHT_HPP__