Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(w3ddevice): tank barrels drawn at their modelled angle off the line

Olcay Seygan259ec6d78c36
diff --git a/GeneralsMD/Code/Data/INI/BalanceReforged.ini b/GeneralsMD/Code/Data/INI/BalanceReforged.ini
index eec1f87e1..1a8e6e769 100644
--- a/GeneralsMD/Code/Data/INI/BalanceReforged.ini
+++ b/GeneralsMD/Code/Data/INI/BalanceReforged.ini
@@ -1368,7 +1368,10 @@ End
; drawn barrel pitches on TurretPitch: the Scorpion has an elevation bone (TurretEl, TurretEl01 on
; the big turret); the Crusader, Paladin and Battlemaster pitch the barrel bone that also recoils.
; StabilizedTurretPitch holds the drawn barrel on that line while the drawn hull tilts on the ground
-; and rocks with each shot, which the logic's hull never does.
+; and rocks with each shot, which the logic's hull never does. BarrelArtPitch is the angle the barrel
+; is modelled at against level, read off the mesh: AVLeopard's rises 4.4 degrees, AVPaladin's 3.4
+; (bone 5 up, mesh 1.6 down in it); the Battlemaster's, the Scorpion's and the laser Crusader's lie
+; within half a degree of level.
;
; The Overlord, the Emperor and the Marauder keep a level gun. Each has a turret with two barrels on
; two bones (the Marauder's after its second upgrade), and a turret pitches one bone.
@@ -1377,6 +1380,7 @@ Object AmericaTankCrusader
ReplaceModule ModuleTag_01
Draw = W3DTankDraw ModuleTag_01_Reforged
StabilizedTurretPitch = Yes
+ BarrelArtPitch = 4.4
DefaultConditionState
Model = AVLeopard
Turret = Turret
@@ -1418,6 +1422,7 @@ Object SupW_AmericaTankCrusader
ReplaceModule ModuleTag_01
Draw = W3DTankDraw ModuleTag_01_Reforged
StabilizedTurretPitch = Yes
+ BarrelArtPitch = 4.4
DefaultConditionState
Model = AVLeopard
Turret = Turret
@@ -1500,6 +1505,7 @@ Object AmericaTankPaladin
ReplaceModule ModuleTag_01
Draw = W3DTankDraw ModuleTag_01_Reforged
StabilizedTurretPitch = Yes
+ BarrelArtPitch = 3.4
ExtraPublicBone = Laser
ConditionState = NONE
Model = AVPaladin
@@ -1554,6 +1560,7 @@ Object SupW_AmericaTankPaladin
ReplaceModule ModuleTag_01
Draw = W3DTankDraw ModuleTag_01_Reforged
StabilizedTurretPitch = Yes
+ BarrelArtPitch = 3.4
ExtraPublicBone = Laser
ConditionState = NONE
Model = AVPaladin
@@ -1608,6 +1615,7 @@ Object Lazr_AmericaTankPaladin
ReplaceModule ModuleTag_01
Draw = W3DTankDraw ModuleTag_01_Reforged
StabilizedTurretPitch = Yes
+ BarrelArtPitch = 3.4
ExtraPublicBone = Laser
ConditionState = NONE
Model = AVPaladin
@@ -1662,6 +1670,7 @@ Object Boss_TankPaladin
ReplaceModule ModuleTag_01
Draw = W3DTankDraw ModuleTag_01_Reforged
StabilizedTurretPitch = Yes
+ BarrelArtPitch = 3.4
ExtraPublicBone = Laser
ConditionState = NONE
Model = AVPaladin
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h
index 7d190dc99..4d133d0f5 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h
@@ -309,6 +309,7 @@ public:
Bool m_okToChangeModelColor;
Bool m_animationsRequirePower;///< Should UnderPowered disable type pause animations in this draw module?
Bool m_stabilizedTurretPitch; ///< draw a pitch bone at the logic's pitch against level ground, whatever the drawn hull's tilt
+ Real m_barrelArtPitch; ///< with that: how far the barrel's mesh is modelled above level at rest, taken off the drawn pitch
#ifdef CACHE_ATTACH_BONE
mutable Bool m_attachToDrawableBoneOffsetValid;
#endif
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp
index 738f222b9..7f48d11ec 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp
@@ -1061,6 +1061,7 @@ W3DModelDrawModuleData::W3DModelDrawModuleData() :
m_particlesAttachedToAnimatedBones(false),
m_animationsRequirePower(true),
m_stabilizedTurretPitch(false),
+ m_barrelArtPitch(0.0f),
#ifdef CACHE_ATTACH_BONE
m_attachToDrawableBoneOffsetValid(false),
#endif
@@ -1257,6 +1258,7 @@ void W3DModelDrawModuleData::buildFieldParse(MultiIniFieldParse& p)
{ "OkToChangeModelColor", INI::parseBool, NULL, offsetof(W3DModelDrawModuleData, m_okToChangeModelColor) },
{ "AnimationsRequirePower", INI::parseBool, NULL, offsetof(W3DModelDrawModuleData, m_animationsRequirePower) },
{ "StabilizedTurretPitch", INI::parseBool, NULL, offsetof(W3DModelDrawModuleData, m_stabilizedTurretPitch) },
+ { "BarrelArtPitch", INI::parseAngleReal, NULL, offsetof(W3DModelDrawModuleData, m_barrelArtPitch) },
{ "ParticlesAttachedToAnimatedBones", INI::parseBool, NULL, offsetof(W3DModelDrawModuleData, m_particlesAttachedToAnimatedBones) },
{ "MinLODRequired", INI::parseStaticGameLODLevel, NULL, offsetof(W3DModelDrawModuleData, m_minLODRequired) },
{ "ProjectileBoneFeedbackEnabledSlots", INI::parseBitString32, TheWeaponSlotTypeNames, offsetof(W3DModelDrawModuleData, m_projectileBoneFeedbackEnabledSlots) },
@@ -2941,23 +2943,18 @@ void W3DModelDraw::handleClientTurretPositioning()
if (m_curState)
turretPitch += tur.m_turretArtPitch;
// The logic aims from a hull that never tilts; the drawn one lies on the ground and rocks when
- // it fires. A stabilized gun takes that tilt along its own heading off, and the pitch the art
- // gave the bone (a Paladin's barrel is modelled 5 degrees up), so the drawn barrel stands at
- // the logic's pitch against level ground, down the line its shell flies.
- if (getW3DModelDrawModuleData()->m_stabilizedTurretPitch && m_renderObject && obj)
+ // it fires. A stabilized gun takes that tilt along its own heading off, and the angle the barrel
+ // is modelled at (BarrelArtPitch: a Crusader's mesh rises 4.4 degrees from its bone), so the
+ // drawn barrel stands at the logic's pitch against level ground, down the line its shell flies.
+ const W3DModelDrawModuleData* md = getW3DModelDrawModuleData();
+ if (md->m_stabilizedTurretPitch && m_renderObject && obj)
{
Vector3 heading(cosf(turretAngle), sinf(turretAngle), 0.0f);
Vector3 drawn = m_renderObject->Get_Transform().Rotate_Vector(heading);
Vector3 logic = obj->getTransformMatrix()->Rotate_Vector(heading);
turretPitch -= atan2f(drawn.Z, sqrtf(drawn.X * drawn.X + drawn.Y * drawn.Y))
- atan2f(logic.Z, sqrtf(logic.X * logic.X + logic.Y * logic.Y));
- Int restBone;
- const Matrix3D* rest = m_curState->findPristineBone(tur.m_turretPitchNameKey, &restBone);
- if (rest)
- {
- Vector3 restX = rest->Get_X_Vector();
- turretPitch -= atan2f(restX.Z, sqrtf(restX.X * restX.X + restX.Y * restX.Y));
- }
+ turretPitch -= md->m_barrelArtPitch;
}
m_drawnTurretPitch[tslot] = turretPitch;
Matrix3D turretPitchXfrm(1);