mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-07-03 03:36:10 +00:00
CRenderBucket: Tidy up code
This commit is contained in:
parent
b02b507675
commit
f88122b2ed
@ -18,52 +18,55 @@ void CRenderBucket::CSubBucket::Add(const SRenderablePtr& rkPtr)
|
|||||||
void CRenderBucket::CSubBucket::Sort(const CCamera* pkCamera, bool DebugVisualization)
|
void CRenderBucket::CSubBucket::Sort(const CCamera* pkCamera, bool DebugVisualization)
|
||||||
{
|
{
|
||||||
std::stable_sort(mRenderables.begin(), mRenderables.begin() + mSize,
|
std::stable_sort(mRenderables.begin(), mRenderables.begin() + mSize,
|
||||||
[&, pkCamera](const SRenderablePtr& rkLeft, const SRenderablePtr& rkRight) -> bool
|
[&, pkCamera](const auto& rkLeft, const auto& rkRight) {
|
||||||
|
const CVector3f CamPos = pkCamera->Position();
|
||||||
|
const CVector3f CamDir = pkCamera->Direction();
|
||||||
|
|
||||||
|
const CVector3f DistL = rkLeft.AABox.ClosestPointAlongVector(CamDir) - CamPos;
|
||||||
|
const CVector3f DistR = rkRight.AABox.ClosestPointAlongVector(CamDir) - CamPos;
|
||||||
|
const float DotL = DistL.Dot(CamDir);
|
||||||
|
const float DotR = DistR.Dot(CamDir);
|
||||||
|
return DotL > DotR;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!DebugVisualization)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (size_t iPtr = 0; iPtr < mSize; iPtr++)
|
||||||
{
|
{
|
||||||
CVector3f CamPos = pkCamera->Position();
|
const SRenderablePtr *pPtr = &mRenderables[iPtr];
|
||||||
CVector3f CamDir = pkCamera->Direction();
|
const CVector3f Point = pPtr->AABox.ClosestPointAlongVector(pkCamera->Direction());
|
||||||
|
CDrawUtil::DrawWireCube(pPtr->AABox, CColor::White());
|
||||||
|
|
||||||
CVector3f DistL = rkLeft.AABox.ClosestPointAlongVector(CamDir) - CamPos;
|
const CVector3f Dist = Point - pkCamera->Position();
|
||||||
CVector3f DistR = rkRight.AABox.ClosestPointAlongVector(CamDir) - CamPos;
|
float Dot = Dist.Dot(pkCamera->Direction());
|
||||||
float DotL = DistL.Dot(CamDir);
|
if (Dot < 0.f)
|
||||||
float DotR = DistR.Dot(CamDir);
|
Dot = -Dot;
|
||||||
return (DotL > DotR);
|
Dot = std::min(Dot, 50.f);
|
||||||
});
|
const float Intensity = 1.f - (Dot / 50.f);
|
||||||
|
const CColor CubeColor(Intensity, Intensity, Intensity, 1.f);
|
||||||
|
|
||||||
if (DebugVisualization)
|
CGraphics::sMVPBlock.ModelMatrix = CTransform4f::TranslationMatrix(Point);
|
||||||
{
|
CGraphics::UpdateMVPBlock();
|
||||||
for (uint32 iPtr = 0; iPtr < mSize; iPtr++)
|
CDrawUtil::DrawCube(CubeColor);
|
||||||
{
|
|
||||||
SRenderablePtr *pPtr = &mRenderables[iPtr];
|
|
||||||
CVector3f Point = pPtr->AABox.ClosestPointAlongVector(pkCamera->Direction());
|
|
||||||
CDrawUtil::DrawWireCube(pPtr->AABox, CColor::White());
|
|
||||||
|
|
||||||
CVector3f Dist = Point - pkCamera->Position();
|
|
||||||
float Dot = Dist.Dot(pkCamera->Direction());
|
|
||||||
if (Dot < 0.f) Dot = -Dot;
|
|
||||||
if (Dot > 50.f) Dot = 50.f;
|
|
||||||
float Intensity = 1.f - (Dot / 50.f);
|
|
||||||
CColor CubeColor(Intensity, Intensity, Intensity, 1.f);
|
|
||||||
|
|
||||||
CGraphics::sMVPBlock.ModelMatrix = CTransform4f::TranslationMatrix(Point);
|
|
||||||
CGraphics::UpdateMVPBlock();
|
|
||||||
CDrawUtil::DrawCube(CubeColor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CRenderBucket::CSubBucket::Clear()
|
void CRenderBucket::CSubBucket::Clear()
|
||||||
{
|
{
|
||||||
mEstSize = mSize;
|
mEstSize = mSize;
|
||||||
if (mRenderables.size() > mSize) mRenderables.resize(mSize);
|
|
||||||
|
if (mRenderables.size() > mSize)
|
||||||
|
mRenderables.resize(mSize);
|
||||||
|
|
||||||
mSize = 0;
|
mSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CRenderBucket::CSubBucket::Draw(const SViewInfo& rkViewInfo)
|
void CRenderBucket::CSubBucket::Draw(const SViewInfo& rkViewInfo)
|
||||||
{
|
{
|
||||||
FRenderOptions Options = rkViewInfo.pRenderer->RenderOptions();
|
const FRenderOptions Options = rkViewInfo.pRenderer->RenderOptions();
|
||||||
|
|
||||||
for (uint32 iPtr = 0; iPtr < mSize; iPtr++)
|
for (size_t iPtr = 0; iPtr < mSize; iPtr++)
|
||||||
{
|
{
|
||||||
const SRenderablePtr& rkPtr = mRenderables[iPtr];
|
const SRenderablePtr& rkPtr = mRenderables[iPtr];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user