protected virtual void OnFrameStarted( object source, FrameEventArgs evt )
{
evt.StopRendering = false;
float scaleMove = 200 * evt.TimeSinceLastFrame;
// reset acceleration zero
camAccel = Vector3.Zero;
// set the scaling of camera motion
cameraScale = 100 * evt.TimeSinceLastFrame;
#if !( SIS )
// TODO: Move this into an event queueing mechanism that is processed every frame
input.Capture();
if ( input.IsKeyPressed( KeyCodes.Escape ) )
{
//Root.Instance.QueueEndRendering();
evt.StopRendering = true;
return;
}
if ( input.IsKeyPressed( KeyCodes.A ) )
{
camAccel.x = -0.5f;
}
if ( input.IsKeyPressed( KeyCodes.D ) )
{
camAccel.x = 0.5f;
}
if ( input.IsKeyPressed( KeyCodes.W ) )
{
camAccel.z = -1.0f;
}
if ( input.IsKeyPressed( KeyCodes.S ) )
{
camAccel.z = 1.0f;
}
//camAccel.y += (float)( input.RelativeMouseZ * 0.1f );
if ( input.IsKeyPressed( KeyCodes.Left ) )
{
camera.Yaw( cameraScale );
}
if ( input.IsKeyPressed( KeyCodes.Right ) )
{
camera.Yaw( -cameraScale );
}
if ( input.IsKeyPressed( KeyCodes.Up ) )
{
camera.Pitch( cameraScale );
}
if ( input.IsKeyPressed( KeyCodes.Down ) )
{
camera.Pitch( -cameraScale );
}
// subtract the time since last frame to delay specific key presses
keypressDelay -= evt.TimeSinceLastFrame;
// toggle rendering mode
if ( input.IsKeyPressed( KeyCodes.R ) && keypressDelay < 0 )
{
if ( camera.PolygonMode == PolygonMode.Points )
{
camera.PolygonMode = PolygonMode.Solid;
}
else if ( camera.PolygonMode == PolygonMode.Solid )
{
camera.PolygonMode = PolygonMode.Wireframe;
}
else
{
//camera.PolygonMode = PolygonMode.Points;
}
SetDebugText( String.Format( "Rendering mode changed to '{0}'.", camera.PolygonMode ) );
keypressDelay = .3f;
}
if ( input.IsKeyPressed( KeyCodes.T ) && keypressDelay < 0 )
{
// toggle the texture settings
switch ( filtering )
{
case TextureFiltering.Bilinear:
filtering = TextureFiltering.Trilinear;
aniso = 1;
break;
case TextureFiltering.Trilinear:
filtering = TextureFiltering.Anisotropic;
aniso = 8;
break;
case TextureFiltering.Anisotropic:
filtering = TextureFiltering.Bilinear;
aniso = 1;
break;
}
SetDebugText( String.Format( "Texture Filtering changed to '{0}'.", filtering ) );
// set the new default
MaterialManager.Instance.SetDefaultTextureFiltering( filtering );
MaterialManager.Instance.DefaultAnisotropy = aniso;
keypressDelay = .3f;
}
#if !( XBOX || XBOX360 )
if ( input.IsKeyPressed( KeyCodes.P ) && keypressDelay < 0 )
{
string[] temp = Directory.GetFiles( Environment.CurrentDirectory, "screenshot*.jpg" );
string fileName = string.Format( "screenshot{0}.jpg", temp.Length + 1 );
TakeScreenshot( fileName );
// show on the screen for some seconds
SetDebugText( string.Format( "Wrote screenshot '{0}'.", fileName ) );
keypressDelay = .3f;
}
#endif
if ( input.IsKeyPressed( KeyCodes.B ) && keypressDelay < 0 )
{
scene.ShowBoundingBoxes = !scene.ShowBoundingBoxes;
SetDebugText( String.Format( "Bounding boxes {0}.", scene.ShowBoundingBoxes ? "visible" : "hidden" ) );
keypressDelay = .3f;
}
if ( input.IsKeyPressed( KeyCodes.F ) && keypressDelay < 0 )
{
// hide all overlays, includes ones besides the debug overlay
viewport.ShowOverlays = !viewport.ShowOverlays;
keypressDelay = .3f;
}
if ( input.IsKeyPressed( KeyCodes.Comma ) && keypressDelay < 0 )
{
Root.Instance.MaxFramesPerSecond = 60;
SetDebugText( String.Format( "Limiting framerate to {0} FPS.", Root.Instance.MaxFramesPerSecond ) );
keypressDelay = .3f;
}
if ( input.IsKeyPressed( KeyCodes.Period ) && keypressDelay < 0 )
{
Root.Instance.MaxFramesPerSecond = 0;
SetDebugText( String.Format( "Framerate limit OFF.", Root.Instance.MaxFramesPerSecond ) );
keypressDelay = .3f;
}
// turn off debug text when delay ends
if ( debugTextDelay < 0.0f )
{
debugTextDelay = 0.0f;
debugText = "";
}
else if ( debugTextDelay > 0.0f )
{
debugTextDelay -= evt.TimeSinceLastFrame;
}
#if DEBUG
if ( !input.IsMousePressed( MouseButtons.Left ) )
{
float cameraYaw = -input.RelativeMouseX * .13f;
float cameraPitch = -input.RelativeMouseY * .13f;
camera.Yaw( cameraYaw );
camera.Pitch( cameraPitch );
}
else
{
// TODO unused
cameraVector.x += input.RelativeMouseX * 0.13f;
}
#endif
#endif
#if ( SIS )
// TODO: Move this into an event queueing mechanism that is processed every frame
mouse.Capture();
keyboard.Capture();
if ( keyboard.IsKeyDown( SharpInputSystem.KeyCode.Key_ESCAPE ) )
{
Root.Instance.QueueEndRendering();
return;
}
if ( keyboard.IsKeyDown( SharpInputSystem.KeyCode.Key_A ) )
{
camAccel.x = -0.5f;
}
if ( keyboard.IsKeyDown( SharpInputSystem.KeyCode.Key_D ) )
{
camAccel.x = 0.5f;
}
if ( keyboard.IsKeyDown( SharpInputSystem.KeyCode.Key_W ) )
{
camAccel.z = -1.0f;
}
if ( keyboard.IsKeyDown( SharpInputSystem.KeyCode.Key_S ) )
{
camAccel.z = 1.0f;
}
camAccel.y += (float)( mouse.MouseState.Z.Relative * 0.1f );
if ( keyboard.IsKeyDown( SharpInputSystem.KeyCode.Key_LEFT ) )
{
camera.Yaw( cameraScale );
}
if ( keyboard.IsKeyDown( SharpInputSystem.KeyCode.Key_RIGHT ) )
{
camera.Yaw( -cameraScale );
}
if ( keyboard.IsKeyDown( SharpInputSystem.KeyCode.Key_UP ) )
{
camera.Pitch( cameraScale );
}
if ( keyboard.IsKeyDown( SharpInputSystem.KeyCode.Key_DOWN ) )
{
camera.Pitch( -cameraScale );
}
// subtract the time since last frame to delay specific key presses
toggleDelay -= e.TimeSinceLastFrame;
// toggle rendering mode
if ( keyboard.IsKeyDown( SharpInputSystem.KeyCode.Key_R ) && toggleDelay < 0 )
{
if ( camera.SceneDetail == SceneDetailLevel.Points )
{
camera.SceneDetail = SceneDetailLevel.Solid;
}
else if ( camera.SceneDetail == SceneDetailLevel.Solid )
{
camera.SceneDetail = SceneDetailLevel.Wireframe;
}
else
{
camera.SceneDetail = SceneDetailLevel.Points;
}
Console.WriteLine( "Rendering mode changed to '{0}'.", camera.SceneDetail );
toggleDelay = 1;
}
if ( keyboard.IsKeyDown( SharpInputSystem.KeyCode.Key_T ) && toggleDelay < 0 )
{
// toggle the texture settings
switch ( filtering )
{
case TextureFiltering.Bilinear:
filtering = TextureFiltering.Trilinear;
aniso = 1;
break;
case TextureFiltering.Trilinear:
filtering = TextureFiltering.Anisotropic;
aniso = 8;
break;
case TextureFiltering.Anisotropic:
filtering = TextureFiltering.Bilinear;
aniso = 1;
break;
}
Console.WriteLine( "Texture Filtering changed to '{0}'.", filtering );
// set the new default
MaterialManager.Instance.SetDefaultTextureFiltering( filtering );
MaterialManager.Instance.DefaultAnisotropy = aniso;
toggleDelay = 1;
}
if ( keyboard.IsKeyDown( SharpInputSystem.KeyCode.Key_P ) )
{
string[] temp = Directory.GetFiles( Environment.CurrentDirectory, "screenshot*.jpg" );
string fileName = string.Format( "screenshot{0}.jpg", temp.Length + 1 );
TakeScreenshot( fileName );
// show briefly on the screen
window.DebugText = string.Format( "Wrote screenshot '{0}'.", fileName );
// show for 2 seconds
debugTextDelay = 2.0f;
}
if ( keyboard.IsKeyDown( SharpInputSystem.KeyCode.Key_B ) )
{
scene.ShowBoundingBoxes = !scene.ShowBoundingBoxes;
}
if ( keyboard.IsKeyDown( SharpInputSystem.KeyCode.Key_F ) )
{
// hide all overlays, includes ones besides the debug overlay
viewport.OverlaysEnabled = !viewport.OverlaysEnabled;
}
if ( !mouse.MouseState.IsButtonDown( SharpInputSystem.MouseButtonID.Left ) )
{
float cameraYaw = -mouse.MouseState.X.Relative * .13f;
float cameraPitch = -mouse.MouseState.Y.Relative * .13f;
camera.Yaw( cameraYaw );
camera.Pitch( cameraPitch );
}
else
{
cameraVector.x += mouse.MouseState.X.Relative * 0.13f;
}
#endif
camVelocity += ( camAccel * scaleMove * camSpeed );
// move the camera based on the accumulated movement vector
camera.MoveRelative( camVelocity * evt.TimeSinceLastFrame );
// Now dampen the Velocity - only if user is not accelerating
if ( camAccel == Vector3.Zero )
{
camVelocity *= ( 1 - ( 6 * evt.TimeSinceLastFrame ) );
}
evt.StopRendering = false;
}