Beispiel #1
0
        // TODO: redo terrain implementation selection to allow other base types than heightMap.
        private BSTerrainPhys BuildPhysicalTerrain(uint id, float[] heightMap)
        {
            // Find high and low points of passed heightmap.
            // The min and max passed in is usually the area objects can be in (maximum
            //     object height, for instance). The terrain wants the bounding box for the
            //     terrain so replace passed min and max Z with the actual terrain min/max Z.
            float minZ = float.MaxValue;
            float maxZ = float.MinValue;

            foreach (float height in heightMap)
            {
                if (height < minZ)
                {
                    minZ = height;
                }
                if (height > maxZ)
                {
                    maxZ = height;
                }
            }
            if (minZ == maxZ)
            {
                // If min and max are the same, reduce min a little bit so a good bounding box is created.
                minZ -= BSTerrainManager.HEIGHT_EQUAL_FUDGE;
            }
            Vector3 minCoords = new Vector3(0, 0, minZ);
            Vector3 maxCoords = new Vector3(PhysicsScene.Scene.RegionInfo.RegionSizeX,
                                            PhysicsScene.Scene.RegionInfo.RegionSizeY, maxZ);

            PhysicsScene.Logger.DebugFormat("{0} Terrain for {1}/ created with {2}",
                                            LogHeader, PhysicsScene.RegionName,
                                            (BSTerrainPhys.TerrainImplementation)BSParam.TerrainImplementation);
            BSTerrainPhys newTerrainPhys = null;

            switch ((int)BSParam.TerrainImplementation)
            {
            case (int)BSTerrainPhys.TerrainImplementation.Heightmap:
                newTerrainPhys = new BSTerrainHeightmap(PhysicsScene, Vector3.Zero, id,
                                                        heightMap, minCoords, maxCoords);
                break;

            case (int)BSTerrainPhys.TerrainImplementation.Mesh:
                newTerrainPhys = new BSTerrainMesh(PhysicsScene, Vector3.Zero, id,
                                                   heightMap, minCoords, maxCoords);
                break;

            default:
                PhysicsScene.Logger.ErrorFormat("{0} Bad terrain implementation specified. Type={1}/{2},Region={3}",
                                                LogHeader,
                                                (int)BSParam.TerrainImplementation,
                                                BSParam.TerrainImplementation,
                                                PhysicsScene.RegionName);
                break;
            }
            return(newTerrainPhys);
        }
        // TODO: redo terrain implementation selection to allow other base types than heightMap.
        private BSTerrainPhys BuildPhysicalTerrain(uint id, float[] heightMap)
        {
            // Find high and low points of passed heightmap.
            // The min and max passed in is usually the area objects can be in (maximum
            //     object height, for instance). The terrain wants the bounding box for the
            //     terrain so replace passed min and max Z with the actual terrain min/max Z.
            float minZ = float.MaxValue;
            float maxZ = float.MinValue;
            foreach (float height in heightMap)
            {
                if (height < minZ) minZ = height;
                if (height > maxZ) maxZ = height;
            }
            if (minZ == maxZ)
            {
                // If min and max are the same, reduce min a little bit so a good bounding box is created.
                minZ -= BSTerrainManager.HEIGHT_EQUAL_FUDGE;
            }
            Vector3 minCoords = new Vector3(0, 0, minZ);
            Vector3 maxCoords = new Vector3(PhysicsScene.Scene.RegionInfo.RegionSizeX,
                PhysicsScene.Scene.RegionInfo.RegionSizeY, maxZ);

            PhysicsScene.Logger.DebugFormat("{0} Terrain for {1}/ created with {2}",
                LogHeader, PhysicsScene.RegionName,
                (BSTerrainPhys.TerrainImplementation)BSParam.TerrainImplementation);
            BSTerrainPhys newTerrainPhys = null;
            switch ((int)BSParam.TerrainImplementation)
            {
                case (int)BSTerrainPhys.TerrainImplementation.Heightmap:
                    newTerrainPhys = new BSTerrainHeightmap(PhysicsScene, Vector3.Zero, id,
                        heightMap, minCoords, maxCoords);
                    break;
                case (int)BSTerrainPhys.TerrainImplementation.Mesh:
                    newTerrainPhys = new BSTerrainMesh(PhysicsScene, Vector3.Zero, id,
                        heightMap, minCoords, maxCoords);
                    break;
                default:
                    PhysicsScene.Logger.ErrorFormat("{0} Bad terrain implementation specified. Type={1}/{2},Region={3}",
                        LogHeader,
                        (int)BSParam.TerrainImplementation,
                        BSParam.TerrainImplementation,
                        PhysicsScene.RegionName);
                    break;
            }
            return newTerrainPhys;
        }