protected override void OnFrameStarted( object source, FrameEventArgs evt )
{
base.OnFrameStarted( source, evt );
if ( evt.StopRendering )
return;
objectsVisible = 0;
float speed = 35 * evt.TimeSinceLastFrame;
float change = 15 * evt.TimeSinceLastFrame;
if ( input.IsKeyPressed( KeyCodes.I ) )
{
frustumNode.Translate( new Vector3( 0, 0, -speed ), TransformSpace.Local );
}
if ( input.IsKeyPressed( KeyCodes.K ) )
{
frustumNode.Translate( new Vector3( 0, 0, speed ), TransformSpace.Local );
}
if ( input.IsKeyPressed( KeyCodes.J ) )
{
frustumNode.Rotate( Vector3.UnitY, speed );
}
if ( input.IsKeyPressed( KeyCodes.L ) )
{
frustumNode.Rotate( Vector3.UnitY, -speed );
}
if ( input.IsKeyPressed( KeyCodes.D1 ) )
{
if ( frustum.FieldOfView - change > 20 )
{
frustum.FieldOfView -= change;
}
}
if ( input.IsKeyPressed( KeyCodes.D2 ) )
{
if ( frustum.FieldOfView < 90 )
{
frustum.FieldOfView += change;
}
}
if ( input.IsKeyPressed( KeyCodes.D3 ) )
{
if ( frustum.Far - change > 20 )
{
frustum.Far -= change;
}
}
if ( input.IsKeyPressed( KeyCodes.D4 ) )
{
if ( frustum.Far + change < 500 )
{
frustum.Far += change;
}
}
// go through each entity in the scene. if the entity is within
// the frustum, show its bounding box
foreach ( Entity entity in entityList )
{
if ( frustum.IsObjectVisible( entity.GetWorldBoundingBox() ) )
{
entity.ShowBoundingBox = true;
objectsVisible++;
}
else
{
entity.ShowBoundingBox = false;
}
}
// report the number of objects within the frustum
debugText = string.Format( "Objects visible: {0}", objectsVisible );
}