MyGame.MyGame.GetHeightAtPosition C# (CSharp) Method

GetHeightAtPosition() public method

public GetHeightAtPosition ( float X, float Z ) : float
X float
Z float
return float
        public float GetHeightAtPosition(float X, float Z)
        {
            float steepness;
            //if (Constants.NUM_OF_TERRAINS == 1)
                return clamp(terrain.GetHeightAtPosition(X, Z, out steepness));
            //if (X > -512 * Constants.TERRAIN_CELL_SIZE && X < 0 &&
            //    Z > -512 * Constants.TERRAIN_CELL_SIZE && Z < 0)
            //    return clamp(terrain[3].GetHeightAtPosition(X, Z, out steepness));
            //else if (X > -512 * Constants.TERRAIN_CELL_SIZE && X < 0 &&
            //         Z > 0 && Z < 512 * Constants.TERRAIN_CELL_SIZE)
            //    return clamp(terrain[1].GetHeightAtPosition(X, Z, out steepness));
            //else if (X >= 0 && X < 512 * Constants.TERRAIN_CELL_SIZE &&
            //         Z >= 0 && Z < 512 * Constants.TERRAIN_CELL_SIZE)
            //    return clamp(terrain[0].GetHeightAtPosition(X, Z, out steepness));
            //else if (X >= 0 && X < 512 * Constants.TERRAIN_CELL_SIZE &&
            //         Z > -512 * Constants.TERRAIN_CELL_SIZE && Z < 0)
            //    return clamp(terrain[2].GetHeightAtPosition(X, Z, out steepness));
            //else
            //    return 0;
            //return clamp(terrain[0].GetHeightAtPosition(X, Z, out steepness)) ;
        }

Usage Example

        /// <summary>
        /// Add a new medkit at a random location on the terrain
        /// </summary>
        private void addFirstAidKit()
        {
            float y = Constants.TERRAIN_HEIGHT;
            float x = 0, z = 0;

            while (y > .7 * Constants.TERRAIN_HEIGHT)
            {
                x = (float)(rnd.NextDouble() * Constants.FIELD_MAX_X_Z * 2 - Constants.FIELD_MAX_X_Z);
                z = (float)(rnd.NextDouble() * Constants.FIELD_MAX_X_Z * 2 - Constants.FIELD_MAX_X_Z);
                y = myGame.GetHeightAtPosition(x, z);
            }
            Vector3  pos      = new Vector3(x, y, z) + Constants.MEDKIT_OFFSET;
            Unit     unit     = new Unit(myGame, pos, Vector3.Zero, Constants.MEDKIT_SCALE);
            FirstAid firstAid = new FirstAid(myGame, myGame.Content.Load <Model>(@"model/First Aid Kit2"), unit);

            firstAidKits.Add(firstAid);
        }
All Usage Examples Of MyGame.MyGame::GetHeightAtPosition