Skip to content

Commit a808475

Browse files
authored
fix(view): Prevent the camera from clipping under terrain (TheSuperHackers#2652)
1 parent 9e8a445 commit a808475

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
// SYSTEM INCLUDES ////////////////////////////////////////////////////////////////////////////////
3838

3939
// USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
40+
#include "Common/MapObject.h"
4041
#include "Common/STLTypedefs.h"
4142
#include "GameClient/ParabolicEase.h"
4243
#include "GameClient/View.h"
@@ -48,7 +49,7 @@ class Drawable;
4849
///////////////////////////////////////////////////////////////////////////////////////////////////
4950
enum {MAX_WAYPOINTS=25};
5051

51-
constexpr const Real TERRAIN_SAMPLE_SIZE = 40.0f;
52+
constexpr const Real TERRAIN_SAMPLE_SIZE = MAP_XY_FACTOR * 4;
5253

5354
// ------------------------------------------------------------------------------------------------
5455
// ------------------------------------------------------------------------------------------------

Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,24 @@ void W3DView::updateCameraTransform()
737737
Vector3 targetPos;
738738
buildCameraPosition(sourcePos, targetPos);
739739

740+
#if PRESERVE_RETAIL_SCRIPTED_CAMERA
741+
const Bool clipCameraAboveTerrain = m_isUserControlled;
742+
#else
743+
const Bool clipCameraAboveTerrain = true;
744+
#endif
745+
if (clipCameraAboveTerrain)
746+
{
747+
// TheSuperHackers @fix Moves the camera above the terrain.
748+
// Uses averaged terrain height sampling to reduce bumpy movements.
749+
const Real minAcceptableCameraHeight = getHeightAroundPos(sourcePos.X, sourcePos.Y, MAP_XY_FACTOR) + NearZ;
750+
if (sourcePos.Z < minAcceptableCameraHeight)
751+
{
752+
const Real repositionZ = minAcceptableCameraHeight - sourcePos.Z;
753+
sourcePos.Z += repositionZ;
754+
targetPos.Z += repositionZ;
755+
}
756+
}
757+
740758
Matrix3D cameraTransform;
741759
buildCameraTransform(&cameraTransform, sourcePos, targetPos);
742760

0 commit comments

Comments
 (0)