Пример #1
0
        private void Check_Movement()
        {
            // Simple check of the mouse.
            if (sngAngleX > 1.3)
            {
                sngAngleX = 1.3F;
            }
            if (sngAngleX < -1.3)
            {
                sngAngleX = -1.3F;
            }
            // Okay, now for the smothing of the movement... Update
            // the forward and backward (walk) movement.
            if (sngWalk > 0)
            {
                sngWalk = sngWalk - 0.005F * (float)TV.TimeElapsed();
                if (sngWalk < 0)
                {
                    sngWalk = 0;
                }
            }
            else
            {
                sngWalk = sngWalk + 0.005F * (float)TV.TimeElapsed();
                if (sngWalk > 0)
                {
                    sngWalk = 0;
                }
            }

            // Now, we update the left and right (strafe) movement.
            if (sngStrafe > 0)
            {
                sngStrafe = sngStrafe - 0.005F * (float)TV.TimeElapsed();
                if (sngStrafe < 0)
                {
                    sngStrafe = 0;
                }
            }
            else
            {
                sngStrafe = sngStrafe + 0.005F * (float)TV.TimeElapsed();
                if (sngStrafe > 0)
                {
                    sngStrafe = 0;
                }
            }

            // Update the vectors using the angles and positions.
            sngPositionX = sngPositionX + (float)(System.Math.Cos((double)sngAngleY) * sngWalk / 5 * TV.TimeElapsed()) + (float)(System.Math.Cos((double)sngAngleY + 3.141596 / 2) * sngStrafe / 5 * TV.TimeElapsed());
            sngPositionZ = sngPositionZ + (float)(System.Math.Sin((double)sngAngleY) * sngWalk / 5 * TV.TimeElapsed()) + (float)(System.Math.Sin((double)sngAngleY + 3.141596 / 2) * sngStrafe / 5 * TV.TimeElapsed());

            // New : because we are using a landscape with up and down, we
            // can't let the camera at the same height. We want the camera to
            // follow the height of the map, so we use the "get height". Also,
            // because we want to have the effect that we are not a mouse,
            // we will add some height to the height returned...
            //sngPositionY = Land.GetHeight(sngPositionX, sngPositionZ) + 10;
            sngPositionY = WMap.GetPositionHeight(WMap.GetWorldPos(sngPositionX, 0, sngPositionZ)) + 10;

            // We update the look at position.
            snglookatX = sngPositionX + (float)System.Math.Cos((double)sngAngleY);
            snglookatY = sngPositionY + (float)System.Math.Tan((double)sngAngleX);
            snglookatZ = sngPositionZ + (float)System.Math.Sin((double)sngAngleY);

            // With the new values of the camera vectors (position and
            // look at), we update the scene's camera.
            Scene.SetCamera(sngPositionX, sngPositionY, sngPositionZ, snglookatX, snglookatY, snglookatZ);

            //We set it in the engine
            GlobalVars.GameEngine.WMap.SetPlayerPosition(sngPositionX, sngPositionY, sngPositionZ);
        }