Remove (almost) all references to pRenderer (#651)

Remove all references to pRenderer, except from the DebugDraw and LyShine Gems that are still being updated.
This commit is contained in:
bosnichd
2021-05-10 10:05:15 -06:00
committed by GitHub
parent 4a2e6a77b5
commit 440c40e490
191 changed files with 118 additions and 23548 deletions
+1 -305
View File
@@ -894,314 +894,10 @@ void CBaseObject::DrawDefault(DisplayContext& dc, const QColor& labelColor)
}
//////////////////////////////////////////////////////////////////////////
void CBaseObject::DrawDimensions(DisplayContext& dc, AABB* pMergedBoundBox)
void CBaseObject::DrawDimensions(DisplayContext&, AABB*)
{
if (HasMeasurementAxis() && GetIEditor()->GetDisplaySettings()->IsDisplayDimensionFigures())
{
AABB localBoundBox;
GetLocalBounds(localBoundBox);
DrawDimensionsImpl(dc, localBoundBox, pMergedBoundBox);
}
}
//////////////////////////////////////////////////////////////////////////
void CBaseObject::DrawDimensionsImpl(DisplayContext& dc, const AABB& localBoundBox, AABB* pMergedBoundBox)
{
AABB boundBox;
Matrix34 rotatedTM;
bool bHave2Axis(false);
float xLength(0);
float yLength(0);
float zLength(0);
if (pMergedBoundBox)
{
rotatedTM = Matrix34::CreateIdentity();
boundBox = *pMergedBoundBox;
xLength = boundBox.max.x - boundBox.min.x;
zLength = boundBox.max.z - boundBox.min.z;
yLength = boundBox.max.y - boundBox.min.y;
}
else
{
rotatedTM = GetWorldRotTM();
Matrix34 scaledTranslatedTM = GetWorldScaleTM();
scaledTranslatedTM.SetTranslation(GetWorldPos());
boundBox.SetTransformedAABB(scaledTranslatedTM, localBoundBox);
IVariable* pVarXLength(NULL);
IVariable* pVarYLength(NULL);
IVariable* pVarZLength(NULL);
IVariable* pVarDimX(NULL);
IVariable* pVarDimY(NULL);
IVariable* pVarDimZ(NULL);
CVarBlock* pVarBlock(GetVarBlock());
if (pVarBlock)
{
pVarXLength = pVarBlock->FindVariable("Width");
pVarYLength = pVarBlock->FindVariable("Length");
pVarZLength = pVarBlock->FindVariable("Height");
pVarDimX = pVarBlock->FindVariable("DimX");
pVarDimY = pVarBlock->FindVariable("DimY");
pVarDimZ = pVarBlock->FindVariable("DimZ");
}
xLength = boundBox.max.x - boundBox.min.x;
zLength = boundBox.max.z - boundBox.min.z;
yLength = boundBox.max.y - boundBox.min.y;
if (pVarDimX && pVarDimY && pVarDimZ)
{
pVarDimX->Get(xLength);
pVarDimZ->Get(zLength);
pVarDimY->Get(yLength);
xLength *= m_scale.x;
zLength *= m_scale.z;
yLength *= m_scale.y;
}
else if (pVarXLength && pVarYLength && pVarZLength)
{
// A case of an area box.
pVarXLength->Get(xLength);
pVarZLength->Get(zLength);
pVarYLength->Get(yLength);
xLength *= m_scale.x;
zLength *= m_scale.z;
yLength *= m_scale.y;
}
else if (!pVarXLength && !pVarYLength && pVarZLength)
{
// A case of an area shape.
pVarZLength->Get(zLength);
zLength *= m_scale.z;
}
}
const float kMinimumLimitation(0.4f);
if (xLength < kMinimumLimitation && yLength < kMinimumLimitation && zLength < kMinimumLimitation)
{
return;
}
const float kEpsilon(0.001f);
bHave2Axis = fabs(zLength) < kEpsilon;
Vec3 basePoints[] = {
Vec3(boundBox.min.x, boundBox.min.y, boundBox.min.z),
Vec3(boundBox.min.x, boundBox.max.y, boundBox.min.z),
Vec3(boundBox.max.x, boundBox.max.y, boundBox.min.z),
Vec3(boundBox.max.x, boundBox.min.y, boundBox.min.z),
Vec3(boundBox.min.x, boundBox.min.y, boundBox.max.z),
Vec3(boundBox.min.x, boundBox.max.y, boundBox.max.z),
Vec3(boundBox.max.x, boundBox.max.y, boundBox.max.z),
Vec3(boundBox.max.x, boundBox.min.y, boundBox.max.z)
};
const int kElementSize(sizeof(basePoints) / sizeof(*basePoints));
Vec3 axisDirections[kElementSize] = { Vec3(1, 1, 1), Vec3(1, -1, 1), Vec3(-1, -1, 1), Vec3(-1, 1, 1), Vec3(1, 1, -1), Vec3(1, -1, -1), Vec3(-1, -1, -1), Vec3(-1, 1, -1) };
int nLoopCount = bHave2Axis ? (kElementSize / 2) : kElementSize;
if (bHave2Axis)
{
for (int i = 0; i < nLoopCount; ++i)
{
basePoints[i].z = 0.5f * (boundBox.min.z + boundBox.max.z);
}
}
// Find out the nearest base point of a bounding box from a camera position and use it as a pivot.
const CCamera& camera = gEnv->pRenderer->GetCamera();
Vec3 cameraPos(camera.GetPosition());
Vec3 pivot(rotatedTM.TransformVector(basePoints[0] - GetWorldPos()) + GetWorldPos());
float fNearestDist = (cameraPos - pivot).GetLength();
int nNearestAxisIndex(0);
bool bPrevVisible(camera.IsPointVisible(pivot));
for (int i = 1; i < nLoopCount; ++i)
{
Vec3 candidatePivot(rotatedTM.TransformVector(basePoints[i] - GetWorldPos()) + GetWorldPos());
float candidateLength = (candidatePivot - cameraPos).GetLength();
bool bVisible = camera.IsPointVisible(candidatePivot);
if (bVisible)
{
if (!bPrevVisible || candidateLength < fNearestDist)
{
fNearestDist = candidateLength;
pivot = candidatePivot;
nNearestAxisIndex = i;
}
bPrevVisible = bVisible;
}
}
float fScale = dc.view->GetScreenScaleFactor(pivot);
float fArrowScale = fScale * 0.04f;
Vec3 vX(xLength, 0, 0);
Vec3 vY(0, yLength, 0);
Vec3 vZ(0, 0, zLength);
vX = vX * axisDirections[nNearestAxisIndex].x;
vY = vY * axisDirections[nNearestAxisIndex].y;
vZ = vZ * axisDirections[nNearestAxisIndex].z;
vX = rotatedTM.TransformVector(vX);
vY = rotatedTM.TransformVector(vY);
vZ = rotatedTM.TransformVector(vZ);
const float kArrowPivotOffset = 0.1f;
pivot = pivot + (-(vX + vY + vZ)).GetNormalized() * kArrowPivotOffset;
Vec3 centerPt(boundBox.GetCenter());
// Display texts of width, height and depth
float fTextScale(1.3f);
dc.SetColor(QColor(200, 200, 200));
QString str;
const float kBrightness(0.35f);
const ColorF kXColor(1.0f, kBrightness, kBrightness, 0.9f);
const ColorF kYColor(kBrightness, 1.0f, kBrightness, 0.9f);
const ColorF kZColor(kBrightness, kBrightness, 1.0f, 0.9f);
const ColorF TextBoxColor(0, 0, 0, 0.75f);
ColorB backupcolor = dc.GetColor();
uint32 backupstate = dc.GetState();
int backupThickness = dc.GetLineWidth();
dc.SetState(backupstate | e_DepthTestOff);
Vec3 vNX = vX.GetNormalized();
Vec3 vNY = vY.GetNormalized();
Vec3 vNZ = vZ.GetNormalized();
const float kMinimumOffset(0.20f);
const float kMaximumOffset(30.0f);
float fMaximumOffset[3] = { kMaximumOffset, kMaximumOffset, kMaximumOffset };
if (xLength > kMaximumOffset * 0.5f)
{
fMaximumOffset[0] = xLength * 3.0f;
}
if (yLength > kMaximumOffset * 0.5f)
{
fMaximumOffset[1] = yLength * 3.0f;
}
if (zLength > kMaximumOffset * 0.5f)
{
fMaximumOffset[2] = zLength * 3.0f;
}
Vec3 textPos[3] = {pivot, pivot, pivot};
Vec3 textMinPos[3] = { pivot + vNX * kMinimumOffset, pivot + vNY * kMinimumOffset, pivot + vNZ * kMinimumOffset };
Vec3 textCenterPos[3] = { pivot + vX * 0.5f, pivot + vY * 0.5f, pivot + vZ * 0.5f };
Vec3 textMaxPos[3] = { pivot + vNX * fMaximumOffset[0], pivot + vNY * fMaximumOffset[1], pivot + vNZ * fMaximumOffset[2] };
const Vec3& cameraDir(camera.GetViewdir());
for (int i = 0; i < 3; ++i)
{
Vec3 d = (textMaxPos[i] - cameraPos).GetNormalized();
float fCameraDir = d.Dot(cameraDir);
if (fCameraDir < 0)
{
fCameraDir = 0;
}
textPos[i] = textMinPos[i] + (textCenterPos[i] - textPos[i]) * fCameraDir;
}
str = QString::number(xLength, 'f', 3);
DrawTextOn2DBox(dc, textPos[0], str.toUtf8().data(), fTextScale, kXColor, TextBoxColor);
if (!bHave2Axis)
{
str = QString::number(zLength, 'f', 3);
DrawTextOn2DBox(dc, textPos[2], str.toUtf8().data(), fTextScale, kZColor, TextBoxColor);
}
str = QString::number(yLength, 'f', 3);
DrawTextOn2DBox(dc, textPos[1], str.toUtf8().data(), fTextScale, kYColor, TextBoxColor);
dc.SetState(backupstate | e_DepthTestOn);
dc.SetLineWidth(4);
// Draw arrows of each axis.
dc.SetColor(kXColor);
dc.DrawArrow(pivot, pivot + vX, fArrowScale, true);
if (!bHave2Axis)
{
dc.SetColor(kZColor);
dc.DrawArrow(pivot, pivot + vZ, fArrowScale, true);
}
dc.SetColor(kYColor);
dc.DrawArrow(pivot, pivot + vY, fArrowScale, true);
dc.SetState(backupstate);
dc.SetColor(backupcolor);
dc.SetLineWidth(backupThickness);
}
//////////////////////////////////////////////////////////////////////////
void CBaseObject::DrawTextOn2DBox(DisplayContext& dc, const Vec3& pos, const char* text, float textScale, const ColorF& TextColor, const ColorF& TextBackColor)
{
Vec3 worldPos = dc.ToWorldSpacePosition(pos);
int vx, vy, vw, vh;
gEnv->pRenderer->GetViewport(&vx, &vy, &vw, &vh);
const CCamera& camera = gEnv->pRenderer->GetCamera();
Vec3 screenPos;
camera.Project(worldPos, screenPos, Vec2i(0, 0), Vec2i(0, 0));
//! Font size information doesn't seem to exist so the proper size is used
int textlen = strlen(text);
float fontsize = 7.5f;
float textwidth = fontsize * textlen;
float textheight = 16.0f;
screenPos.x = screenPos.x - textwidth * 0.5f;
Vec3 textregion[4] = {
Vec3(screenPos.x, screenPos.y, screenPos.z),
Vec3(screenPos.x + textwidth, screenPos.y, screenPos.z),
Vec3(screenPos.x + textwidth, screenPos.y + textheight, screenPos.z),
Vec3(screenPos.x, screenPos.y + textheight, screenPos.z)
};
Vec3 textworldreign[4];
Matrix34 dcInvTm = dc.GetMatrix().GetInverted();
Matrix44A mProj, mView;
mathMatrixPerspectiveFov(&mProj, camera.GetFov(), camera.GetProjRatio(), camera.GetNearPlane(), camera.GetFarPlane());
mathMatrixLookAt(&mView, camera.GetPosition(), camera.GetPosition() + camera.GetViewdir(), Vec3(0, 0, 1));
Matrix44A mInvViewProj = (mView * mProj).GetInverted();
for (int i = 0; i < 4; ++i)
{
Vec4 projectedpos = Vec4((textregion[i].x - vx) / vw * 2.0f - 1.0f,
-((textregion[i].y - vy) / vh) * 2.0f + 1.0f,
textregion[i].z,
1.0f);
Vec4 wp = projectedpos * mInvViewProj;
wp.x /= wp.w;
wp.y /= wp.w;
wp.z /= wp.w;
textworldreign[i] = dcInvTm.TransformPoint(Vec3(wp.x, wp.y, wp.z));
}
ColorB backupcolor = dc.GetColor();
uint32 backupstate = dc.GetState();
dc.SetColor(TextBackColor);
dc.SetDrawInFrontMode(true);
dc.DrawQuad(textworldreign[3], textworldreign[2], textworldreign[1], textworldreign[0]);
dc.SetColor(TextColor);
dc.DrawTextLabel(pos, textScale, text);
dc.SetDrawInFrontMode(false);
dc.SetColor(backupcolor);
dc.SetState(backupstate);
}
//////////////////////////////////////////////////////////////////////////
void CBaseObject::DrawSelectionHelper(DisplayContext& dc, const Vec3& pos, const QColor& labelColor, [[maybe_unused]] float alpha)
{