Converting floats

Pages: 12
Hello

How do you convert a number float in a range of -10.0f to 17.0f to a eqivalent number in the range of 0.0f to 1.0f?

The code does not work well. floaty is the float to change.

//change range to 0..1
diamond[x][y] = (floaty - minY) / (maxY - minY);

Vivienne
If it's just a matter of scaling, you offset it, then scale it:

1
2
f += 10.0f; // offset from [-10,17] to [0,27]
f /= 27.0f; // scale from [0,27] to [0,1] 




The formula for converting 'Old' to 'New' would be:

1
2
3
4
5
6
7
8
9
New = ((Old - Old_minimum) * New_range / Old_range ) + New_minimum;

/* Where, for your example:

Old_minimum = -10
Old_range   = 27
New_minimum = 0
New_range   = 1
*/
Last edited on
f(x) = ax + b
f(min) = 0
f(max) = 1

a min + b = 0
a max + b = 1

a min = a max - 1
min = max - 1/a
min - max = - 1/a
max - min = 1/a
1/(max - min) = a

a min + b = 0
min / (max - min) + b = 0
b = -min / (max - min)

f(x) = x / (max - min) - min / (max - min)
f(x) = (x - min) / (max - min)

You must be doing something else wrong.
This is the complete code that's not working on the latter part.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
bool Image::generateDiamondMethod1 (float * buffer,const int &width, const int &height, const float &maxYcoords,const float &minYcoords)
{
    float maxY=2048;
    float minY=0;


    /// set range keeping scale
    float NewMax = 1.0f;
    float NewMin = 0.0f;
    float NewRange = (NewMax - NewMin);

    float lowfloat=1.0f;
    float highfloat=1.0f;


    //struct to hold values when writing to a file
    struct sPoint
    {
        float x, y, z;
    } point;


    unsigned int DATA_SIZE=width+1;
    //an initial seed value for the corners of the data
    double SEED = 0.0f;
    float diamond[DATA_SIZE][DATA_SIZE];

    //initialise the values of the corners++
    diamond[0][0] = SEED;
    diamond[0][DATA_SIZE-1] = SEED;
    diamond[DATA_SIZE-1][0] = SEED;
    diamond[DATA_SIZE-1][DATA_SIZE-1] = SEED;

    float h =300.0; 	//the range (-h -> h) for the average offset
    srand(513);		//seed the random generator


    //side length is the distance of a single square side
    //or distance of diagonal in diamond
    //each iteration we are looking at smaller squares and diamonds, we decrease the variation of the offset
    for (int sideLength = DATA_SIZE-1; sideLength >= 2; sideLength /= 2, h /= 2.0)
    {

        int halfSide = sideLength/2;

        //generate new square values
        for(int x=0; x<DATA_SIZE-1; x+=sideLength)
        {
            for(int y=0; y<DATA_SIZE-1; y+=sideLength)
            {

                //x,y is upper left corner of the square
                //calculate average of existing corners
                float avg = diamond[x][y] + 				//top left
                            diamond[x+sideLength][y]   +				//top right
                            diamond[x][y+sideLength]   + 				//lower left
                            diamond[x+sideLength][y+sideLength]; 	//lower right

                avg /= 4.0;

                //center is average plus random offset in the range (-h, h)
                float offset = (-h) + rand() * (h - (-h)) / RAND_MAX;
                diamond[x+halfSide][y+halfSide] = avg + offset;

            } //for y
        } // for x


        //Generate the diamond values
        //Since diamonds are staggered, we only move x by half side
        //NOTE: if the data shouldn't wrap the x < DATA_SIZE and y < DATA_SIZE
        for (int x=0; x<DATA_SIZE-1; x+=halfSide)
        {
            for (int y=(x+halfSide)%sideLength; y<DATA_SIZE-1; y+=sideLength)
            {

                //x,y is center of diamond
                //we must use mod and add DATA_SIZE for subtraction
                //so that we can wrap around the array to find the corners

                float avg =
                    diamond[(x-halfSide+DATA_SIZE)%DATA_SIZE][y] +	//left of center
                    diamond[(x+halfSide)%DATA_SIZE][y]				+	//right of center
                    diamond[x][(y+halfSide)%DATA_SIZE]				+	//below center
                    diamond[x][(y-halfSide+DATA_SIZE)%DATA_SIZE];	//above center

                avg /= 4.0;

                //new value = average plus random offset
                //calc random value in the range (-h,+h)
                float offset = (-h) + rand() * (h - (-h)) / RAND_MAX;
                avg = avg + offset;

                //update value for center of diamond
                diamond[x][y] = avg;

                //wrap values on the edges
                //remove this and adjust loop condition above
                //for non-wrapping values
                if (x == 0) diamond[DATA_SIZE-1][y] = avg;
                if (y == 0) diamond[x][DATA_SIZE-1] = avg;
            } //for y
        } //for x
    } //for sideLength

    //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);
        }

    }


    // 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);

            buffer[index]=diamond[x][y];
        }
    }


    return true;
}
Additional code that takes the input and create a RGB grayscale in memory below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/// generate perlin output
bool Image::GenerateBuild(float * buffer, unsigned *output)
{
    int width=width_;
    int height=height_;
    int components=components_;
    int depth=1;

    // 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*height);

            unsigned col = buffer[index]* 255;  /// create color value

            col = rgba32ToUInt(col,col,col, 255);

            output[index] = col;      /// set grayscale - rgba is not needed. it seems to be screwy with this type of code.
        }
    }

    return true;
}
1
2
    float maxY=2048;
    float minY=0;

