예제 #1
0
void Terrain::init(ID3D10Device* device, const InitInfo& initInfo)
{
	md3dDevice = device;

	mTech          = fx::TerrainFX->GetTechniqueByName("TerrainTech");
	mfxWVPVar      = fx::TerrainFX->GetVariableByName("gWVP")->AsMatrix();
	mfxWorldVar    = fx::TerrainFX->GetVariableByName("gWorld")->AsMatrix();
	mfxDirToSunVar = fx::TerrainFX->GetVariableByName("gDirToSunW")->AsVector();
	mfxLayer0Var   = fx::TerrainFX->GetVariableByName("gLayer0")->AsShaderResource();
	mfxLayer1Var   = fx::TerrainFX->GetVariableByName("gLayer1")->AsShaderResource();
	mfxLayer2Var   = fx::TerrainFX->GetVariableByName("gLayer2")->AsShaderResource();
	mfxLayer3Var   = fx::TerrainFX->GetVariableByName("gLayer3")->AsShaderResource();
	mfxLayer4Var   = fx::TerrainFX->GetVariableByName("gLayer4")->AsShaderResource();
	mfxBlendMapVar = fx::TerrainFX->GetVariableByName("gBlendMap")->AsShaderResource();

	mInfo = initInfo;

	mNumVertices = mInfo.NumRows*mInfo.NumCols;
	mNumFaces    = (mInfo.NumRows-1)*(mInfo.NumCols-1)*2;

	loadHeightmap();
	smooth();

	buildVB();
	buildIB();

	mLayer0   = GetTextureMgr().createTex(initInfo.LayerMapFilename0);
	mLayer1   = GetTextureMgr().createTex(initInfo.LayerMapFilename1);
	mLayer2   = GetTextureMgr().createTex(initInfo.LayerMapFilename2);
	mLayer3   = GetTextureMgr().createTex(initInfo.LayerMapFilename3);
	mLayer4   = GetTextureMgr().createTex(initInfo.LayerMapFilename4);
	mBlendMap = GetTextureMgr().createTex(initInfo.BlendMapFilename);
}
예제 #2
0
Terrain::Terrain(std::string filename, float resolution, float interval)
{
	// set member values
	m_interval = interval;
	m_resolution = resolution;

	// initialize the height field
	loadHeightmap(filename);

	for (int z = 1; z < m_resolutionY - 1; z++){
		for (int x = 1; x < m_resolutionX - 1; x++){
			m_normals.push_back(calculateNormal(x, z));
			m_vertices.push_back(glm::vec4(x, getHeight(glm::vec2(x, z)), z, 1.0));
			//m_uvs.push_back(glm::vec2(x / (float)m_resolutionX, z / (float)m_resolutionY));
			m_uvs.push_back(glm::vec2((float)x / 5, (float)z / 5));
		}
	}

	int offset = 0;
	for (int z = 0; z < m_resolutionY - 3; z++){
		for (int x = 0; x < m_resolutionX - 3; x++){
			// 1. Triangle
			m_index.push_back(offset + x);
			m_index.push_back(offset + x + 1);
			m_index.push_back(offset + x + (m_resolutionY - 2));

			// 2. Triangle
			m_index.push_back(offset + x + (m_resolutionY - 2));
			m_index.push_back(offset + x + 1);
			m_index.push_back(offset + x + (m_resolutionY - 2) + 1);
		}
		offset += (m_resolutionY - 2);
	}

	m_indices = m_index.size();
	m_points = m_vertices.size();
	setNormalsTrue();
	setIndexTrue();
	setUVTrue();

}
    //-------------------------------------------------------------------------
    void HeightmapTerrainPageSource::initialise(TerrainSceneManager* tsm, 
        ushort tileSize, ushort pageSize, bool asyncLoading, 
        TerrainPageSourceOptionList& optionList)
    {
        // Shutdown to clear any previous data
        shutdown();

        TerrainPageSource::initialise(tsm, tileSize, pageSize, asyncLoading, optionList);

        // Get source image
        TerrainPageSourceOptionList::iterator ti, tiend;
        tiend = optionList.end();
        bool imageFound = false;
        mIsRaw = false;
        bool rawSizeFound = false;
        bool rawBppFound = false;
        for (ti = optionList.begin(); ti != tiend; ++ti)
        {
            String val = ti->first;
            StringUtil::trim(val);
            if (StringUtil::startsWith(val, "Heightmap.image", false))
            {
                mSource = ti->second;
                imageFound = true;
                // is it a raw?
                if (StringUtil::endsWith(mSource, "raw"))
                {
                    mIsRaw = true;
                }
            }
            else if (StringUtil::startsWith(val, "Heightmap.raw.size", false))
            {
                mRawSize = atoi(ti->second.c_str());
                rawSizeFound = true;
            }
            else if (StringUtil::startsWith(val, "Heightmap.raw.bpp", false))
            {
                mRawBpp = atoi(ti->second.c_str());
                if (mRawBpp < 1 || mRawBpp > 2)
                {
                    OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, 
                        "Invalid value for 'Heightmap.raw.bpp', must be 1 or 2",
                        "HeightmapTerrainPageSource::initialise");
                }
                rawBppFound = true;
            }
            else if (StringUtil::startsWith(val, "Heightmap.flip", false))
            {
                mFlipTerrain = StringConverter::parseBool(ti->second);
            }
            else
            {
                LogManager::getSingleton().logMessage("Warning: ignoring unknown Heightmap option '"
                    + val + "'");
            }
        }
        if (!imageFound)
        {
            OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, 
                "Missing option 'Heightmap.image'", 
                "HeightmapTerrainPageSource::initialise");
        }
        if (mIsRaw && 
            (!rawSizeFound || !rawBppFound))
        {
            OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, 
                "Options 'Heightmap.raw.size' and 'Heightmap.raw.bpp' must "
                "be specified for RAW heightmap sources", 
                "HeightmapTerrainPageSource::initialise");
        }
        // Load it!
        loadHeightmap();
    }