void terrain::setTerrainSize(btVector3 size) { if(size == m_terrainSize) return; btVector3 modscale = (size - m_terrainSize) / m_terrainSize; // the difference between the new and old size divided by the old size if(m_terrainSize.z() == 0) modscale.setZ(size.z()); // incase of NAN m_terrainMinHeight = m_terrainMaxHeight = 0; for(int i=0; i<m_terrainVertexCount; i++){ m_terrainVerts[i].x += modscale.x() * m_terrainVerts[i].x; m_terrainVerts[i].y += modscale.y() * m_terrainVerts[i].y; if(m_terrainSize.z() == 0) m_terrainVerts[i].z = size.z(); else m_terrainVerts[i].z += modscale.z() * m_terrainVerts[i].z; if(m_terrainVerts[i].z > m_terrainMaxHeight) m_terrainMaxHeight = m_terrainVerts[i].z; else if(m_terrainVerts[i].z < m_terrainMinHeight) m_terrainMinHeight = m_terrainVerts[i].z; } buildNormals(); m_terrainSize = size; tTool->setSize(m_terrainSize); m_parent->printText(QString("Terrain Resized %1,%2,%3").arg(m_terrainSize.x()).arg(m_terrainSize.y()).arg(m_terrainSize.z())); this->terrainRefresh(); emit newTerrain(); }
///////////////////////////////////////// // Terrain file slots ///////////// void terrain::openTerrain(QString filename) { if(filename == NULL){ // open an Open File dialog to look for a PNG image to represent a height map filename = QFileDialog::getOpenFileName(m_parent,tr("Open Terrain"), tr("/Users"),tr("Image File (*.png)")); if(filename == NULL) return; // if cancel is pressed dont do anything } QFileInfo terrainInfo(filename); this->terrainClear(); m_terrainFilename = filename; m_terrainSize = tTool->getSize(); // set the terrain size, loading a file will overwrite it if(filename != NULL && filename != "NULL" && terrainLoadFile()) // image data is good create terrain { m_terrainShortname = terrainInfo.baseName(); this->generateGround(); } else { // no image file, create flat terrain m_terrainShortname = "NULL"; m_terrainFilename = "NULL"; this->terrainCreateMesh(NULL); this->generateGround(); } m_parent->printText("Terrain Loaded: " + terrainInfo.baseName()); m_terrainModified = false; emit newTerrain(); }
AS3_Val initializeTerrain( void * self, AS3_Val args ) { Entity * entity; Material * material; Texture * texture; Bitmap * map; double width, height, maxHeight; int addressMode; DWORD render_mode; Terrain* terrain; AS3_ArrayValue( args, "PtrType, PtrType, PtrType, PtrType, DoubleType, DoubleType, DoubleType, IntType, IntType", & entity, & map, & material, & texture, & width, & height, & maxHeight, & render_mode, & addressMode ); terrain = newTerrain( entity, map, ( float )width, ( float )height, ( float )maxHeight, material, texture, render_mode, addressMode ); return AS3_Ptr(terrain); }
void terrain::flattenTerrain() { this->terrainClear(); this->openTerrain("NULL"); emit newTerrain(); }