Beispiel #1
0
        public String GetTerrainTypeName(eTerrainModel model)
        {
            switch (model)
            {
            case eTerrainModel.eRadial:
                return("Radial");

            case eTerrainModel.eFractal:
                return("Fractal");

            default:
                Debug.Assert(false, "bad terrain model type");
                break;
            }

            return(null);
        }
        public byte[] GetRawHeightfieldData(eTerrainModel model,PHY_ScalarType type,ref float minHeight,ref float maxHeight)
        {
        //	std::cerr << "\nRegenerating terrain\n";
        //	std::cerr << "  model = " << model << "\n";
        //	std::cerr << "  type = " << type << "\n";

	        long nElements = ((long) s_gridSize) * s_gridSize;
        //	std::cerr << "  nElements = " << nElements << "\n";

	        int bytesPerElement = GetByteSize(type);
        //	std::cerr << "  bytesPerElement = " << bytesPerElement << "\n";
	        Debug.Assert(bytesPerElement > 0,"bad bytes per element");

	        long nBytes = nElements * bytesPerElement;
        //	std::cerr << "  nBytes = " << nBytes << "\n";
	        byte[] raw = new byte[nBytes];
	        Debug.Assert(raw != null ,"out of memory");

	        // reseed randomization every 30 seconds
        //	srand(time(NULL) / 30);

	        // populate based on model
	        switch (model) 
            {
	        case eTerrainModel.eRadial:
		        SetRadial(raw, bytesPerElement, type);
		        break;

            case eTerrainModel.eFractal:
		        for (int i = 0; i < nBytes; i++)
		        {
			        raw[i] = 0;
		        }
		        SetFractal(raw,0, bytesPerElement, type, s_gridSize - 1);
		        break;

	        default:
		        Debug.Assert(false,"bad model type");
                break;
	        }

	        if (false) 
            {
		        // inside if(0) so it keeps compiling but isn't
		        // 	exercised and doesn't cause warnings
        //		std::cerr << "final grid:\n";
		        DumpGrid(raw,bytesPerElement, type, s_gridSize - 1);
	        }

	        // find min/max
	        for (int i = 0; i < s_gridSize; ++i) 
            {
		        for (int j = 0; j < s_gridSize; ++j) 
                {
			        float z = GetGridHeight(raw, i, j, type);
        //			std::cerr << "i=" << i << ", j=" << j << ": z=" << z << "\n";

			        // update min/max
			        if (i == 0 && j == 0) 
                    {
				        minHeight = z;
				        maxHeight = z;
			        } 
                    else 
                    {
				        if (z < minHeight) 
                        {
					        minHeight = z;
				        }
				        if (z > maxHeight) 
                        {
					        maxHeight = z;
				        }
			        }
		        }
	        }

	        if (maxHeight < -minHeight) 
            {
		        maxHeight = -minHeight;
	        }
	        if (minHeight > -maxHeight) 
            {
		        minHeight = -maxHeight;
	        }

        //	std::cerr << "  minHeight = " << minHeight << "\n";
        //	std::cerr << "  maxHeight = " << maxHeight << "\n";

	        return raw;
        }
        public String GetTerrainTypeName(eTerrainModel model)
        {
	        switch (model) 
            {
	        case eTerrainModel.eRadial:
		        return "Radial";

            case eTerrainModel.eFractal:
		        return "Fractal";

	        default:
		        Debug.Assert(false,"bad terrain model type");
                break;
	        }

	        return null;
        }
Beispiel #4
0
        public byte[] GetRawHeightfieldData(eTerrainModel model, PHY_ScalarType type, ref float minHeight, ref float maxHeight)
        {
            //	std::cerr << "\nRegenerating terrain\n";
            //	std::cerr << "  model = " << model << "\n";
            //	std::cerr << "  type = " << type << "\n";

            long nElements = ((long)s_gridSize) * s_gridSize;
            //	std::cerr << "  nElements = " << nElements << "\n";

            int bytesPerElement = GetByteSize(type);

            //	std::cerr << "  bytesPerElement = " << bytesPerElement << "\n";
            Debug.Assert(bytesPerElement > 0, "bad bytes per element");

            long nBytes = nElements * bytesPerElement;

            //	std::cerr << "  nBytes = " << nBytes << "\n";
            byte[] raw = new byte[nBytes];
            Debug.Assert(raw != null, "out of memory");

            // reseed randomization every 30 seconds
            //	srand(time(NULL) / 30);

            // populate based on model
            switch (model)
            {
            case eTerrainModel.eRadial:
                SetRadial(raw, bytesPerElement, type);
                break;

            case eTerrainModel.eFractal:
                for (int i = 0; i < nBytes; i++)
                {
                    raw[i] = 0;
                }
                SetFractal(raw, 0, bytesPerElement, type, s_gridSize - 1);
                break;

            default:
                Debug.Assert(false, "bad model type");
                break;
            }

            if (false)
            {
                // inside if(0) so it keeps compiling but isn't
                //  exercised and doesn't cause warnings
                //		std::cerr << "final grid:\n";
                DumpGrid(raw, bytesPerElement, type, s_gridSize - 1);
            }

            // find min/max
            for (int i = 0; i < s_gridSize; ++i)
            {
                for (int j = 0; j < s_gridSize; ++j)
                {
                    float z = GetGridHeight(raw, i, j, type);
                    //			std::cerr << "i=" << i << ", j=" << j << ": z=" << z << "\n";

                    // update min/max
                    if (i == 0 && j == 0)
                    {
                        minHeight = z;
                        maxHeight = z;
                    }
                    else
                    {
                        if (z < minHeight)
                        {
                            minHeight = z;
                        }
                        if (z > maxHeight)
                        {
                            maxHeight = z;
                        }
                    }
                }
            }

            if (maxHeight < -minHeight)
            {
                maxHeight = -minHeight;
            }
            if (minHeight > -maxHeight)
            {
                minHeight = -maxHeight;
            }

            //	std::cerr << "  minHeight = " << minHeight << "\n";
            //	std::cerr << "  maxHeight = " << maxHeight << "\n";

            return(raw);
        }