@@ -539,9 +539,9 @@ void W3DView::calcCameraAreaConstraints()
539539 Matrix3D prevCameraTransform = m_3DCamera->Get_Transform ();
540540 m_3DCamera->Set_Transform (cameraTransform);
541541
542- const Vector3 cameraForward = -cameraTransform. Get_Z_Vector ( );
543- const Bool isLookingDown = cameraForward. Z <= 0 . 0f ;
544- Real offset = calcCameraAreaOffset (m_groundLevel, isLookingDown );
542+ Real offset = calcCameraAreaOffset (m_groundLevel );
543+ offset = std::min (offset, (mapRegion. hi . x - mapRegion. lo . x ) / 2 ) ;
544+ offset = std::min (offset, (mapRegion. hi . y - mapRegion. lo . y ) / 2 );
545545
546546 // Revert the 3D camera transform.
547547 m_3DCamera->Set_Transform (prevCameraTransform);
@@ -556,21 +556,26 @@ void W3DView::calcCameraAreaConstraints()
556556}
557557
558558// -------------------------------------------------------------------------------------------------
559- Real W3DView::calcCameraAreaOffset (Real maxEdgeZ, Bool isLookingDown )
559+ Real W3DView::calcCameraAreaOffset (Real maxEdgeZ)
560560{
561561 Coord2D center;
562562 ICoord2D screen;
563563 Vector3 rayStart;
564564 Vector3 rayEnd;
565565
566- // Pick at the center
566+ // Pick at the center
567567 screen.x = 0 .5f * getWidth () + m_originX;
568568 screen.y = 0 .5f * getHeight () + m_originY;
569569 getPickRay (&screen, &rayStart, &rayEnd);
570570
571+ // Looking at the horizon would yield infinite numbers.
572+ if (fabs (rayStart.Z - rayEnd.Z ) < 1 .0f )
573+ return 1e+6f ;
574+
571575 center.x = Vector3::Find_X_At_Z (maxEdgeZ, rayStart, rayEnd);
572576 center.y = Vector3::Find_Y_At_Z (maxEdgeZ, rayStart, rayEnd);
573577
578+ const Bool isLookingDown = rayStart.Z >= rayEnd.Z ;
574579 const Real height = isLookingDown ? getHeight () : 0 .0f ;
575580 screen.y = height + m_originY;
576581 getPickRay (&screen, &rayStart, &rayEnd);
@@ -1555,7 +1560,10 @@ void W3DView::update()
15551560 return ; // don't draw - makes it faster :) jba.
15561561 }
15571562
1558- updateCameraAreaConstraints ();
1563+ if (!didScriptedMovement)
1564+ {
1565+ updateCameraAreaConstraints ();
1566+ }
15591567
15601568 // (gth) C&C3 if m_isCameraSlaved then force the camera to update each frame
15611569 if (m_recalcCamera || m_isCameraSlaved)
0 commit comments