Hello all, I am kinda new in this community, but i work since one year on lwjgl to get this kind of thing. I actually first thaught about a “cube generated sphere” but I found out you can get a way better one using a golden rectangle based icosahedron. I actually started making a seed based random geography subdivision system, that uses a formula that subdivides each seed each time to get a new one. I got this (yes, i messed the vertex coloring…

and there is a code: (feel free to use it as you want since this is basic math)
[java]
public static void drawgeodesic( Color col, float r, Position p,float sub, long se){
float L = (float) Math.cos(Util.getGoldenAngle())r2;
float H = (float) Math.sin(Util.getGoldenAngle())r2;
float L2 = L/2;
float H2 = H/2;
//Point a1 = new Point(pos.x+L2,pos.y+H2,pos.z,1,1,1,1);
Random ran = new Random(se);
point a1 = new point(pos.x+L2,pos.y+H2,pos.z, col.red, col.green-20, col.blue, col.alpha);
point a2 = new point(pos.x-L2,pos.y+H2,pos.z, col.red, col.green, col.blue, col.alpha);
point a3 = new point(pos.x-L2,pos.y-H2,pos.z, col.red, col.green, col.blue, col.alpha);
point a4 = new point(pos.x+L2,pos.y-H2,pos.z, col.red, col.green, col.blue, col.alpha);
point b1 = new point(pos.x+H2,pos.y,pos.z+L2, col.red, col.green, col.blue, col.alpha);
point b2 = new point(pos.x+H2,pos.y,pos.z-L2, col.red, col.green, col.blue, col.alpha);
point b3 = new point(pos.x-H2,pos.y,pos.z-L2, col.red, col.green, col.blue, col.alpha);
point b4 = new point(pos.x-H2,pos.y,pos.z+L2, col.red, col.green, col.blue, col.alpha);
point c1 = new point(pos.x,pos.y+L2,pos.z+H2, col.red, col.green, col.blue, col.alpha);
point c2 = new point(pos.x,pos.y-L2,pos.z+H2, col.red, col.green, col.blue, col.alpha);
point c3 = new point(pos.x,pos.y-L2,pos.z-H2, col.red, col.green, col.blue, col.alpha);
point c4 = new point(pos.x,pos.y+L2,pos.z-H2, col.red, col.green, col.blue, col.alpha);
long ra = ran.nextLong();
subdiv.draw(a1, b1, c1, sub , p,r, se*ra*100);
subdiv.draw(a1, b1, b2, sub , p,r, se*ra*100);
subdiv.draw(a1, a2, c1, sub , p,r, se*ra*100);
subdiv.draw(a1, a2, c4, sub , p,r, se*ra*100);
subdiv.draw(a1, b2, c4, sub , p,r, se*ra*100);
subdiv.draw(a2, c1, b4, sub , p,r, se*ra*100);
subdiv.draw(a2, c4, b3, sub , p,r, se*ra*100);
subdiv.draw(a2, b4, b3, sub , p,r, se*ra*100);
subdiv.draw(a3, b4, b3, sub , p,r, se*ra*100);
subdiv.draw(a3, c3, b3, sub , p,r, se*ra*100);
subdiv.draw(a3, c2, b4, sub , p,r, se*ra*100);
subdiv.draw(a3, c3, a4, sub , p,r, se*ra*100);
subdiv.draw(a3, c2, a4, sub , p,r, se*ra*100);
subdiv.draw(a4, b1, b2, sub , p,r, se*ra*100);
subdiv.draw(a4, b2, c3, sub , p,r, se*ra*100);
subdiv.draw(a4, c2, b1, sub , p,r, se*ra*100);
subdiv.draw(b1, c1, c2, sub , p,r, se*ra*100);
subdiv.draw(b2, c3, c4, sub , p,r, se*ra*100);
subdiv.draw(b4, c1, c2, sub , p,r, se*ra*100);
subdiv.draw(b3, c4, c3, sub , p,r, se*ra*100);
}
public static void draw(point a,point b,point c, float s, Position p,float r, long se){
sub2(a, b, c, s, p,r, se);
}
public static void sub(point a,point b,point c, float s, Position p,float r){
point d = Util.getmiddlesphere(a, b, p, r);
point e = Util.getmiddlesphere(b, c, p, r);
point f = Util.getmiddlesphere(c, a, p, r);
if(s-1>0){
sub(f, e, d, s-1,p,r);
sub(a, d, f, s-1,p,r);
sub(b, e, d, s-1,p,r);
sub(c, e, f, s-1,p,r);
}else{
Line.draw(d, f);
Line.draw(f, e);
Line.draw(e, d);
Line.draw(c, f);
Line.draw(b, e);
Line.draw(c, e);
Line.draw(a, d);
Line.draw(b, d);
Line.draw(a, f);
}
}
public static void sub2(point a,point b,point c, float s, Position p,float r, long se){
Random ran = new Random(se);
point g=Util.getmiddle(a, b);
point h=Util.getmiddle(b, c);
point i=Util.getmiddle(c, a);
Long ra = ran.nextLong();
Long ar = ran.nextLong();
point d = Util.getmiddleirregularsphere(a, b, p, r, (long) (ra+(g.x+g.y+g.z)*100));
point e = Util.getmiddleirregularsphere(b, c, p, r, (long) (ra+(h.x+h.y+h.z)*100));
point f = Util.getmiddleirregularsphere(c, a, p, r, (long) (ra+(i.x+i.y+i.z)*100));
if(s-1>0){
sub2(f, e, d, s-1,p,r,ar*100);
sub2(a, d, f, s-1,p,r,ar*100);
sub2(b, e, d, s-1,p,r,ar*100);
sub2(c, e, f, s-1,p,r,ar*100);
}else{
Line.draw(d, f);
Line.draw(f, e);
Line.draw(e, d);
Line.draw(c, f);
Line.draw(b, e);
Line.draw(c, e);
Line.draw(a, d);
Line.draw(b, d);
Line.draw(a, f);
}
}
public static float getGoldenAngle(){
final float a = (float) Math.atan(1.5/Math.cos(Math.PI/8));
return a;
}
public static float getGoldenAngle2(){
final float a = (float) ((Math.PI-2*(Math.PI/2-getGoldenAngle()))/2);
return a;
}[/java]
and to load it use this method:
[java]IcoSphere.drawgeodesic(new Color(0, 1, 1, 1f), 2,new Position(0, 0, 0),0,252);[/java]
btw, the thing is to get each side of the triangle to be the same as the other, and that’s a bit complicated but possible. after there is a way to do mountain like things with a sedd and seeded formula besed sinus and cosinus plane to wrap arround the sphere (180 high an d 360 large and the top side must be the same and the bottom side also and the 2 on each side also.
I will try to get that to work on my brand new started Jmonkey project.
Hope I helped you.
PS: I think icosahedron based is the most efficient since every geometry in java is triangle based and so it gives a way more smooth rendering.
PPS: for textures you might want to make it terrain variation / center based so you get stone textures on the side, sand on the beach and other cool stuff.
PPPS: what you already did is awesome!