Shakenbake158

02-17-2015, 07:58 PM

Hey guys, I am attempting to make a fractal mountain using OpenGL and recursion.

I have already wrote the code to create the Sierpinski Gasket, and I figures it wouldn't be that big of a deal to modify, but it is proving to be more difficult than I anticipated.

Here is my recursive function

void divide_triangle(const vec4 &a, const vec4 &b, const vec4 &c, int count) {

double random = (rand() % 5 + 1) / 100;

if (count > 0) {

// Midpoints of sides

vec4 v0 = (a + b) / 2.0;

vec4 v1 = (a + c) / 2.0;

vec4 v2 = (b + c) / 2.0;

divide_triangle(v0, v1, v2, count - 1); // This is the line I added

in order to also divide the middle triangle

divide_triangle(b, v2, v0, count - 1);

divide_triangle(a, v0, v1, count - 1);

divide_triangle(c, v1, v2, count - 1);

}

else {

triangle(a, b, c); // Draw triangle at the end of recursion

}

}

Have you guys got any ideas? Thanks!

I have already wrote the code to create the Sierpinski Gasket, and I figures it wouldn't be that big of a deal to modify, but it is proving to be more difficult than I anticipated.

Here is my recursive function

void divide_triangle(const vec4 &a, const vec4 &b, const vec4 &c, int count) {

double random = (rand() % 5 + 1) / 100;

if (count > 0) {

// Midpoints of sides

vec4 v0 = (a + b) / 2.0;

vec4 v1 = (a + c) / 2.0;

vec4 v2 = (b + c) / 2.0;

divide_triangle(v0, v1, v2, count - 1); // This is the line I added

in order to also divide the middle triangle

divide_triangle(b, v2, v0, count - 1);

divide_triangle(a, v0, v1, count - 1);

divide_triangle(c, v1, v2, count - 1);

}

else {

triangle(a, b, c); // Draw triangle at the end of recursion

}

}

Have you guys got any ideas? Thanks!