By setting these values up front, you will never get a maxY that is smaller than 2048. To fix this, just add the following before line 107:
maxY = minY = diamond[0][0];
I think it has problem converting negative numbers(floats) and positive numbers(floats) produced from the algorithm.

http://tinypic.com/r/2kotwx/8

This is the code now

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
   maxY = minY = 0.0f;

    //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);
            diamond[x][y] = ((floaty - minY) * 1 / maxY-minY ) + 0;

        }

    }
Last edited on
maxY = minY = 0.0f;
Think about what happens if the max value in diamonds is negative. You will never update maxY because 0.0f is already greater than any value.

Similarly, what if the minimum value in diamonds is 10? You will never update minY because it is already smaller than any value.

That's why I suggested setting maxY and minY to diamonds[0][0]. By setting them to one of the values, you guarantee that the initial value of maxY won't be too large, or minY too small.
I would agree if that's the problem. I tried that fix and it did not work. I actually did the same thing with a Perlin noise function which works correctly. Looking at the photo it looks like it cycles repeatedly from 0 to 1, 0 to 1, 0 to 1. So, I'm thinking making it has to do with the main algorithm.

This is the current code still with no luck.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/// Cold to create noise through the Diamond method. Requires offset and better hash table to create random heightmaps but repeatable
bool Image::generateDiamondMethod1 (float * buffer,const int &width, const int &height, const float &maxYcoords,const float &minYcoords)
{
    //an initial seed value for the corners of the data
    float SEED = 0.0f;
    unsigned int DATA_SIZE=width+1;
    float diamond[DATA_SIZE][DATA_SIZE];

    //initialise the values of the corners++
    diamond[0][0] = SEED;
    diamond[0][DATA_SIZE-1] = SEED;
    diamond[DATA_SIZE-1][0] = SEED;
    diamond[DATA_SIZE-1][DATA_SIZE-1] = SEED;

    float h =100.0; 	//the range (-h -> h) for the average offset
    srand(513);		//seed the random generator

    //side length is the distance of a single square side
    //or distance of diagonal in diamond
    //each iteration we are looking at smaller squares and diamonds, we decrease the variation of the offset
    for (int sideLength = DATA_SIZE-1; sideLength >= 2; sideLength /= 2, h /= 2.0)
    {

        int halfSide = sideLength/2;

        //generate new square values
        for(int x=0; x<DATA_SIZE-1; x+=sideLength)
        {
            for(int y=0; y<DATA_SIZE-1; y+=sideLength)
            {

                //x,y is upper left corner of the square
                //calculate average of existing corners
                float avg = diamond[x][y] + 				//top left
                            diamond[x+sideLength][y]   +				//top right
                            diamond[x][y+sideLength]   + 				//lower left
                            diamond[x+sideLength][y+sideLength]; 	//lower right
                avg /= 4.0;

                //center is average plus random offset in the range (-h, h)
                float offset = (-h) + rand() * (h - (-h)) / RAND_MAX;
                diamond[x+halfSide][y+halfSide] = avg + offset;

            } //for y
        } // for x

        //Generate the diamond values
        //Since diamonds are staggered, we only move x by half side
        //NOTE: if the data shouldn't wrap the x < DATA_SIZE and y < DATA_SIZE
        for (int x=0; x<DATA_SIZE-1; x+=halfSide)
        {
            for (int y=(x+halfSide)%sideLength; y<DATA_SIZE-1; y+=sideLength)
            {

                //x,y is center of diamond
                //we must use mod and add DATA_SIZE for subtraction
                //so that we can wrap around the array to find the corners

                float avg =
                    diamond[(x-halfSide+DATA_SIZE)%DATA_SIZE][y] +	//left of center
                    diamond[(x+halfSide)%DATA_SIZE][y]				+	//right of center
                    diamond[x][(y+halfSide)%DATA_SIZE]				+	//below center
                    diamond[x][(y-halfSide+DATA_SIZE)%DATA_SIZE];	//above center

                avg /= 4.0;

                //new value = average plus random offset
                //calc random value in the range (-h,+h)
                float offset = (-h) + rand() * (h - (-h)) / RAND_MAX;
                avg = avg + offset;

                //update value for center of diamond
                diamond[x][y] = avg;

                //wrap values on the edges
                //remove this and adjust loop condition above
                //for non-wrapping values
                if (x == 0) diamond[DATA_SIZE-1][y] = avg;
                if (y == 0) diamond[x][DATA_SIZE-1] = avg;
            } //for y
        } //for x
    } //for sideLength

    /// Set maxY and minY to 0.0f
    float maxY = diamond[1][1];
    float minY = diamond[1][1];

    /// Calculate minY and maxY values
    for (int x = 0; x<DATA_SIZE-1; x++)
    {
        for(int y=0; y<DATA_SIZE-1; y++)
        {
            if (diamond[x][y] > maxY)
                maxY = diamond[x][y];
            if (diamond[x][y] < minY)
                minY = diamond[x][y];
        }
    }

    /// Calculate height from 0 to 1
    for(int x=0; x < DATA_SIZE-1; x++)
    {
        for(int y=0; y < DATA_SIZE-1; y++)
        {
            //change range to 0..1
            diamond[x][y] = (diamond[x][y] - minY) / (maxY - minY);
        }

    }

    /// Copy color float from create texture
    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);

            buffer[index]=diamond[x][y];
        }
    }

    return true;
}
Can the problem be with this code. When I change the offset to be 0. to float offset=0.1;

