Hey guys, got an odd problem.
I am a class in which i am setting a value to m_size.
It all works fine, but when i leave the class, i look into
the class information and find out my values have been reset
to what they where prior to function execution.
m_size is set a private.
The code for the function is:
bool TerrainGeneration::LoadFractalFaultMap(int size, int min, int max, int iterations, float softenFilter)
{
int iterationNum;
int height;
int randX1, randX2, randZ1, randZ2;
int vecX1, vecX2;
int vecZ1, vecZ2;
int x, z, i;
double *tempImageBuffer;
//Sometimes this crappy compiler won't work on one, but the other
//Including them both so atleast it will work on one or the other.
m_size = size;
//For the love of all things holy seed your random
//Because seriously without this for some reason
//terrain will always generate EXACTLY the same???
srand ( (unsigned int)time ( NULL ) );
m_heightData.m_data = new double [m_size * m_size];
std::cout << m_heightData.m_data[0] << std::endl;
//Make it a float as we need greater precision
//Because of the equation later on
tempImageBuffer = new double [m_size * m_size];
if(m_heightData.m_data == NULL || tempImageBuffer == NULL)
{
printf("Error Allocating Memory,\n but since there is no exit here\n I will just go on and crash");
}
//Zero out the image buffer
for(i = 0; i < (m_size * m_size); i++)
{
tempImageBuffer = 0;
}
for(iterationNum = 0; iterationNum < iterations; iterationNum++)
{
//Calculate the linear height for this iteration
height= max - ((max - min) * iterationNum) / iterations;
//Choose random points on x and z
randX1 = rand() % m_size;
randZ1 = rand() % m_size;
//If they are the same spot
//Reposition them...
do
{
randX2= rand() % m_size;
randZ2= rand() % m_size;
} while( randX2 == randX1 || randZ2== randZ1 );
//Make Vectorzzzzzzzz
vecX1 = randX2 - randX1;
vecZ1 = randZ2 - randZ1;
//Run through X and Z values on the terrain
for(z = 0; z < m_size ; z++)
{
for(x = 0; x < m_size; x++)
{
//Move Vectors plz
vecX2 = x - randX1;
vecZ2 = z - randZ1;
//If the result is up
//That is greater than 0...go up plz
if((vecX2 * vecX1 - vecZ1 * vecZ2) > 0)
{
tempImageBuffer[(z * m_size ) + x] += (double)height;
}
}
}
//Errosion
FilterHeightField(tempImageBuffer, softenFilter);
}
//Normalise (set all points between 0 - 255)
TerrainNormalization(tempImageBuffer);
for(z = 0; z < m_size; z++)
{
for(x = 0; x < m_size; x++)
{
SetTrueHeight((double)tempImageBuffer[(z * m_size) + x], x, z);
}
}
//Empty out the junk in image buffer
delete[] tempImageBuffer;
printf("%d", m_size);
return true;
}
and i am calling it from this:
int main(int argc, char **argv)
{
TerrainGeneration *terrain2 = new TerrainGeneration;
// GLchar *VertexShaderSource, *FragmentShaderSource
terrain2->LoadFractalFaultMap(128, 0, 255, 10, 0.3);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutInitWindowPosition(100, 100);
glutCreateWindow("Aurora: Overload");
glutReshapeFunc(ReshapeFunc);
glutDisplayFunc(DisplayFunc);
glutIdleFunc(idleFunc);
glutKeyboardFunc(KeyboardFunc);
glewInit();
// OpenGL::InitialiseGL();
atexit(OnExit);
// initialise the glut keyboard callbacks.
// InitKeyboard();
glutMainLoop();
return 0;
}
Umm thanks for any help you can offer =(