Skip to content

Commit 2d049a5

Browse files
committed
Fix false negative/positives caused by frustum culling
1 parent 0da3b4a commit 2d049a5

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

Samples/2.0/Tests/NearFarProjection/NearFarProjectionGameState.cpp

+17-8
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,19 @@ namespace Demo
4949
planeMeshV1->unload();
5050
}
5151

52+
53+
{
54+
// We must alter the AABB because we want to always pass frustum culling
55+
// Otherwise frustum culling may hide bugs in the projection matrix math
56+
planeMesh->load();
57+
Ogre::Aabb aabb = planeMesh->getAabb();
58+
aabb.mHalfSize.z = aabb.mHalfSize.x;
59+
planeMesh->_setBounds( aabb );
60+
}
61+
5262
Ogre::Item *item = sceneManager->createItem( planeMesh, Ogre::SCENE_DYNAMIC );
5363
mSceneNode = sceneManager->getRootSceneNode( Ogre::SCENE_DYNAMIC )
5464
->createChildSceneNode( Ogre::SCENE_DYNAMIC );
55-
mSceneNode->setPosition( 0, 0, -5 );
5665
mSceneNode->setScale( Ogre::Vector3( 1000.0f ) );
5766
mSceneNode->attachObject( item );
5867

@@ -69,18 +78,18 @@ namespace Demo
6978
camera->setOrientation( Ogre::Quaternion::IDENTITY );
7079

7180
camera->setNearClipDistance( 0.5f );
72-
mSceneNode->setPosition( 0, 0, -0.5f );
81+
mSceneNode->setPosition( 0, 0, -0.5f + 1e-6f );
7382

7483
TutorialGameState::createScene01();
7584
}
7685
//-----------------------------------------------------------------------------------
7786
void NearFarProjectionGameState::generateDebugText( float timeSinceLast, Ogre::String &outText )
7887
{
7988
TutorialGameState::generateDebugText( timeSinceLast, outText );
80-
outText += "\nF2 to test at near plane";
81-
outText += "\nF3 to test after near plane";
82-
outText += "\nF4 to test behind far plane";
83-
outText += "\nF5 to test at far plane";
89+
outText += "\nF2 to test behind near plane (should be blue)";
90+
outText += "\nF3 to test after near plane (should be grey)";
91+
outText += "\nF4 to test behind far plane (should be grey)";
92+
outText += "\nF5 to test after far plane (should be blue)";
8493

8594
char tmpBuffer[256];
8695
Ogre::LwString tmpStr( Ogre::LwString::FromEmptyPointer( tmpBuffer, sizeof( tmpBuffer ) ) );
@@ -107,7 +116,7 @@ namespace Demo
107116

108117
if( arg.keysym.sym == SDLK_F2 )
109118
{
110-
mSceneNode->setPosition( 0, 0, -camera->getNearClipDistance() );
119+
mSceneNode->setPosition( 0, 0, -camera->getNearClipDistance() + 1e-6f );
111120
}
112121
else if( arg.keysym.sym == SDLK_F3 )
113122
{
@@ -119,7 +128,7 @@ namespace Demo
119128
}
120129
else if( arg.keysym.sym == SDLK_F5 )
121130
{
122-
mSceneNode->setPosition( 0, 0, -camera->getFarClipDistance() );
131+
mSceneNode->setPosition( 0, 0, -camera->getFarClipDistance() - 0.5f );
123132
}
124133
else
125134
{

0 commit comments

Comments
 (0)