I get.

http://tinypic.com/r/20r4did/8

1
2
3
4
5
6
7
8
9
10
        //x,y is upper left corner of the square
                //calculate average of existing corners
                float avg = diamond[x][y] + 				//top left
                            diamond[x+sideLength][y]   +				//top right
                            diamond[x][y+sideLength]   + 				//lower left
                            diamond[x+sideLength][y+sideLength]; 	//lower right
                avg /= 4.0;

                //center is average plus random offset in the range (-h, h)
                float offset = (-h) + rand() * (h - (-h))  / RAND_MAX;
Last edited on
In that code, I think you need to change x+sideLength to (x+sideLength)%DATA_SIZE, and change y+sideLength to (y+sideLength)%DATA_SIZE.

And are you sure your loop bounds are correct? Diamond is defined with DATA_SIZE items in each index, but some of your loops (e.g.. line 89) are:

for (int x = 0; x<DATA_SIZE-1; x++)

The largest value of x in this loop will be DATA_SIZE-2, which is one less than the largest index. This should be:
for (int x = 0; x<DATA_SIZE; x++)

dhayden,

I looked and modified the code as such . It is partially fixed. Here is a link of the produced image so I am trying to figure out the rest of the problem.

Main Picture
http://tinypic.com/r/23ser1s/8

Troubled area after I inverted in a paint program (If that helps)
http://tinypic.com/r/2irlxsz/8

code segment
1
2
3
4
5
6
7
8
  //calculate average of existing corners
                float avg = diamond[x][y] + 				//top left
                            diamond[(x+sideLength)%DATA_SIZE][y]   +				//top right
                            diamond[x][ (y+sideLength)%DATA_SIZE]   + 				//lower left
                            diamond[(x+sideLength)%DATA_SIZE][(y+sideLength)%DATA_SIZE]; 	//lower right

                avg /= 4.0;
code segment
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
   for (int x = 0; x<DATA_SIZE;x++)
    {
        for(int y=0; y<DATA_SIZE; y++)
        {
            if (diamond[x][y] > maxY)
                maxY = diamond[x][y];
            if (diamond[x][y] < minY)
                minY = diamond[x][y];
        }
    }

    /// Calculate height from 0 to 1
    for(int x=0; x < DATA_SIZE; x++)
    {
        for(int y=0; y < DATA_SIZE; y++)
        {
            //change range to 0..1
            diamond[x][y] = (diamond[x][y] - minY) / (maxY - minY);
        }

    }
