Hey,
I took a crack at converting some JAVA procedural method to c++. I’m getting the following compile error.
/media/home2/vivienne/testingc++/olsen2dwip.cpp||In member function ?int* OlsenNoise2D::olsennoise(int, int, int, int)?:|
/media/home2/vivienne/testingc++/olsen2dwip.cpp|79|error: no matching function for call to ?OlsenNoise2D::hashrandom(int, int, int&)?|
/media/home2/vivienne/testingc++/olsen2dwip.cpp|79|note: candidate is:|
/media/home2/vivienne/testingc++/olsen2dwip.cpp|17|note: int OlsenNoise2D::hashrandom(int*)|
/media/home2/vivienne/testingc++/olsen2dwip.cpp|17|note: candidate expects 1 argument, 3 provided|
/media/home2/vivienne/testingc++/olsen2dwip.cpp||In member function ?int OlsenNoise2D::hashrandom(int*)?:|
/media/home2/vivienne/testingc++/olsen2dwip.cpp|144|error: request for member ?size? in ?elements?, which is of non-class type ?int*?|
/media/home2/vivienne/testingc++/olsen2dwip.cpp|147|error: ?hash? cannot be used as a function|
||=== Build finished: 6 errors, 0 warnings ===|
The code is at PasteBin is pastebin.com/gh6P5zf3
[code]
int * OlsenNoise2D::olsennoise(int x, int y, int width, int height)
{
int maxiterations = 7;
int cx, cy;
int cxh, cyh;
int cwidth, cheight;
int xoff, yoff;
int nwidth, nheight;
int nx, ny;
int nxh, nyh;
int m=0;
int n=0;
int * field = NULL;
for (int iteration = 0; iteration < maxiterations; iteration++)
{
nx = x;
ny = y;
nxh = x + width;
nyh = y + width;
n = maxiterations - iteration;
for (int i = 1; i < n; i++)
{
nx = (nx / 2) - 1;
ny = (ny / 2) - 1;
nxh = 1 -(-nxh/2);
nyh = 1 -(-nyh/2);
}
xoff = -2*((nx/2)) + nx + 1;
yoff = -2*((ny/2)) + ny + 1;
cx = (nx / 2) - 1;
cy = (ny / 2) - 1;
cxh = 1 -(-nxh/2);
cyh = 1 -(-nyh/2);
nwidth = nxh - nx;
nheight = nyh - ny;
cwidth = cxh - cx;
cheight = cyh - cy;
/// Field
m=cwidth;
n=cheight;
if (field == NULL) field = new int[m*(n*m)];
for (int j = 0; j < m; j++)
{
for (int k = 0; k < n; k++)
{
field[j+(k*m)] += (hashrandom(cx + j, cy + k, iteration) & (1 << (7 - iteration)));
}
}
/// Up sampled
//m=field.length * 2;
//n=field[0].length * 2;
m=cwidth*2;
n=cheight*2;
int * upsampled = new int[m*(n*m)];
for (int j = 0; j < m; j++)
{
for (int k = 0; k < n; k++)
{
upsampled[j+(k*m)] = field[(j / 2)+((k / 2)*cwidth)];
}
}
field = upsampled;
/// Blur field
//int m=field.length - 2;
//int n=field[0].length - 2;
m=cwidth-2;
n=cheight-2;
int * blurfield = new int[m*(n*m)];
for (int j = 0; j < m; j++)
{
for (int k = 0; k < n; k++)
{
for (int h = 0; h < 9; h++)
{
blurfield[j+(k*m)] += field[(j + (h % 3))+((k + (h / 3))*(cheight*2))];
}
blurfield[j+(k*m)] /= 9;
}
}
field = blurfield;
/// Trim field
m=nwidth;
n=nheight;
int * trimfield = new int[m*(n*m)];
for (int j = 0;j < m; j++)
{
for (int k = 0; k < n; k++)
{
trimfield[j+(k*m)] = field[(j + xoff)+((k + yoff)*(nheight-2))];
}
}
field = trimfield;
}
return field;
}
int OlsenNoise2D::hashrandom(int elements[])
{
long hash = 0;
for (int i = 0; i < elements.size; i++)
{
hash ^= elements[i];
hash = hash(hash);
}
return (int) hash;
};
long OlsenNoise2D::hash(long v)
{
long hash = v;
long h = hash;
switch ((int) hash & 3)
{
case 3:
hash += h;
hash ^= hash << 32;
hash ^= h << 36;
hash += hash >> 22;
break;
case 2:
hash += h;
hash ^= hash << 22;
hash += hash >> 34;
break;
case 1:
hash += h;
hash ^= hash << 20;
hash += hash >> 2;
}
hash ^= hash << 6;
hash += hash >> 10;
hash ^= hash << 8;
hash += hash >> 34;
hash ^= hash << 50;
hash += hash >> 12;
return hash;
};
int main()
{
return 1;
}[/code]