Ejemplo n.º 1
0
        private Ray LinearSearch(Ray ray)
        {
            ray.Direction /= 50.0f;

            Vector3 nextPoint         = ray.Position + ray.Direction;
            float   heightAtNextPoint = terrain.GetExactHeightAt(nextPoint.X, -nextPoint.Z);

            while (heightAtNextPoint < nextPoint.Y)
            {
                ray.Position = nextPoint;

                nextPoint         = ray.Position + ray.Direction;
                heightAtNextPoint = terrain.GetExactHeightAt(nextPoint.X, -nextPoint.Z);
            }
            return(ray);
        }
        protected override void Update(GameTime gameTime)
        {
            GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);

            if (gamePadState.Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            MouseState    mouseState = Mouse.GetState();
            KeyboardState keyState   = Keyboard.GetState();

            fpsCam.Update(mouseState, keyState, gamePadState);

            float   treshold      = 3.0f;
            float   terrainHeight = terrain.GetExactHeightAt(fpsCam.Position.X, -fpsCam.Position.Z);
            Vector3 newPos        = fpsCam.Position;

            newPos.Y        = terrainHeight + treshold;
            fpsCam.Position = newPos;

            base.Update(gameTime);
        }