Hello
I'm trying to scale the output of the diamond nose maker to values to 0.0f to 1.0f. From any pair of mininumY to maximumY. I was able to get it to partially work but stuck. I'm not sure how the final line should be to convert signed floats to a 0 to 1 range keeping the original scale.
bool Image::generateDiamondMethod1 (float * buffer,constint &width, constint &height, constfloat &maxYcoords,constfloat &minYcoords)
{
float maxY=2048;
float minY=-2048;
/// set range keeping scale
float NewMax = 1.0f;
float NewMin = 0.0f;
float NewRange = (NewMax - NewMin);
float lowfloat=0.0f;
float highfloat=0.0f;
(rest of code at end)
//Calculate minY and maxY values
for (int i = 0; i<DATA_SIZE-1; i++)
{
for(int j=0; j<DATA_SIZE-1; j++)
{
if (diamond[i][j] > maxY)
maxY = diamond[i][j];
if (diamond[i][j] < minY)
minY = diamond[i][j];
}
}
//print out the data
for(int x=0; x < DATA_SIZE-1; x++){
for(int y=0; y < DATA_SIZE-1; y++){
//populate the point struct
float floaty = diamond[x][y];
//change range to 0..1
diamond[x][y] = (floaty - minY) / (maxY - minY);
}
}
// Set range
float OldRange = (highfloat-lowfloat);
// loop through all the floats then convert to grayscale setting the color basis to .5 (forcing values 0 to 1)
for(unsigned x = 0; x<width; x++)
{
for(unsigned y = 0; y<height; y++)
{
/// incremennt memory which seems to work
int index = x+(y*width);
float value=diamond[x][y];
buffer[index]=value;
}
}