metaforce/Runtime/GuiSys/CGuiLight.cpp

109 lines
3.0 KiB
C++
Raw Normal View History

#include "CGuiLight.hpp"
2016-03-16 20:49:35 +00:00
#include "CGuiFrame.hpp"
namespace urde
{
CGuiLight::CGuiLight(const CGuiWidgetParms& parms, const CLight& light)
2016-03-16 20:49:35 +00:00
: CGuiWidget(parms),
2017-04-08 20:40:36 +00:00
xb8_type(light.x1c_type),
xbc_spotCutoff(light.x20_spotCutoff),
xc0_distC(light.x24_distC),
xc4_distL(light.x28_distL),
xc8_distQ(light.x2c_distQ),
xcc_angleC(light.x30_angleC),
xd0_angleL(light.x34_angleL),
xd4_angleQ(light.x38_angleQ),
xd8_loadedIdx(light.x40_loadedIdx)
2016-03-16 20:49:35 +00:00
{}
CGuiLight::~CGuiLight()
{
xb0_frame->RemoveLight(this);
}
2016-03-15 04:55:57 +00:00
CLight CGuiLight::BuildLight() const
{
2016-03-16 20:49:35 +00:00
CLight ret = CLight::BuildLocalAmbient(zeus::CVector3f::skZero, zeus::CColor::skBlack);
2017-04-08 20:40:36 +00:00
switch (xb8_type)
2016-03-16 20:49:35 +00:00
{
case ELightType::Spot:
2017-04-08 20:40:36 +00:00
ret = CLight::BuildSpot(GetWorldPosition(), x34_worldXF.basis[1], xa4_color, xbc_spotCutoff);
2016-03-16 20:49:35 +00:00
break;
case ELightType::Point:
ret = CLight::BuildPoint(GetWorldPosition(), xa4_color);
2016-03-16 20:49:35 +00:00
break;
case ELightType::Directional:
ret = CLight::BuildDirectional(x34_worldXF.basis[1], xa4_color);
2016-03-16 20:49:35 +00:00
break;
default: break;
}
2017-04-08 20:40:36 +00:00
ret.SetAttenuation(xc0_distC, xc4_distL, xc8_distQ);
ret.SetAngleAttenuation(xcc_angleC, xd0_angleL, xd4_angleQ);
2016-03-16 20:49:35 +00:00
return ret;
}
void CGuiLight::SetIsVisible(bool vis)
{
if (vis)
2017-03-20 05:09:53 +00:00
xb0_frame->AddLight(this);
2016-03-16 20:49:35 +00:00
else
xb0_frame->RemoveLight(this);
2016-03-16 20:49:35 +00:00
CGuiWidget::SetIsVisible(vis);
2016-03-15 04:55:57 +00:00
}
std::shared_ptr<CGuiWidget> CGuiLight::Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp)
{
CGuiWidgetParms parms = ReadWidgetHeader(frame, in);
2016-03-16 20:49:35 +00:00
ELightType tp = ELightType(in.readUint32Big());
float distC = in.readFloatBig();
float distL = in.readFloatBig();
float distQ = in.readFloatBig();
float angC = in.readFloatBig();
float angL = in.readFloatBig();
float angQ = in.readFloatBig();
u32 loadedIdx = in.readUint32Big();
std::shared_ptr<CGuiLight> ret = {};
2016-03-16 20:49:35 +00:00
switch (tp)
{
case ELightType::Spot:
{
float cutoff = in.readFloatBig();
CLight lt = CLight::BuildSpot(zeus::CVector3f::skZero, zeus::CVector3f::skZero,
parms.x10_color, cutoff);
lt.SetAttenuation(distC, distL, distQ);
lt.SetAngleAttenuation(angC, angL, angQ);
lt.x40_loadedIdx = loadedIdx;
ret = std::make_shared<CGuiLight>(parms, lt);
2016-03-16 20:49:35 +00:00
break;
}
case ELightType::Point:
{
CLight lt = CLight::BuildPoint(zeus::CVector3f::skZero, parms.x10_color);
lt.SetAttenuation(distC, distL, distQ);
lt.x40_loadedIdx = loadedIdx;
ret = std::make_shared<CGuiLight>(parms, lt);
2016-03-16 20:49:35 +00:00
break;
}
case ELightType::Directional:
{
CLight lt = CLight::BuildDirectional(zeus::CVector3f::skZero, parms.x10_color);
lt.x40_loadedIdx = loadedIdx;
ret = std::make_shared<CGuiLight>(parms, lt);
2016-03-16 20:49:35 +00:00
break;
}
default: break;
}
2016-03-16 20:49:35 +00:00
ret->ParseBaseInfo(frame, in, parms);
2017-03-20 05:09:53 +00:00
frame->RegisterLight(ret->shared_from_this());
frame->AddLight(ret.get());
2016-03-16 20:49:35 +00:00
return ret;
}
}