Skip to content

Commit 234f633

Browse files
committed
Replicate in Generals
1 parent 70c8ad4 commit 234f633

File tree

3 files changed

+24
-40
lines changed
  • Generals/Code

3 files changed

+24
-40
lines changed

Generals/Code/GameEngine/Include/GameClient/View.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ class View : public Snapshot
182182
virtual Real getZoom() { return m_zoom; }
183183
virtual void setZoom(Real z) { }
184184
virtual Real getHeightAboveGround() { return m_heightAboveGround; }
185-
virtual void setHeightAboveGround(Real z) { m_heightAboveGround = z; }
185+
virtual void setHeightAboveGround(Real z);
186186
virtual void zoom( Real height ); ///< Zoom in/out, closer to the ground, limit to min, or farther away from the ground, limit to max
187-
virtual void setZoomToDefault( void ) { } ///< Set zoom to default value
187+
virtual void setZoomToDefault( void ) { m_zoom = 1.0f; } ///< Set zoom to default value
188188
virtual Real getMaxZoom( void ) { return m_maxZoom; } ///< return max zoom value
189189
virtual void setOkToAdjustHeight( Bool val ) { m_okToAdjustHeight = val; } ///< Set this to adjust camera height
190190

@@ -265,8 +265,8 @@ class View : public Snapshot
265265

266266
Real m_maxZoom; ///< Largest zoom value (minimum actual zoom)
267267
Real m_minZoom; ///< Smallest zoom value (maximum actual zoom)
268-
Real m_maxHeightAboveGround;
269-
Real m_minHeightAboveGround;
268+
Real m_maxHeightAboveGround; ///< Highest camera above ground value
269+
Real m_minHeightAboveGround; ///< Lowest camera above ground value
270270
Real m_zoom; ///< Current zoom value
271271
Real m_heightAboveGround; ///< User's desired height above ground
272272
Bool m_zoomLimited; ///< Camera restricted in zoom height
@@ -276,7 +276,7 @@ class View : public Snapshot
276276
Real m_terrainHeightUnderCamera; ///< Cached value for debugging
277277

278278
ObjectID m_cameraLock; ///< if nonzero, id of object that the camera should follow
279-
Drawable *m_cameraLockDrawable; ///< if nonzero, drawble of object that camera should follow.
279+
Drawable *m_cameraLockDrawable; ///< if nonzero, drawable of object that camera should follow.
280280
CameraLockType m_lockType; ///< are we following or just tethering?
281281
Real m_lockDist; ///< how far can we be when tethered?
282282

@@ -286,7 +286,7 @@ class View : public Snapshot
286286
Bool m_okToAdjustHeight; ///< Should we attempt to adjust camera height?
287287
Bool m_snapImmediate; ///< Should we immediately snap to the object we're following?
288288

289-
Coord2D m_guardBandBias; ///< Exttra beefy margins so huge thins can stay "on-screen"
289+
Coord2D m_guardBandBias; ///< Extra beefy margins so huge thins can stay "on-screen"
290290

291291
};
292292

Generals/Code/GameEngine/Source/GameClient/View.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,8 @@ void View::setAngle( Real angle )
166166
*/
167167
void View::setPitch( Real angle )
168168
{
169-
m_pitchAngle = angle;
170-
171-
Real limit = PI/5.0f;
172-
173-
if (m_pitchAngle < -limit)
174-
m_pitchAngle = -limit;
175-
else if (m_pitchAngle > limit)
176-
m_pitchAngle = limit;
169+
constexpr Real limit = PI/5.0f;
170+
m_pitchAngle = clamp(-limit, angle, limit);
177171
}
178172

179173
/**
@@ -185,6 +179,19 @@ void View::setAngleAndPitchToDefault( void )
185179
m_pitchAngle = m_defaultPitchAngle;
186180
}
187181

182+
void View::setHeightAboveGround(Real z)
183+
{
184+
// if our zoom is limited, we will stay within a predefined distance from the terrain
185+
if( m_zoomLimited )
186+
{
187+
m_heightAboveGround = clamp(m_minHeightAboveGround, z, m_maxHeightAboveGround);
188+
}
189+
else
190+
{
191+
m_heightAboveGround = z;
192+
}
193+
}
194+
188195
/**
189196
* write the view's current location in to the view location object
190197
*/

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,7 @@ inline Real maxf(Real a, Real b) { if (a > b) return a; else return b; }
117117
//-------------------------------------------------------------------------------------------------
118118
static void normAngle(Real &angle)
119119
{
120-
if (angle < -10*PI) {
121-
angle = 0;
122-
}
123-
if (angle > 10*PI) {
124-
angle = 0;
125-
}
126-
while (angle < -PI) {
127-
angle += 2*PI;
128-
}
129-
while (angle > PI) {
130-
angle -= 2*PI;
131-
}
120+
angle = WWMath::Normalize_Angle(angle);
132121
}
133122

134123
#define TERRAIN_SAMPLE_SIZE 40.0f
@@ -1753,7 +1742,7 @@ void W3DView::setAngleAndPitchToDefault( void )
17531742
// call our base class, we are adding functionality
17541743
View::setAngleAndPitchToDefault();
17551744

1756-
this->m_FXPitch = 1.0;
1745+
m_FXPitch = 1.0;
17571746

17581747
// set the camera
17591748
setCameraTransform();
@@ -1775,19 +1764,7 @@ void W3DView::setDefaultView(Real pitch, Real angle, Real maxHeight)
17751764
//-------------------------------------------------------------------------------------------------
17761765
void W3DView::setHeightAboveGround(Real z)
17771766
{
1778-
m_heightAboveGround = z;
1779-
1780-
// if our zoom is limited, we will stay within a predefined distance from the terrain
1781-
if( m_zoomLimited )
1782-
{
1783-
1784-
if (m_heightAboveGround < m_minHeightAboveGround)
1785-
m_heightAboveGround = m_minHeightAboveGround;
1786-
1787-
if (m_heightAboveGround > m_maxHeightAboveGround)
1788-
m_heightAboveGround = m_maxHeightAboveGround;
1789-
1790-
}
1767+
View::setHeightAboveGround(z);
17911768

17921769
m_doingMoveCameraOnWaypointPath = false;
17931770
m_doingRotateCamera = false;

0 commit comments

Comments
 (0)