Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class W3DView : public View, public SubsystemInterface
Bool movePivotToGround();
void updateCameraAreaConstraints();
void calcCameraAreaConstraints(); ///< Recalculates the camera area constraints
Real calcCameraAreaOffset(Real maxEdgeZ, Bool isLookingDown);
Real calcCameraAreaOffset(Real maxEdgeZ);
void clipCameraIntoAreaConstraints();
Bool isWithinCameraAreaConstraints() const;
Bool isWithinCameraHeightConstraints() const;
Expand Down
20 changes: 14 additions & 6 deletions Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,9 @@ void W3DView::calcCameraAreaConstraints()
Matrix3D prevCameraTransform = m_3DCamera->Get_Transform();
m_3DCamera->Set_Transform(cameraTransform);

const Vector3 cameraForward = -cameraTransform.Get_Z_Vector();
const Bool isLookingDown = cameraForward.Z <= 0.0f;
Real offset = calcCameraAreaOffset(m_groundLevel, isLookingDown);
Real offset = calcCameraAreaOffset(m_groundLevel);
offset = std::min(offset, (mapRegion.hi.x - mapRegion.lo.x) / 2);
offset = std::min(offset, (mapRegion.hi.y - mapRegion.lo.y) / 2);

// Revert the 3D camera transform.
m_3DCamera->Set_Transform(prevCameraTransform);
Expand All @@ -556,21 +556,26 @@ void W3DView::calcCameraAreaConstraints()
}

//-------------------------------------------------------------------------------------------------
Real W3DView::calcCameraAreaOffset(Real maxEdgeZ, Bool isLookingDown)
Real W3DView::calcCameraAreaOffset(Real maxEdgeZ)
{
Coord2D center;
ICoord2D screen;
Vector3 rayStart;
Vector3 rayEnd;

//Pick at the center
// Pick at the center
screen.x = 0.5f * getWidth() + m_originX;
screen.y = 0.5f * getHeight() + m_originY;
getPickRay(&screen, &rayStart, &rayEnd);

// Looking at the horizon would yield infinite numbers.
if (fabs(rayStart.Z - rayEnd.Z) < 1.0f)
return 1e+6f;

center.x = Vector3::Find_X_At_Z(maxEdgeZ, rayStart, rayEnd);
center.y = Vector3::Find_Y_At_Z(maxEdgeZ, rayStart, rayEnd);

const Bool isLookingDown = rayStart.Z >= rayEnd.Z;
const Real height = isLookingDown ? getHeight() : 0.0f;
screen.y = height + m_originY;
getPickRay(&screen, &rayStart, &rayEnd);
Expand Down Expand Up @@ -1555,7 +1560,10 @@ void W3DView::update()
return; // don't draw - makes it faster :) jba.
}

updateCameraAreaConstraints();
if (!didScriptedMovement)
{
updateCameraAreaConstraints();
}

// (gth) C&C3 if m_isCameraSlaved then force the camera to update each frame
if (m_recalcCamera || m_isCameraSlaved)
Expand Down
Loading