Jump to content
  • Advertisement
Sign in to follow this  
Juliean

Dynamic cloud rendering

This topic is 2606 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Thanks, now it makes sense. I thought hum, act and cld were floats..

However my implentation isn't working as expected.

#include "Cloud.h"


CCloud::CCloud(void)
{
}


CCloud::~CCloud(void)
{
for(int i = 0; i<m_SizeX;i++)
{
for(int j = 0;j<m_SizeY;j++)
{
delete[] m_Cells[j];
}
delete[] m_Cells;
}
delete[] m_Cells;
}

void CCloud::Init(int SizeX, int SizeY, int SizeZ)
{
m_SizeX = SizeX;
m_SizeY = SizeY;
m_SizeZ = SizeZ;
m_Cells = new CloudCell**[SizeX];
for(int i = 0; i<SizeX;i++)
{
m_Cells = new CloudCell*[SizeY];
for(int j = 0;j<SizeY;j++)
{
m_Cells[j] = new CloudCell[SizeZ];
}
}
}

void CCloud::Setup(float pEx, float pAct, float pHum)
{
m_pEx = pEx;
m_pAct = pAct;
m_pHum = pHum;
for(int i = 0; i<m_SizeX;i++)
{
for(int j = 0;j<m_SizeY;j++)
{
for(int k = 0;k<m_SizeZ;k++)
{
m_Cells[j][k].act = rand()/RAND_MAX;
m_Cells[j][k].cld = rand()/RAND_MAX;
m_Cells[j][k].hum = rand()/RAND_MAX;
}
}
}
}

void CCloud::Update(void)
{
CloudCell* Cell;
for(int i = 0; i<m_SizeX;i++)
{
for(int j = 0;j<m_SizeY;j++)
{
for(int k = 0;k<m_SizeZ;k++)
{
Cell = &m_Cells[j][k];
Cell->hum = Cell->hum&(!Cell->act);
Cell->cld = Cell->cld|(!Cell->act);
Cell->act = !Cell->act&Cell->hum&GetAct(i, j, k);
}
}
}

vector<vector<vector<CloudCell>>> Cells;
Cells.resize(m_SizeX);
for(int i = 0; i<m_SizeX;i++)
{
Cells.resize(m_SizeY);
for(int j = 0;j<m_SizeY;j++)
{
Cells[j].resize(m_SizeZ);
for(int k = 0;k<m_SizeZ;k++)
{
Cell = &m_Cells[j][k];
Cell->cld = Cell->cld & (rand()/RAND_MAX>m_pEx);
Cell->hum = Cell->hum | (rand()/RAND_MAX>m_pHum);
Cell->act = Cell->act | (rand()/RAND_MAX>m_pAct);
Cells[j][k] = *Cell;
}
}
}

}

bool CCloud::GetAct(int X, int Y, int Z)
{
m_SizeX -=1;
m_SizeY -=1;
m_SizeZ -=1;
bool Act = m_Cells[min(X+1,m_SizeX)][Y][Z].act | m_Cells[X][min(Y+1,m_SizeY)][Z].act | m_Cells[X][Y][min(Z+1,m_SizeZ)].act | m_Cells[max(X-1,0)][Y][Z].act |
m_Cells[X][max(Y-1,0)][Z].act | m_Cells[X][Y][max(Z-1,0)].act | m_Cells[max(X-2,0)][Y][Z].act | m_Cells[min(X+2,m_SizeX)][Y][Z].act | m_Cells[X][max(Y-2,0)][Z].act |
m_Cells[X][min(Y+2,m_SizeY)][Z].act | m_Cells[X][Y][max(Z-2,0)].act;
m_SizeX +=1;
m_SizeY +=1;
m_SizeZ +=1;
return Act;
}


Is there anything obviously wrong with the code? Or something I misunderstood? Because after having called Update(), all cells in the temporary 3d vector are having the same 3 variables: hum = false, cld = false, act = false. Some ideas?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!