Skip to content

Commit

Permalink
Clamp model bounding box values before centering view
Browse files Browse the repository at this point in the history
Set far Z to 2^24 so really really really large models show up
  • Loading branch information
Solokiller committed Apr 6, 2019
1 parent 54f2c05 commit be2ef47
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/stdlib/graphics/GraphicsUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void SetProjection( const float flFOV, const int iWidth, const int iHeight )
{
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( flFOV, ( GLfloat ) iWidth / ( GLfloat ) iHeight, 1.0f, 4096.0f );
gluPerspective( flFOV, ( GLfloat ) iWidth / ( GLfloat ) iHeight, 1.0f, 1 << 24 );
}

void DrawBox( const glm::vec3* const v )
Expand Down
10 changes: 10 additions & 0 deletions src/tools/hlmv/CHLMVState.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "shared/Utility.h"

#include "shared/studiomodel/CStudioModel.h"

#include "game/entity/CBaseEntityList.h"
Expand Down Expand Up @@ -93,6 +95,14 @@ void CHLMVState::CenterView()
glm::vec3 min, max;
m_pEntity->ExtractBbox( min, max );

//Clamp the values to a reasonable range
for( int i = 0; i < 3; ++i )
{
//Use different limits for min and max so centering won't end up setting origin to 0 0 0
min[ i ] = clamp( min[ i ], -2000.f, 2000.f );
max[ i ] = clamp( max[ i ], -1000.f, 1000.f );
}

float dx = max[ 0 ] - min[ 0 ];
float dy = max[ 1 ] - min[ 1 ];
float dz = max[ 2 ] - min[ 2 ];
Expand Down

0 comments on commit be2ef47

Please sign in to comment.