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); }
void OutBuilding::build(float w, float h, float d){ VertexPNTList vertices; VertexPNT v; float width = w; float height = h; float depth = d; float thrirdwidth = w/3; float twothirdwidth = (2*w)/3; float twothirdheight = (2*h)/3; //Front v.normal = D3DXVECTOR3( 0.0f, 0.0f, -1.0f); v.pos = D3DXVECTOR3(0.0f, 0.0f, 0.0f); v.texC = D3DXVECTOR2(0.0,0.0); vertices.push_back(v); v.pos = D3DXVECTOR3(0.0f, height, 0.0f); v.texC = D3DXVECTOR2(0.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(thrirdwidth, height, 0.0f); v.texC = D3DXVECTOR2(0.4,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(thrirdwidth, 0.0f, 0.0f); v.texC = D3DXVECTOR2(0.4,0.0); vertices.push_back(v); v.pos = D3DXVECTOR3(thrirdwidth, twothirdheight, 0.0f); v.texC = D3DXVECTOR2(0.4,0.7); vertices.push_back(v); v.pos = D3DXVECTOR3(twothirdwidth, twothirdheight, 0.0f); v.texC = D3DXVECTOR2(0.8,0.7); vertices.push_back(v); v.pos = D3DXVECTOR3(twothirdwidth, height, 0.0f); v.texC = D3DXVECTOR2(0.8,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(width, height, 0.0f); v.texC = D3DXVECTOR2(1.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(width, 0.0f, 0.0f); v.texC = D3DXVECTOR2(1.0,0.0); vertices.push_back(v); v.pos = D3DXVECTOR3(twothirdwidth, 0.0f, 0.0f); v.texC = D3DXVECTOR2(0.8,0.0); vertices.push_back(v); //Left Face v.normal = D3DXVECTOR3( -1.0f, 0.0f, 0.0f); v.pos = D3DXVECTOR3(0.0f, 0.0f, 0.0f); v.texC = D3DXVECTOR2(0.0,0.0); vertices.push_back(v); v.pos = D3DXVECTOR3(0.0f, height, 0.0f); v.texC = D3DXVECTOR2(0.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(0.0f, height, depth); v.texC = D3DXVECTOR2(1.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(0.0f, 0.0f, depth); v.texC = D3DXVECTOR2(1.0,0.0); vertices.push_back(v); //Top v.normal = D3DXVECTOR3( 0.0f, 1.0f, 0.0f); v.pos = D3DXVECTOR3(0.0f, height, 0.0f); v.texC = D3DXVECTOR2(0.0,0.0); vertices.push_back(v); v.pos = D3DXVECTOR3(0.0f, height, depth); v.texC = D3DXVECTOR2(0.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(width, height, depth); v.texC = D3DXVECTOR2(1.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(width, height, 0.0f); v.texC = D3DXVECTOR2(1.0,0.0); vertices.push_back(v); //Right v.normal = D3DXVECTOR3( 1.0f, 0.0f, 0.0f); v.pos = D3DXVECTOR3(width, 0.0f, 0.0f); v.texC = D3DXVECTOR2(0.0,0.0); vertices.push_back(v); v.pos = D3DXVECTOR3(width, 0.0f, depth); v.texC = D3DXVECTOR2(0.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(width, height, depth); v.texC = D3DXVECTOR2(1.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(width, height, 0.0f); v.texC = D3DXVECTOR2(1.0,0.0); vertices.push_back(v); //Bottom v.normal = D3DXVECTOR3( 0.0f, -1.0f, 0.0f); v.pos = D3DXVECTOR3(0.0f, 0.0f, 0.0f); v.texC = D3DXVECTOR2(0.0,0.0); vertices.push_back(v); v.pos = D3DXVECTOR3(0.0f, 0.0f, depth); v.texC = D3DXVECTOR2(0.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(width, 0.0f, depth); v.texC = D3DXVECTOR2(1.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(width, 0.0f, 0.0f); v.texC = D3DXVECTOR2(1.0,0.0); vertices.push_back(v); //Back v.normal = D3DXVECTOR3( 0.0f, 0.0f, 1.0f); v.pos = D3DXVECTOR3(width, 0.0f, depth); v.texC = D3DXVECTOR2(0.0,0.0); vertices.push_back(v); v.pos = D3DXVECTOR3(width, height, depth); v.texC = D3DXVECTOR2(0.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(0.0f, height, depth); v.texC = D3DXVECTOR2(1.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(0.0f, 0.0f, depth); v.texC = D3DXVECTOR2(1.0,0.0); vertices.push_back(v); mNumVertices = (UINT)vertices.size(); buildVB(vertices); IndexList indices; indices.push_back(0); indices.push_back(1); indices.push_back(2); indices.push_back(2); indices.push_back(3); indices.push_back(0); indices.push_back(4); indices.push_back(2); indices.push_back(6); indices.push_back(6); indices.push_back(5); indices.push_back(4); indices.push_back(9); indices.push_back(6); indices.push_back(7); indices.push_back(7); indices.push_back(8); indices.push_back(9); indices.push_back(10); indices.push_back(13); indices.push_back(12); indices.push_back(12); indices.push_back(11); indices.push_back(10); indices.push_back(14); indices.push_back(15); indices.push_back(16); indices.push_back(16); indices.push_back(17); indices.push_back(14); indices.push_back(18); indices.push_back(21); indices.push_back(16); indices.push_back(16); indices.push_back(19); indices.push_back(18); indices.push_back(22); indices.push_back(25); indices.push_back(24); indices.push_back(24); indices.push_back(23); indices.push_back(22); indices.push_back(26); indices.push_back(27); indices.push_back(28); indices.push_back(28); indices.push_back(29); indices.push_back(26); mNumFaces = (UINT)indices.size()/3; mNumIndices = (UINT)indices.size(); buildIB(indices); }