コード例 #1
0
CTerrain::CTerrain(IDirect3DDevice9* device,
    std::string heightmapFileName,
    int numVertsPerRow,
    int numVertsPerCol,
    int cellSpacing,
    float heightScale)
{
    _device = device;
    _numVertsPerRow = numVertsPerRow;
    _numVertsPerCol = numVertsPerCol;
    _cellSpacing = cellSpacing;

    _numCellsPerRow = _numVertsPerRow - 1;
    _numCellsPerCol = _numVertsPerCol - 1;

    _width = _numCellsPerRow * _cellSpacing;
    _depth = _numCellsPerCol * _cellSpacing;

    _numVertices = _numVertsPerRow * _numVertsPerCol;
    _numTriangles = _numCellsPerRow * _numCellsPerCol * 2;

    _heightScale = heightScale;

    // 加载高度图
    if (!readRawFile(heightmapFileName))
    {
        ::MessageBox(0, _T("readRawFile - FAILED"), 0, 0);
        ::PostQuitMessage(0);
    }

    // 高度缩放
    for (unsigned int i = 0; i < _heightmap.size(); i++)
        _heightmap[i] *= heightScale;

    // 计算点点坐标
    if (!computeVertices())
    {
        ::MessageBox(0, _T("computeVertices - FAILED"), 0, 0);
        ::PostQuitMessage(0);
    }

    // 计算索引
    if (!computeIndices())
    {
        ::MessageBox(0, _T("computeIndices - FAILED"), 0, 0);
        ::PostQuitMessage(0);
    }
    computeNormals();
}
コード例 #2
0
ファイル: terrain.cpp プロジェクト: jtianling/introd3d9
Terrain::Terrain(IDirect3DDevice9* device,
				 std::string heightmapFileName,
				 int numVertsPerRow,
				 int numVertsPerCol,
				 int cellSpacing,
				 float heightScale)
{
	_device         = device;
	_numVertsPerRow = numVertsPerRow;
	_numVertsPerCol = numVertsPerCol;
	_cellSpacing    = cellSpacing;

	_numCellsPerRow = _numVertsPerRow - 1;
	_numCellsPerCol = _numVertsPerCol - 1;

	_width = _numCellsPerRow * _cellSpacing;
	_depth = _numCellsPerCol * _cellSpacing;

	_numVertices  = _numVertsPerRow * _numVertsPerCol;
	_numTriangles = _numCellsPerRow * _numCellsPerCol * 2;

	_heightScale = heightScale;

	// load heightmap
	if( !readRawFile(heightmapFileName) )
	{
		::MessageBox(0, "readRawFile - FAILED", 0, 0);
		::PostQuitMessage(0);
	}

	// scale heights
	for(int i = 0; i < _heightmap.size(); i++)
		_heightmap[i] *= heightScale;

	// compute the vertices
	if( !computeVertices() )
	{
		::MessageBox(0, "computeVertices - FAILED", 0, 0);
		::PostQuitMessage(0);
	}

	// compute the indices
	if( !computeIndices() )
	{
		::MessageBox(0, "computeIndices - FAILED", 0, 0);
		::PostQuitMessage(0);
	}
}
コード例 #3
0
				bool TileAssembler::fillModelIntoTree(AABSPTree<SubModel *> *pMainTree, const Vector3& pBasePos, std::string& pPos, std::string& pModelFilename)
				{
					bool result = false;
					ModelPosition modelPosition;
					getModelPosition(pPos, modelPosition);
					// all should be relative to object base position
					modelPosition.moveToBasePos(pBasePos);

					modelPosition.init();

					if(readRawFile(pModelFilename,  modelPosition, pMainTree))
					{
						result = true;
					}

					return result;
				}