Last edited on
This code produces this output

Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
   cout << "\r\nlocation1 "<< diamond[305][742];
    cout << "\r\nlocation2 " <<diamond[288][732];

    /// Set maxY and minY to 0.0f
    float maxY = diamond[1][1];
    float minY = diamond[1][1];

    for (int x = 0; x<DATA_SIZE;x++)
    {
        for(int y=0; y<DATA_SIZE; y++)
        {
            if (diamond[x][y] > maxY)
                maxY = diamond[x][y];
            if (diamond[x][y] < minY)
                minY = diamond[x][y];
        }
    }

    cout << "\r\nminY"<< minY;
    cout << "\r\nmaxY"<< maxY;


Output - Command Line (Debug)
1
2
3
4
location1 -24.0164
location2 -13.1731
minY-21.6058
maxY186.181

The for loop is not catching the minY and maxY!!!

What is 'DATA_SIZE'? Is it less than 743?
I bet DATA_SIZE is less than 743. That would cause location1 to be set from outside the array.
DATA_SIZE is unsigned int DATA_SIZE=width+1;

In the case of the code width is 1024 so datasize is 1025.

The two locations are the points one in the good area (location2) and point b is the bad area (location1).

Oddly. The loop do not make that number the new mininumY or minY although it's clearly less then -21.6058
Last edited on
In the case of the code width is 1024 so datasize is 1025.


I'm skeptical. Did you try printing it along with minY/maxY?


EDIT:

How big is this program? Could you upload the full source somewhere so I can debug what's going on?
Last edited on
I added more information.

Numbers
Data Size 1025
Image Size 1024x1024
Location1 -24.0164
Location2 -13.1731
MinimumY 0.0260689
MaximumY 0.0260689
(Loop to find highest and new minimum)
MinimumY -21.6058
MaximumY 186.181

The source is at https://sourceforge.net/projects/proteusgameengine/files/Existence/Source/Engine/Resources/

I'm integrating it into a game engine. So it could probably be stripped out.


1
2
/// Cold to create noise through the Diamond method. Requires offset and better hash table to create random heightmaps but repeatable
bool Image::generateDiamondMethod1 (float * buffer,const int &width, const int &height, const float &maxYcoords,const float &minYcoords)
> I get.
> http://tinypic.com/r/20r4did/8
¿how is that image wrong?
¿couldn't you test with something simpler, like a gradient?


> The source is at https://sourceforge.net/projects/proteusgameengine/files/Existence/Source/Engine/Resources/
1
2
3
4
5
6
7
#include "Precompiled.h"
#include "Context.h"
#include "Decompress.h"
#include "File.h"
#include "FileSystem.h"
#include "Log.h"
#include "Profiler.h" 
¿where are those?



