Skip to content

Commit

Permalink
properly consider frame index for multi-section vxl shadow
Browse files Browse the repository at this point in the history
  • Loading branch information
chaserli committed Feb 24, 2024
1 parent cc907d5 commit 3134755
Showing 1 changed file with 44 additions and 8 deletions.
52 changes: 44 additions & 8 deletions src/Ext/TechnoType/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,15 @@ DEFINE_HOOK(0x4DB157, FootClass_DrawVoxelShadow_TurretShadow, 0x8)

if (pTypeExt->TurretShadow.Get(RulesExt::Global()->DrawTurretShadow) && tur->VXL && tur->HVA)
{
auto mtx = pThis->Locomotor->Shadow_Matrix(0);
auto mtx = Matrix3D::GetIdentity();
pTypeExt->ApplyTurretOffset(&mtx, *reinterpret_cast<double*>(0xB1D008));
mtx.TranslateZ(-tur->HVA->Matrixes[0].GetZVal());
mtx.RotateZ(static_cast<float>(pThis->SecondaryFacing.Current().GetRadian<32>() - pThis->PrimaryFacing.Current().GetRadian<32>()));
Matrix3D::MatrixMultiply(&mtx, &Matrix3D::VoxelDefaultMatrix, &mtx);
mtx = *pMatrix * mtx;

pThis->DrawVoxelShadow(tur, 0, angle, 0, a4, &a3, &mtx, a9, pSurface, pos);
auto bar = &pType->BarrelVoxel;

auto bar = (pType->TurretCount == 0 || pType->IsGattling) ?
&pType->BarrelVoxel : &pType->ChargerBarrels[pThis->CurrentTurretNumber];

if (bar->VXL && bar->HVA)
pThis->DrawVoxelShadow(bar, 0, angle, 0, a4, &a3, &mtx, a9, pSurface, pos);
Expand All @@ -376,13 +377,48 @@ DEFINE_HOOK(0x4DB157, FootClass_DrawVoxelShadow_TurretShadow, 0x8)
{
for (auto index : pTypeExt->ShadowIndices)
{
auto hva = pVXL->HVA;
Matrix3D idxmtx = *pMatrix;
idxmtx.TranslateZ(-hva->Matrixes[index].GetZVal());
Matrix3D::MatrixMultiply(&idxmtx, &Matrix3D::VoxelDefaultMatrix, &idxmtx);
pThis->DrawVoxelShadow(pVXL, index, angle, a5, a4, &a3, pMatrix, a9, pSurface, pos);
}
}

return 0x4DB195;
}

DEFINE_HOOK(0x7072A1, sub707280_TryFixingTheMatrix, 0x7)
{
GET(FootClass*, pThis, EBX);
GET(VoxelStruct*, pVXL, EBP);
GET_STACK(Matrix3D*, pMat, STACK_OFFSET(0xE8, 0xC));
GET_STACK(int, shadow_index, STACK_OFFSET(0xE8, 0x18));

REF_STACK(Matrix3D, matRet, STACK_OFFSET(0xE8, -0x60));

auto hva = pVXL->HVA;
// cursed
int index = shadow_index + hva->LayerCount * (pThis->WalkedFramesSoFar % hva->FrameCount);
Matrix3D hvamat = hva->Matrixes[index];
// TODO : what is this Z offset supposed to be exactly? In order to properly shift the sections to the same level
hvamat.TranslateZ(
-hvamat.GetZVal()
- pVXL->VXL->TailerData->MinBounds.Z
);

matRet = *pMat * hvamat;

// Recover vanilla instructions
auto pType = pThis->GetTechnoType();
if (pType->UseBuffer)
*reinterpret_cast<DWORD*>(0xB43180) = 1;

REF_STACK(Matrix3D, b, STACK_OFFSET(0xE8, -0x90));
b.MakeIdentity();

// TODO: properly scale this
if (pType->ConsideredAircraft)
b.Scale(
// 1.f - 0.5f * std::clamp(pThis->GetHeight(), 0, 728) / 728.f
0.5f
);

return 0x707331;
}

0 comments on commit 3134755

Please sign in to comment.