bool HMTerrain::Initialise(ID3D11Device* pd3dDevice, char* filename, ID3D11ShaderResourceView* texture) { bool result; // Load in the height map for the terrain. result = LoadHeightMap(filename); if (!result) return false; // Normalise the Height int i, j; for (j = 0; j<_pTerrainHeight; j++) { for (i = 0; i<_pTerrainWidth; i++) { _pHeightMap[(_pTerrainHeight * j) + i].y /= 3.75f; } } // Initialize the vertex and index buffer that hold the geometry for the terrain. result = InitialiseBuffers(pd3dDevice); if (!result) return false; _pTextureRV = texture; return true; }
void init() { skybox = new SkyBox(); skybox->initialize(); light.ambient = vec4(0.5f, 0.5f, 0.5f, 1.0f); light.diffuse = vec4(1.0f, 1.0f, 1.0f, 1.0f); light.direction = vec3(-0.5f, -1.0f, 0.0f); camera.perspective(45.0f,(float)width/height,1.0f,1000.0f); camera.lookat(vec3(125.0,10.0,125.0),glm::vec3(0.0),glm::vec3(0.0,1.0,0.0)); shader = new GLShader("shader/TerrainTexturing.vert","shader/TerrainTexturing.frag"); int width, height; unsigned char * ht_mp = LoadHeightMap(width, height); terrain.initialize(ht_mp,width,height,""); textureHandle = getTextureHandle("data/dirt01.dds"); ps = shader->getProgram(); glClearColor(0.0,0.0,0.0,1.0); glEnable(GL_DEPTH_TEST); }
bool TerrainClass::Initialize(ID3D11Device* device, char* heightMapFilename) { bool result; // Load in the height map for the terrain. result = LoadHeightMap(heightMapFilename); if(!result) { return false; } // Normalize the height of the height map. NormalizeHeightMap(); // Calculate the normals for the terrain data. result = CalculateNormals(); if(!result) { return false; } // Initialize the vertex and index buffer that hold the geometry for the terrain. result = InitializeBuffers(device); if(!result) { return false; } return true; }
IActor::ActorReturnState Terrain::Load() { LoadHeightMap(); GenerateVertices(); GenerateIndicesWithTextureMapping(); GenerateVerticesNormal(); BuildGeometryBuffer(); UnloadHeightMap(); SetInitialPhysicsProperties(); return IActor::Load(); }
void Terrain::Init(ID3D11Device* device, const InitInfo& info) { mTerrainData = info; LoadHeightMap(); InitVB(device); InitIB(device); mEffect = new TerrainEffect(); mEffect->LoadEffect(L"FX/terrain.fx", device); LoadTextures(device); }
Mesh* MeshBuilder::GenerateTerrain(const std::string &meshName, const std::string &file_path, std::vector<unsigned char> &heightMap) { const float SCALE_FACTOR = 256.0f; if(!LoadHeightMap(file_path.c_str(), heightMap)) return NULL; Vertex v; std::vector<Vertex> vertex_buffer_data; std::vector<GLuint> index_buffer_data; unsigned terrainSize = (unsigned)sqrt((double)heightMap.size()); for(unsigned z = 0; z < terrainSize; ++z) { for(unsigned x = 0; x < terrainSize; ++x) { float scaledHeight = (float)heightMap[z * terrainSize + x] / SCALE_FACTOR; v.pos.Set(static_cast<float>(x) / terrainSize - 0.5f, scaledHeight, static_cast<float>(z) / terrainSize - 0.5f); v.color.Set(scaledHeight, scaledHeight, scaledHeight); //for rendering height map without texture v.texCoord.Set((float)x / terrainSize*8 , 1.f - (float)z / terrainSize*8); vertex_buffer_data.push_back(v); } } for(unsigned z = 0; z < terrainSize - 1; ++z) { for(unsigned x = 0; x < terrainSize - 1; ++x) { index_buffer_data.push_back(terrainSize * z + x + 0); //Tri 1 index_buffer_data.push_back(terrainSize * (z + 1) + x + 0); index_buffer_data.push_back(terrainSize * z + x + 1); index_buffer_data.push_back(terrainSize * (z + 1) + x + 1); //Tri 2 index_buffer_data.push_back(terrainSize * z + x + 1); index_buffer_data.push_back(terrainSize * (z + 1) + x + 0); } } Mesh *mesh = new Mesh(meshName); glBindBuffer(GL_ARRAY_BUFFER, mesh->vertexBuffer); glBufferData(GL_ARRAY_BUFFER, vertex_buffer_data.size() * sizeof(Vertex), &vertex_buffer_data[0], GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh->indexBuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, index_buffer_data.size() * sizeof(GLuint), &index_buffer_data[0], GL_STATIC_DRAW); mesh->indexSize = index_buffer_data.size(); mesh->mode = Mesh::DRAW_TRIANGLES; return mesh; }
bool TerrainClass::Initialize(ID3D11Device* device, char* heightMapFilename, WCHAR* colorTextureFilename, WCHAR* normalMapFilename) { bool result; // Load in the height map for the terrain. result = LoadHeightMap(heightMapFilename); if(!result) { return false; } // Reduce the height of the height map. ReduceHeightMap(); // Calculate the normals for the terrain data. result = CalculateNormals(); if(!result) { return false; } // Construct a 3D model from the height map and normal data. result = BuildTerrainModel(); if(!result) { return false; } // Calculate the normal, tangent, and binormal vectors for the terrain model. CalculateTerrainVectors(); // Initialize the vertex and index buffer for the terrain. result = InitializeBuffers(device); if(!result) { return false; } // Load the textures. result = LoadTextures(device, colorTextureFilename, normalMapFilename); if(!result) { return false; } return true; }
MapObject::MapObject(const char* filename,const char* heightmap_name, __INT32 _width, __INT32 _height, float scale, float scale_height, __INT32 detail):mVertices(NULL),mTextcoord(NULL),mIndices(NULL),mWidth(0),mHeight(0), mTextureID(0),mHeightMap(NULL),drawGrid(false),mIndices_grid(NULL),mGridColor(NULL),isPressed(false),scale(1),heightscale(1),selected(-1),mLogicMap(NULL),isDrag(false),MapCameraOffsetX(0),MapCameraOffsetY(0),detail_level(1),drawRange(false),boundarycolor(SColor<__UINT8>(255,255,255,255)),mCircleTextureID(0) { mType = OBJECT_MAP; LoadTextureMap(filename); LoadHeightMap(heightmap_name); skybox = new SkyBox(PATH_GRAPHIC("HellSide5.tga"),PATH_GRAPHIC("HellSide3.tga"),PATH_GRAPHIC("HellSide6.tga"),PATH_GRAPHIC("HellSide1.tga"),PATH_GRAPHIC("HellSide2.tga"),PATH_GRAPHIC("HellSide4.tga")); SetMapProperties(_width,_height,scale,scale_height,detail); //initialize for mapLogic SAFE_DEL_ARRAY(mLogicMap); mLogicMap = new __INT32[mWidth*mHeight]; for(int i = 0; i < mWidth*mHeight; i++) { mLogicMap[i] = OBJECT_NONE; } }
void MT_HeightMap::Init(const char *fileName) { bool sucessFlag; imageReader = new MT_BitmapReader(); sucessFlag = imageReader->Init(fileName); if(!sucessFlag) { MT_Logger::LogError("Unable to read image file : %s", fileName); } sucessFlag = LoadHeightMap(); if(!sucessFlag) { MT_Logger::LogError("Unable to load heightmap"); } // clean up image reader imageReader->Clean(); }
bool TerrainClass::Initialize(ID3D10Device* device, char* heightMapFilename, WCHAR* textureFilename) { bool result; // Load in the height map for the terrain. result = LoadHeightMap(heightMapFilename); if (!result) { return false; } // Normalize the height of the height map. NormalizeHeightMap(); // Calculate the normals for the terrain data. result = CalculateNormals(); if (!result) { return false; } // Calculate the texture coordinates. CalculateTextureCoordinates(); // Load the texture. result = LoadTexture(device, textureFilename); if (!result) { return false; } // Initialize the vertex array that will hold the geometry for the terrain. result = InitializeBuffers(device); if (!result) { return false; } return true; }
void LoadData( void ) { glDeleteLists( 1, NUM_LISTS ); if( glIsTexture( BASE_TEXTURE ) ) { GLuint textureNum = BASE_TEXTURE; glDeleteTextures( 1, &textureNum ); } if( glIsTexture( NORMAL_TEXTURE ) ) { GLuint textureNum = NORMAL_TEXTURE; glDeleteTextures( 1, &textureNum ); } LoadHeightMap( bumpTextureName ); glBindTexture( GL_TEXTURE_2D, BASE_TEXTURE ); LoadTexture( baseTextureName, false, 1.0f ); BuildNormalTexture(); BuildDisplayLists(); }
bool CTerrain::UpdateBuffers(ID3D11Device * device, ID3D11DeviceContext* deviceContext, double ** heightMap, int newWidth, int newHeight) { mUpdating = true; if (mpHeightMap) { ReleaseHeightMap(); } if (mpTerrainTiles != nullptr) { for (int i = 0; i < mHeight; ++i) { delete[] mpTerrainTiles[i]; logger->GetInstance().MemoryDeallocWriteLine(typeid(mpTerrainTiles[i]).name()); mpTerrainTiles[i] = nullptr; } delete[] mpTerrainTiles; mpTerrainTiles = nullptr; logger->GetInstance().MemoryDeallocWriteLine(typeid(mpTerrainTiles).name()); } mHeight = newHeight; mWidth = newWidth; // Load the new data into our member vars. LoadHeightMap(heightMap); if (mpVertexBuffer) { mpVertexBuffer->Release(); mpVertexBuffer = nullptr; } if (mpIndexBuffer) { mpIndexBuffer->Release(); mpIndexBuffer = nullptr; } if (mpWater != nullptr) { mpWater->Shutdown(); delete mpWater; mpWater = nullptr; mpWater = new CWater(); if (!mpWater->Initialise(device, D3DXVECTOR3(0.0f, 0.0f, 0.0f), D3DXVECTOR3(mWidth - 1.0f, 0.0f, mHeight - 1.0f), 200, 200, "Resources/Textures/WaterNormalHeight.png", mScreenWidth, mScreenHeight)) { logger->GetInstance().WriteLine("Failed to initialise the body of water."); return false; } } mTreesInfo.clear(); mPlantsInfo.clear(); InitialiseBuffers(device); mUpdating = false; return true; }