> I'm integrating it into a game engine. So it could probably be stripped out.
go ahead
I stripped out the function in question and made changes so that it would actually compile (you're doing some non-standard stuff) and so it wouldn't cause a stack overflow.

Here is the exact code I ran:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <vector>
#include <iostream>
#include <cstdlib>
using namespace std;


bool generateDiamondMethod1 (const int &height)
{
    static const int width = 1024;
    //an initial seed value for the corners of the data
    float SEED = 0.0f;
    static const unsigned int DATA_SIZE=width+1;
    std::vector< std::vector<float> > diamond( DATA_SIZE, std::vector<float>(DATA_SIZE) );
    //float diamond[DATA_SIZE][DATA_SIZE];

    //initialise the values of the corners++
    diamond[0][0] = SEED;
    diamond[0][DATA_SIZE-1] = SEED;
    diamond[DATA_SIZE-1][0] = SEED;
    diamond[DATA_SIZE-1][DATA_SIZE-1] = SEED;

    float h =200; 	//the range (-h -> h) for the average offset
    srand(512);		//seed the random generator

    //side length is the distance of a single square side
    //or distance of diagonal in diamond
    //each iteration we are looking at smaller squares and diamonds, we decrease the variation of the offset
    for (int sideLength = DATA_SIZE-1; sideLength >= 2; sideLength /= 2, h /= 2.0)
    {

        int halfSide = sideLength/2;

        //generate new square values
        for(int x=0; x<DATA_SIZE-1; x+=sideLength)
        {
            for(int y=0; y<DATA_SIZE-1; y+=sideLength)
            {

                //x,y is upper left corner of the square
                //calculate average of existing corners
                float avg = diamond[x][y] + 				//top left
                            diamond[(x+sideLength)%DATA_SIZE][y]   +				//top right
                            diamond[x][ (y+sideLength)%DATA_SIZE]   + 				//lower left
                            diamond[(x+sideLength)%DATA_SIZE][(y+sideLength)%DATA_SIZE]; 	//lower right

                avg /= 4.0;

                //center is average plus random offset in the range (-h, h)
                float offset = (-h) + (float)rand() * (h - (-h))  / RAND_MAX;

                diamond[x+halfSide][y+halfSide] = avg + offset;

            } //for y
        } // for x

        //Generate the diamond values
        //Since diamonds are staggered, we only move x by half side
        //NOTE: if the data shouldn't wrap the x < DATA_SIZE and y < DATA_SIZE
        for (int x=0; x<DATA_SIZE-1; x+=halfSide)
        {
            for (int y=(x+halfSide)%sideLength; y<DATA_SIZE-1; y+=sideLength)
            {

                //x,y is center of diamond
                //we must use mod and add DATA_SIZE for subtraction
                //so that we can wrap around the array to find the corners

                float avg =
                    diamond[(x-halfSide+DATA_SIZE)%DATA_SIZE][y] +	//left of center
                    diamond[(x+halfSide)%DATA_SIZE][y]				+	//right of center
                    diamond[x][(y+halfSide)%DATA_SIZE]				+	//below center
                    diamond[x][(y-halfSide+DATA_SIZE)%DATA_SIZE];	//above center

                avg /= 4.0;

                //new value = average plus random offset
                //calc random value in the range (-h,+h)
                float offset = (-h) + (float)rand() * (h - (-h))  / RAND_MAX;

                avg = avg + offset;

                //update value for center of diamond
                diamond[x][y] = avg;

                //wrap values on the edges
                //remove this and adjust loop condition above
                //for non-wrapping values
                if (x == 0) diamond[DATA_SIZE-1][y] = avg;
                if (y == 0) diamond[x][DATA_SIZE-1] = avg;
            } //for y
        } //for x
    } //for sideLength


    cout << "\r\nData Size " << DATA_SIZE;
    cout << "\r\nImage Size " << width << "x" << width;
    cout << "\r\nLocation1 "<< diamond[305][742];
    cout << "\r\nLocation2 " <<diamond[288][732];

    /// Set maxY and minY to 0.0f
    float maxY = diamond[1][1];
    float minY = diamond[1][1];

    cout << "\r\nMinimumY " << minY;
    cout << "\r\nMaximumY " << maxY;

    cout << "(Loop to find highest and new minimum)";

    for (int x = 0; x<DATA_SIZE; x++)
    {
        for(int y = 0; y<DATA_SIZE; y++)
        {
            if ((float)diamond[x][y] > maxY)
            {
                maxY = diamond[x][y];
            }
            if ((float)diamond[x][y] < minY)
            {
                minY = diamond[x][y];
            }
        }
    }

    cout << "\r\nMinimumY " << minY;
    cout << "\r\nMaximumY " << maxY << "\r\n";

    /// Calculate height from 0 to 1
    for(int x=0; x < DATA_SIZE; x++)
    {
        for(int y=0; y < DATA_SIZE; y++)
        {
            //change range to 0..1
            diamond[x][y] = (diamond[x][y] - minY) / (maxY - minY);
        }

    }

    /// Copy color float from create texture
    for(unsigned y = 0; y<width; y++)
    {
        for(unsigned x = 0; x<height; x++)
        {
            /// incremennt memory which seems to work
            int index = (y*width)+x;

            //buffer[index]=diamond[x][y];
        }
    }

    return true;
}

int main()
{
    generateDiamondMethod1(1024);
}


And my output:


Data Size 1025
Image Size 1024x1024
Location1 -66.9458
Location2 -67.7313
MinimumY -1.03156
MaximumY -1.03156(Loop to find highest and new minimum)
MinimumY -179.125
MaximumY 65.8693



So it seems to be working for me.

Can you show me how to reproduce the problem?


EDIT:

I get identical output on GCC as well as MSVS 2012 (though I had to add #include <cstdlib>)

EDIT2:

IDEOne gives me different output, but still "functional" output:

http://ideone.com/PEe7Qn

Data Size 1025
Image Size 1024x1024
Location1 -24.0164
Location2 -13.1731
MinimumY 0.0260689
MaximumY 0.0260689(Loop to find highest and new minimum)
MinimumY -59.9904
MaximumY 194.645
Last edited on
Pages: 12