CLightNode: Use structured bindings where applicable
This commit is contained in:
parent
15f151e798
commit
9c8b65c629
|
@ -34,7 +34,7 @@ void CLightNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo
|
||||||
|
|
||||||
if (IsSelected() && mpLight->Type() == ELightType::Custom)
|
if (IsSelected() && mpLight->Type() == ELightType::Custom)
|
||||||
{
|
{
|
||||||
CAABox RadiusBox = (CAABox::One() * 2.f * mpLight->GetRadius()) + mPosition;
|
const CAABox RadiusBox = (CAABox::One() * 2.f * mpLight->GetRadius()) + mPosition;
|
||||||
|
|
||||||
if (rkViewInfo.ViewFrustum.BoxInFrustum(RadiusBox))
|
if (rkViewInfo.ViewFrustum.BoxInFrustum(RadiusBox))
|
||||||
pRenderer->AddMesh(this, -1, AABox(), false, ERenderCommand::DrawSelection);
|
pRenderer->AddMesh(this, -1, AABox(), false, ERenderCommand::DrawSelection);
|
||||||
|
@ -53,14 +53,15 @@ void CLightNode::DrawSelection()
|
||||||
|
|
||||||
void CLightNode::RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& /*ViewInfo*/)
|
void CLightNode::RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& /*ViewInfo*/)
|
||||||
{
|
{
|
||||||
CVector2f BillScale = BillboardScale();
|
const CVector2f BillScale = BillboardScale();
|
||||||
float ScaleXY = (BillScale.X > BillScale.Y ? BillScale.X : BillScale.Y);
|
const float ScaleXY = (BillScale.X > BillScale.Y ? BillScale.X : BillScale.Y);
|
||||||
|
|
||||||
CAABox BillBox = CAABox(mPosition + CVector3f(-ScaleXY, -ScaleXY, -BillScale.Y),
|
const CAABox BillBox = CAABox(mPosition + CVector3f(-ScaleXY, -ScaleXY, -BillScale.Y),
|
||||||
mPosition + CVector3f( ScaleXY, ScaleXY, BillScale.Y));
|
mPosition + CVector3f(ScaleXY, ScaleXY, BillScale.Y));
|
||||||
|
|
||||||
std::pair<bool,float> BoxResult = BillBox.IntersectsRay(rTester.Ray());
|
const auto [intersects, distance] = BillBox.IntersectsRay(rTester.Ray());
|
||||||
if (BoxResult.first) rTester.AddNode(this, 0, BoxResult.second);
|
if (intersects)
|
||||||
|
rTester.AddNode(this, 0, distance);
|
||||||
}
|
}
|
||||||
|
|
||||||
SRayIntersection CLightNode::RayNodeIntersectTest(const CRay& rkRay, uint32 AssetID, const SViewInfo& rkViewInfo)
|
SRayIntersection CLightNode::RayNodeIntersectTest(const CRay& rkRay, uint32 AssetID, const SViewInfo& rkViewInfo)
|
||||||
|
@ -79,22 +80,22 @@ SRayIntersection CLightNode::RayNodeIntersectTest(const CRay& rkRay, uint32 Asse
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 1: check whether the ray intersects with the plane the billboard is on
|
// Step 1: check whether the ray intersects with the plane the billboard is on
|
||||||
CPlane BillboardPlane(-rkViewInfo.pCamera->Direction(), mPosition);
|
const CPlane BillboardPlane(-rkViewInfo.pCamera->Direction(), mPosition);
|
||||||
std::pair<bool,float> PlaneTest = Math::RayPlaneIntersection(rkRay, BillboardPlane);
|
const auto [intersects, distance] = Math::RayPlaneIntersection(rkRay, BillboardPlane);
|
||||||
|
|
||||||
if (PlaneTest.first)
|
if (intersects)
|
||||||
{
|
{
|
||||||
// Step 2: transform the hit point into the plane's local space
|
// Step 2: transform the hit point into the plane's local space
|
||||||
CVector3f PlaneHitPoint = rkRay.PointOnRay(PlaneTest.second);
|
const CVector3f PlaneHitPoint = rkRay.PointOnRay(distance);
|
||||||
CVector3f RelHitPoint = PlaneHitPoint - mPosition;
|
const CVector3f RelHitPoint = PlaneHitPoint - mPosition;
|
||||||
|
|
||||||
CVector3f PlaneForward = -rkViewInfo.pCamera->Direction();
|
const CVector3f PlaneForward = -rkViewInfo.pCamera->Direction();
|
||||||
CVector3f PlaneRight = -rkViewInfo.pCamera->RightVector();
|
const CVector3f PlaneRight = -rkViewInfo.pCamera->RightVector();
|
||||||
CVector3f PlaneUp = rkViewInfo.pCamera->UpVector();
|
const CVector3f PlaneUp = rkViewInfo.pCamera->UpVector();
|
||||||
CQuaternion PlaneRot = CQuaternion::FromAxes(PlaneRight, PlaneForward, PlaneUp);
|
const CQuaternion PlaneRot = CQuaternion::FromAxes(PlaneRight, PlaneForward, PlaneUp);
|
||||||
|
|
||||||
CVector3f RotatedHitPoint = PlaneRot.Inverse() * RelHitPoint;
|
const CVector3f RotatedHitPoint = PlaneRot.Inverse() * RelHitPoint;
|
||||||
CVector2f LocalHitPoint = RotatedHitPoint.XZ() / BillboardScale();
|
const CVector2f LocalHitPoint = RotatedHitPoint.XZ() / BillboardScale();
|
||||||
|
|
||||||
// Step 3: check whether the transformed hit point is in the -1 to 1 range
|
// Step 3: check whether the transformed hit point is in the -1 to 1 range
|
||||||
if ((LocalHitPoint.X >= -1.f) && (LocalHitPoint.X <= 1.f) && (LocalHitPoint.Y >= -1.f) && (LocalHitPoint.Y <= 1.f))
|
if ((LocalHitPoint.X >= -1.f) && (LocalHitPoint.X <= 1.f) && (LocalHitPoint.Y >= -1.f) && (LocalHitPoint.Y <= 1.f))
|
||||||
|
@ -102,25 +103,28 @@ SRayIntersection CLightNode::RayNodeIntersectTest(const CRay& rkRay, uint32 Asse
|
||||||
// Step 4: look up the hit texel and check whether it's transparent or opaque
|
// Step 4: look up the hit texel and check whether it's transparent or opaque
|
||||||
CVector2f TexCoord = (LocalHitPoint + CVector2f(1.f)) * 0.5f;
|
CVector2f TexCoord = (LocalHitPoint + CVector2f(1.f)) * 0.5f;
|
||||||
TexCoord.X = -TexCoord.X + 1.f;
|
TexCoord.X = -TexCoord.X + 1.f;
|
||||||
float TexelAlpha = pBillboard->ReadTexelAlpha(TexCoord);
|
const float TexelAlpha = pBillboard->ReadTexelAlpha(TexCoord);
|
||||||
|
|
||||||
if (TexelAlpha < 0.25f)
|
if (TexelAlpha < 0.25f)
|
||||||
|
{
|
||||||
Out.Hit = false;
|
Out.Hit = false;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// It's opaque... we have a hit!
|
// It's opaque... we have a hit!
|
||||||
Out.Hit = true;
|
Out.Hit = true;
|
||||||
Out.Distance = PlaneTest.second;
|
Out.Distance = distance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
|
{
|
||||||
Out.Hit = false;
|
Out.Hit = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
|
{
|
||||||
Out.Hit = false;
|
Out.Hit = false;
|
||||||
|
}
|
||||||
|
|
||||||
return Out;
|
return Out;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue