Note that there are some explanatory texts on larger screens.

plurals
  1. POParticle Deposition Terrain Generation
    primarykey
    data
    text
    <p>I'm using Particle Deposition to try and create some volcano-like mountains procedurally but all I'm getting out of it is pyramid-like structures. Is anyone familiar with the algorithm that might be able to shed some light on what I might be doing wrong. I'm dropping each particle in the same place at the moment. If I don't they spread out in a very thin layer rather than any sort of mountain. </p> <pre><code>void TerrainClass::ParticalDeposition(int loops){ float height = 0.0; //for(int k= 0; k &lt;10; k++){ int dropX = mCurrentX = rand()%(m_terrainWidth-80) + 40; int dropY = mCurrentZ = rand()%(m_terrainHeight-80) + 40; int radius = 15; float angle = 0; int tempthing = 0; loops = 360; for(int i = 0; i &lt; loops; i++){ mCurrentX = dropX + radius * cos(angle); mCurrentZ = dropY + radius * sin(angle); /*f(i%loops/5 == 0){ dropX -= radius * cos(angle); dropY += radius * sin(angle); angle+= 0.005; mCurrentX = dropX; mCurrentZ = dropY; }*/ angle += 360/loops; //dropX += rand()%5; //dropY += rand()%5; //for(int j = 0; j &lt; loops; j++){ float newY = 0; newY = (1 - (2.0f/loops)*i); if(newY &lt; 0.0f){ newY = 0.0f; } DepositParticle(newY); //} } //} } void TerrainClass::DepositParticle(float heightIncrease){ bool posFound = false; m_lowerList.clear(); while(posFound == false){ int offset = 10; int jitter; if(Stable(0.5f)){ m_heightMap[(m_terrainHeight*mCurrentZ)+mCurrentX].y += heightIncrease; posFound = true; }else{ if(!m_lowerList.empty()){ int element = rand()%m_lowerList.size(); int lowerIndex = m_lowerList.at(element); MoveTo(lowerIndex); } } } } bool TerrainClass::Stable(float deltaHeight){ int index[9]; float height[9]; index[0] = ((m_terrainHeight*mCurrentZ)+mCurrentX); //the current index index[1] = ValidIndex((m_terrainHeight*mCurrentZ)+mCurrentX+1) ? (m_terrainHeight*mCurrentZ)+mCurrentX+1 : -1; // if the index to the right is valid index set index[] to index else set index[] to -1 index[2] = ValidIndex((m_terrainHeight*mCurrentZ)+mCurrentX-1) ? (m_terrainHeight*mCurrentZ)+mCurrentX-1 : -1; //to the left index[3] = ValidIndex((m_terrainHeight*(mCurrentZ+1))+mCurrentX) ? (m_terrainHeight*(mCurrentZ+1))+mCurrentX : -1; // above index[4] = ValidIndex((m_terrainHeight*(mCurrentZ-1))+mCurrentX) ? (m_terrainHeight*(mCurrentZ-1))+mCurrentX : -1; // bellow index[5] = ValidIndex((m_terrainHeight*(mCurrentZ+1))+mCurrentX+1) ? (m_terrainHeight*(mCurrentZ+1))+mCurrentX+1: -1; // above to the right index[6] = ValidIndex((m_terrainHeight*(mCurrentZ-1))+mCurrentX+1) ? (m_terrainHeight*(mCurrentZ-1))+mCurrentX+1: -1; // below to the right index[7] = ValidIndex((m_terrainHeight*(mCurrentZ+1))+mCurrentX-1) ? (m_terrainHeight*(mCurrentZ+1))+mCurrentX-1: -1; // above to the left index[8] = ValidIndex((m_terrainHeight*(mCurrentZ-1))+mCurrentX-1) ? (m_terrainHeight*(mCurrentZ-1))+mCurrentX-1: -1; // above to the right for ( int i = 0; i &lt; 9; i++){ height[i] = (index[i] != -1) ? m_heightMap[index[i]].y : -1; } m_lowerList.clear(); for(int i = 1; i &lt; 9; i++){ if(height[i] != -1){ if(height[i] &lt; height[0] - deltaHeight){ m_lowerList.push_back(index[i]); } } } return m_lowerList.empty(); } bool TerrainClass::ValidIndex(int index){ return (index &gt; 0 &amp;&amp; index &lt; m_terrainWidth*m_terrainHeight) ? true : false; } void TerrainClass::MoveTo(int index){ mCurrentX = index%m_terrainWidth; mCurrentZ = index/m_terrainHeight; } </code></pre> <p>Thats all the code thats used. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload