2020-01-15 12:07:48 +00:00
|
|
|
#include "Runtime/Graphics/CSimpleShadow.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/Collision/CGameCollision.hpp"
|
2016-08-31 00:33:59 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2018-02-05 06:56:09 +00:00
|
|
|
|
|
|
|
CSimpleShadow::CSimpleShadow(float scale, float userAlpha, float maxObjHeight, float displacement)
|
2020-04-21 07:22:41 +00:00
|
|
|
: x30_scale(scale), x38_userAlpha(userAlpha), x40_maxObjHeight(maxObjHeight), x44_displacement(displacement) {}
|
2018-02-05 06:56:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CAABox CSimpleShadow::GetMaxShadowBox(const zeus::CAABox& aabb) const {
|
|
|
|
float extent = x34_radius * x30_scale;
|
|
|
|
zeus::CVector3f center = aabb.center();
|
|
|
|
zeus::CAABox expandedAABB = aabb;
|
|
|
|
expandedAABB.accumulateBounds({center.x() + extent, center.y() + extent, center.z() - GetMaxObjectHeight()});
|
|
|
|
expandedAABB.accumulateBounds({center.x() - extent, center.y() - extent, center.z() - GetMaxObjectHeight()});
|
|
|
|
return expandedAABB;
|
2018-02-05 06:56:09 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CAABox CSimpleShadow::GetBounds() const {
|
|
|
|
float extent = x34_radius * x30_scale;
|
|
|
|
return {{x0_xf.origin.x() - extent, x0_xf.origin.y() - extent, x0_xf.origin.z() - extent},
|
|
|
|
{x0_xf.origin.x() + extent, x0_xf.origin.y() + extent, x0_xf.origin.z() + extent}};
|
2018-02-05 06:56:09 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 01:44:46 +00:00
|
|
|
void CSimpleShadow::Render(const TLockedToken<CTexture>& tex) {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!x48_24_collision)
|
|
|
|
return;
|
2019-07-21 08:42:52 +00:00
|
|
|
SCOPED_GRAPHICS_DEBUG_GROUP("CSimpleShadow::Render", zeus::skGrey);
|
2018-02-05 06:56:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CGraphics::DisableAllLights();
|
|
|
|
CGraphics::SetModelMatrix(x0_xf);
|
2016-08-31 00:33:59 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!m_filter || m_filter->GetTex().GetObj() != tex.GetObj())
|
|
|
|
m_filter.emplace(EFilterType::InvDstMultiply, tex, CTexturedQuadFilter::ZTest::LEqual);
|
2018-02-05 06:56:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
float radius = x34_radius * x30_scale;
|
2020-04-19 06:47:25 +00:00
|
|
|
const std::array<CTexturedQuadFilter::Vert, 4> verts{{
|
|
|
|
{{-radius, 0.f, -radius}, {0.f, 0.f}},
|
|
|
|
{{radius, 0.f, -radius}, {0.f, 1.f}},
|
|
|
|
{{-radius, 0.f, radius}, {1.f, 0.f}},
|
|
|
|
{{radius, 0.f, radius}, {1.f, 1.f}},
|
|
|
|
}};
|
2019-02-24 07:15:54 +00:00
|
|
|
m_filter->drawVerts(zeus::skWhite, verts);
|
2017-03-04 04:31:08 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CSimpleShadow::Calculate(const zeus::CAABox& aabb, const zeus::CTransform& xf, const CStateManager& mgr) {
|
|
|
|
x48_24_collision = false;
|
|
|
|
float halfHeight = (aabb.max.z() - aabb.min.z()) * 0.5f;
|
|
|
|
zeus::CVector3f pos = xf.origin + zeus::CVector3f(0.f, 0.f, halfHeight);
|
2019-02-24 07:15:54 +00:00
|
|
|
CRayCastResult res = mgr.RayStaticIntersection(pos, zeus::skDown, x40_maxObjHeight,
|
2018-12-08 05:30:43 +00:00
|
|
|
CMaterialFilter::MakeExclude({EMaterialTypes::SeeThrough}));
|
|
|
|
float height = x40_maxObjHeight;
|
|
|
|
if (res.IsValid()) {
|
|
|
|
x48_24_collision = true;
|
|
|
|
height = res.GetT();
|
|
|
|
}
|
2018-02-05 06:56:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (height > 0.1f + halfHeight) {
|
|
|
|
TUniqueId cid = kInvalidUniqueId;
|
|
|
|
rstl::reserved_vector<TUniqueId, 1024> nearList;
|
|
|
|
CRayCastResult resD = CGameCollision::RayDynamicIntersection(
|
2019-02-24 07:15:54 +00:00
|
|
|
mgr, cid, pos, zeus::skDown, x40_maxObjHeight, CMaterialFilter::skPassEverything, nearList);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (resD.IsValid() && resD.GetT() < height) {
|
|
|
|
x48_24_collision = true;
|
|
|
|
height = resD.GetT();
|
|
|
|
res = resD;
|
2018-02-05 06:56:09 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-04 04:31:08 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x48_24_collision) {
|
|
|
|
x3c_heightAlpha = 1.f - height / x40_maxObjHeight;
|
2019-02-24 07:15:54 +00:00
|
|
|
x0_xf = zeus::lookAt(res.GetPlane().normal(), zeus::skZero3f);
|
2018-12-08 05:30:43 +00:00
|
|
|
x0_xf.origin = res.GetPlane().normal() * x44_displacement + res.GetPoint();
|
|
|
|
if (x48_25_alwaysCalculateRadius || !x48_26_radiusCalculated) {
|
|
|
|
float xExtent = aabb.max.x() - aabb.min.x();
|
|
|
|
float yExtent = aabb.max.y() - aabb.min.y();
|
|
|
|
x34_radius = std::sqrt(xExtent * xExtent + yExtent * yExtent) * 0.5f;
|
|
|
|
x48_26_radiusCalculated = true;
|
2018-02-05 06:56:09 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-08-31 00:33:59 +00:00
|
|
|
}
|
2018-02-05 06:56:09 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|