I’m doing a planet generation program.
My code:
import peasy.*;
PVector resolution = new PVector(200,200);
PVector[][] basicGlobe = new PVector[round(resolution.x) + 1][round(resolution.y) + 1];
float radius = 400;
PVector[][] lithosphere = new PVector[round(resolution.x) + 1][round(resolution.y) + 1];
int lithoSeed;
PeasyCam camera;
void setup(){
size(600,600,P3D);
camera = new PeasyCam(this,0,0,0,600);
lithoSeed = round(random(-2147483647,2147483647));
}
void draw(){
for(int i = 0;i < resolution.x + 1;i++){
float latitude = map(i,0,resolution.x,0,TAU);
for(int j = 0;j < resolution.y + 1;j++){
float longitude = map(j,0,resolution.y,0,PI);
float x = cos(latitude) * cos(longitude);
float y = sin(latitude);
float z = cos(latitude) * sin(longitude);
basicGlobe[i][j] = new PVector(x,y,z);
}
}
background(0);
noStroke();
fill(127);
pointLight(255,255,255,-1000,0,0);
beginShape(TRIANGLE_STRIP);
noiseSeed(lithoSeed);
for(int i = 0;i < resolution.x + 1;i++){
float latitude = map(i,0,resolution.x,0,TAU);
for(int j = 0;j < resolution.y + 1;j++){
float longitude = map(j,0,resolution.y,0,PI);
float x = cos(latitude) * cos(longitude);
float y = sin(latitude);
float z = cos(latitude) * sin(longitude);
x *= map(noise(basicGlobe[i][j].x,basicGlobe[i][j].y,basicGlobe[i][j].z),0,1,400,500);
y *= map(noise(basicGlobe[i][j].x,basicGlobe[i][j].y,basicGlobe[i][j].z),0,1,400,500);
z *= map(noise(basicGlobe[i][j].x,basicGlobe[i][j].y,basicGlobe[i][j].z),0,1,400,500);
lithosphere[i][j] = new PVector(x,y,z);
if(i != 0){
PVector v1 = lithosphere[i - 1][j];
PVector v2 = lithosphere[i][j];
vertex(v1.x,v1.y,v1.z);
vertex(v2.x,v2.y,v2.z);
}
}
}
endShape();
}
There is a “gap” in the middle of my planet.
How do I fix that?