/// <summary>
        /// Handles command messages from <see cref="TrackingCameraCommands"/>
        /// </summary>
        private void HandleCommand( CommandTriggerData triggerData )
        {
            if ( triggerData.Command == TrackingCameraCommands.Zoom )
            {
                m_Camera.Radius += ( ( CommandScalarInputState )triggerData.InputState ).Value;
            }
            else if ( triggerData.Command == TrackingCameraCommands.Pan )
            {
                if ( !m_Camera.CanModifyLookAtPoint )
                {
                    return;
                }

                CommandPointInputState cursorMsg = ( CommandPointInputState )triggerData.InputState;
                Vector2 delta = cursorMsg.Delta;

                UniPoint3 newLookAt = m_Camera.LookAtPoint;

                newLookAt += m_Camera.Frame.TransposedXAxis * Units.Convert.MetresToUni( delta.X );
                newLookAt += m_Camera.Frame.TransposedYAxis * Units.Convert.MetresToUni( delta.Y );

                m_Camera.LookAtPoint = newLookAt;
            }
            else if ( triggerData.Command == TrackingCameraCommands.Rotate )
            {
                CommandPointInputState cursorMsg = ( CommandPointInputState )triggerData.InputState;
                Vector2 delta = cursorMsg.Delta;

                m_Camera.S -= delta.X * 0.01f;
                m_Camera.T -= delta.Y * 0.01f;
            }
        }
        public void TestSerializeDeserializeWithNoInputState( )
        {
            CommandTriggerData dataIn = new CommandTriggerData( m_User, m_Command0, null );
            CommandTriggerData dataOut = SerializeDeserialize( m_Formatter, dataIn );

            Assert.AreEqual( dataIn.User, dataOut.User );
            Assert.AreEqual( dataIn.Command, dataOut.Command );
            Assert.AreEqual( dataIn.InputState, dataOut.InputState );
        }
 public void TestDeserializeTriggerDataWithoutContextThrows( )
 {
     CommandTriggerData dataIn = new CommandTriggerData( m_User, m_Command0, null );
     try
     {
         SerializeDeserialize( new BinaryFormatter( ), dataIn );
         Assert.Fail( "Expected deserialization to throw a TargetInvocationException with an inner IOException" );
     }
     catch ( Exception ex )
     {
         Assert.AreEqual( typeof( TargetInvocationException ), ex.GetType( ) );
         Assert.AreEqual( typeof( IOException ), ex.InnerException.GetType( ) );
     }
 }
        public void TestSerializeDeserializeWithPointInputState( )
        {
            CommandTriggerData dataIn = new CommandTriggerData( m_User, m_Command0, new CommandPointInputState( new Point2( 1, 1 ), new Point2( 2, 2 ) ) );
            CommandTriggerData dataOut = SerializeDeserialize( m_Formatter, dataIn );

            Assert.AreEqual( dataIn.User, dataOut.User );
            Assert.AreEqual( dataIn.Command, dataOut.Command );
            Assert.IsTrue( Loose.DeepEquality( dataIn.InputState, dataOut.InputState ) );
        }
        /// <summary>
        /// Serializes a CommandTriggerData object, then deserializes it
        /// </summary>
        private static CommandTriggerData SerializeDeserialize( BinaryFormatter formatter, CommandTriggerData dataIn )
        {
            MemoryStream stream = new MemoryStream( );

            formatter.Serialize( stream, dataIn );

            stream.Position = 0;
            return ( CommandTriggerData )formatter.Deserialize( stream );
        }
 /// <summary>
 /// Raises the <see cref="CommandTriggered"/> event
 /// </summary>
 /// <param name="triggerData">Trigger data to pass to the event</param>
 /// <remarks>
 /// Warning:
 /// Calling this does not raise the event <see cref="Command.CommandTriggered"/>, but
 /// calling <see cref="Command.Trigger"/> will call this method.
 /// Call <see cref="Command.Trigger"/> by preference
 /// </remarks>
 public void OnCommandTriggered( CommandTriggerData triggerData )
 {
     Arguments.CheckNotNull( triggerData, "triggerData" );
     if ( triggerData.User.Id != Id )
     {
         throw new ArgumentException( string.Format( "Trigger data did not contain the correct user (was user \"{0}\", expected user \"{1}\"", triggerData.User.Name, Name ) );
     }
     if ( CommandTriggered != null )
     {
         CommandTriggered( triggerData );
     }
 }
 private void OnCommandTriggered( CommandTriggerData triggerData )
 {
     display.Invalidate( );
 }
        /// <summary>
        /// Handles camera commands
        /// </summary>
        private void HandleCommand( CommandTriggerData triggerData )
        {
            if ( m_Camera == null )
            {
                return;
            }

            float secondsSinceLastUpdate = m_SecondsSinceLastUpdate;

            InvariantMatrix44 movementFrame = m_Camera.InverseFrame;
            if ( triggerData.Command == FirstPersonCameraCommands.Forwards )
            {
                m_Camera.Position.Add( movementFrame.ZAxis * -MaxForwardSpeed * secondsSinceLastUpdate );
            }
            else if ( triggerData.Command == FirstPersonCameraCommands.Backwards )
            {
                m_Camera.Position.Add( movementFrame.ZAxis * MaxForwardSpeed * secondsSinceLastUpdate );
            }
            else if ( triggerData.Command == FirstPersonCameraCommands.PitchUp )
            {
                m_Camera.ChangePitch( -MaxTurnSpeed * secondsSinceLastUpdate );
            }
            else if ( triggerData.Command == FirstPersonCameraCommands.PitchDown )
            {
                m_Camera.ChangePitch( MaxTurnSpeed * secondsSinceLastUpdate );
            }
            else if ( triggerData.Command == FirstPersonCameraCommands.YawLeft )
            {
                m_Camera.ChangeYaw( MaxTurnSpeed * secondsSinceLastUpdate );
            }
            else if ( triggerData.Command == FirstPersonCameraCommands.YawRight )
            {
                m_Camera.ChangeYaw( -MaxTurnSpeed * secondsSinceLastUpdate );
            }
            else if ( triggerData.Command == FirstPersonCameraCommands.RollClockwise )
            {
                m_Camera.ChangeRoll( -MaxTurnSpeed * secondsSinceLastUpdate );
            }
            else if ( triggerData.Command == FirstPersonCameraCommands.RollAnticlockwise )
            {
                m_Camera.ChangeRoll( MaxTurnSpeed * secondsSinceLastUpdate );
            }
            else if ( triggerData.Command == FirstPersonCameraCommands.SlipLeft )
            {
                m_Camera.Position -= movementFrame.XAxis * MaxSlipSpeed * secondsSinceLastUpdate;
            }
            else if ( triggerData.Command == FirstPersonCameraCommands.SlipRight )
            {
                m_Camera.Position += movementFrame.XAxis * MaxSlipSpeed * secondsSinceLastUpdate;
            }
            else if ( triggerData.Command == FirstPersonCameraCommands.Turn )
            {
                CommandPointInputState pointState = ( CommandPointInputState )triggerData.InputState;
                Vector2 delta = pointState.Delta * 0.01f * secondsSinceLastUpdate;

                m_Camera.ChangeYaw( -delta.X );
                m_Camera.ChangePitch( -delta.Y );
            }
        }
 /// <summary>
 /// Triggers the command (raises the command triggered event)
 /// </summary>
 public virtual void Trigger( CommandTriggerData triggerData )
 {
     Arguments.CheckNotNull( triggerData, "triggerData" );
     if ( CommandTriggered != null )
     {
         CommandTriggered( triggerData );
     }
     if ( triggerData.User != null )
     {
         triggerData.User.OnCommandTriggered( triggerData );
     }
 }
        /// <summary>
        /// Handles command messages, from the <see cref="Commands"/> enum
        /// </summary>
        private void HandleCameraCommand( CommandTriggerData data )
        {
            if ( data .Command == Zoom )
            {
                Camera.Zoom += ( ( CommandScalarInputState )data.InputState ).Value;
            }
            else if ( data.Command == Pan )
            {
                CommandPointInputState cursorMsg = ( CommandPointInputState )data.InputState;
                Vector2 delta = cursorMsg.Delta * PanSpeed;

                Point3 newLookAt = Camera.LookAt;

                newLookAt += Camera.Frame.XAxis * delta.X;
                newLookAt += Camera.Frame.YAxis * delta.Y;

                Camera.LookAt = newLookAt;
            }
            else if ( data.Command == Rotate )
            {
                CommandPointInputState cursorMsg = ( CommandPointInputState )data.InputState;
                Vector2 delta = cursorMsg.Delta * PanSpeed;
                Camera.S += delta.X * 0.01f;
                Camera.T -= delta.Y * 0.01f;
            }
        }