The function that I know I need to change somehow is below.

It simply takes the min and max X/Z coordinates for the current square being subdivided (which index into an array of Y-Values where these min's and max's already have a Y value computed) and a displacement.

I'm pretty sure the step where I calculate a new midpoint is correct (setting E) but the part that I know is wrong is where I set the midpoint of each side (F G H I)

The forumla seems like it should work, but on high levels of recursion I see almost veritcal drops instead of a smoother transition:

An alternate approach I tried that -almost- worked was just doing:

yMap[xMin][zMidpnt] = (A + C ) / 2; // F
yMap[xMidpnt][zMin] = (A + B) / 2 ; // G
yMap[xMax][zMidpnt] = (B + D)/ 2; // H
yMap[xMidpnt][zMax] = (C + D) / 2 ; // I

Which produces a more better landscape but isn't really performing the square step of the algorithm correctly (I think) because it does not add any random displacement to these midpoints.

Any help on how to fix this would be appreciated.

void genLandscapeRec(int xMin, int xMax, int zMin, int zMax, float disp) {
float nDisp = (float)(disp * (float)pow(2, -(double)roughnes)); // New displacement
int xMidpnt = (xMin+xMax) / 2;
int zMidpnt = (zMin+zMax) / 2;
GLfloat A = yMap[xMin][zMin];
GLfloat B = yMap[xMax][zMin];
GLfloat C = yMap[xMin][zMax];
GLfloat D = yMap[xMax][zMax];
GLfloat E = (A + B + C + D) / 4 + randDisp(disp); // Midpoint height
yMap[xMidpnt][zMidpnt] = E; // Set E
yMap[xMin][zMidpnt] = (A + C + E) / 3 + randDisp(disp); // F
yMap[xMidpnt][zMin] = (A + B + E) / 3 + randDisp(disp); // G
yMap[xMax][zMidpnt] = (B + D + E) / 3 + randDisp(disp); // H
yMap[xMidpnt][zMax] = (C + D + E) / 3 + randDisp(disp); // I
if ((xMidpnt - xMin) > 1) { // Subdivide if new midpoint length will be > 1
genLandscapeRec(xMin, xMidpnt, zMin, zMidpnt, nDisp);
genLandscapeRec(xMidpnt, xMax, zMin, zMidpnt, nDisp);
genLandscapeRec(xMin, xMidpnt, zMidpnt, zMax, nDisp);
genLandscapeRec(xMidpnt, xMax, zMidpnt, zMax, nDisp);
}
}
float randDisp(float disp) {
return (((float)rand()) / ((float)RAND_MAX)) * (disp + (disp/3)) - disp/3;
}

Jaggedness was being caused by overwriting edge midpoints that had already been computed.
Solution would be to code snippet to something like:
if(!yMap[xMin][zMidpnt])
yMap[xMin][zMidpnt] =

randDisp works fine, its at the bottom of the code snippet, simply returns floats in the range of the parameter passed (with a preference on positive values).

Jaggedness was being caused by overwriting edge midpoints that had already been computed.

Solution would be to code snippet to something like:

if(!yMap[xMin][zMidpnt])
yMap[xMin][zMidpnt] = (A + C + E) / 3 + randDisp(disp); // F
if(!yMap[xMidpnt][zMin])
yMap[xMidpnt][zMin] = (A + B + E) / 3 + randDisp(disp); // G
if(!yMap[xMax][zMidpnt])
yMap[xMax][zMidpnt] = (B + D + E) / 3 + randDisp(disp); // H
if(!yMap[xMidpnt][zMax])
yMap[xMidpnt][zMax] = (C + D + E) / 3 + randDisp(disp); // I

Checking to see if midpoints had been previously set.

0

Featured Post

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain. A* is a particularly easy way to approach it. I’ll start with the algor…

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough. To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…