Exemplo n.º 1
0
        public static float MoveAlongVector(MovingObject entity, TimeStamp p1, TimeStamp p2, float timeStep)
        {
            Vector3 direction = Vector3.Subtract(p2.Vector3, entity.TimePosition);

            double distance = direction.Length();

            Vector3 movement = Vector3.Normalize(direction);

            //Note: This doesn't really work. Different objects travel at different speeds, so having a constant speed here breaks the whole thing. Change the algorithm so that it takes the speeds of different objects into accoutn.
            entity.TimePosition += movement*(entity.Acceleration*timeStep)*5;

            Vector3 checkVector =  Vector3.Subtract(p2.Vector3, entity.TimePosition);

            double checkDistance = checkVector.Length();

            if(checkDistance > distance )
            {

                entity.TimePosition = p2.Vector3;

                int navigation = (int) (p2.Time - p1.Time);

                entity.TimeStamps.Navigate(navigation);

                return (float)(checkDistance - distance);
            }

            return 0;
        }
Exemplo n.º 2
0
        private void SpoolMovingObject(MovingObject movingObject, KeyboardState keyboardState, GameTime gameTime)
        {
            float carry = 0;
            TimeStamp p2 = new TimeStamp();

            if(keyboardState.IsKeyDown(Keys.Left))
            {
                if(movingObject.TimeStamps.Index.Next != null)
                {
                    p2 = movingObject.TimeStamps.Index.Next.Value;
                    carry = TimeStampHelper.MoveAlongVector( movingObject, movingObject.TimeStamps.Index.Value, p2, 5);

                    if(carry != 0)
                    {
            // ReSharper disable ConditionIsAlwaysTrueOrFalse
                        if(movingObject.TimeStamps.Index.Next != null)
                        {
                            TimeStampHelper.MoveAlongVector(movingObject, movingObject.TimeStamps.Index.Value, movingObject.TimeStamps.Index.Next.Value, carry);
                        }
            // ReSharper restore ConditionIsAlwaysTrueOrFalse

                    }
                }

            }

            if (keyboardState.IsKeyDown(Keys.Right))
            {
                if(movingObject.TimeStamps.Index.Previous != null)
                {
                    p2 = movingObject.TimeStamps.Index.Previous.Value;
                    carry = TimeStampHelper.MoveAlongVector(movingObject, movingObject.TimeStamps.Index.Value, p2, 5);

                    if(carry != 0)
                    {
            // ReSharper disable ConditionIsAlwaysTrueOrFalse
                        if(movingObject.TimeStamps.Index.Previous != null)
            // ReSharper restore ConditionIsAlwaysTrueOrFalse
                        {
                            TimeStampHelper.MoveAlongVector(movingObject, movingObject.TimeStamps.Index.Value, movingObject.TimeStamps.Index.Previous.Value, carry);
                        }

                    }
                }

            }
        }