Maybe Im doing it the wrong way but it is the same but a loooot :_) slower. Here is the code:
import processing.opengl.*;
ground new_ground = new ground();
float c_x,c_y,c_z;
void setup(){
size(1000,1000,P3D);
frameRate(30);
new_ground.setup();
frustum(-500,500,-500, 500, 200, 0);
}
void draw(){
background(0);
new_ground.draw();
camera(c_x,c_y-200,c_z,c_x + 200*sin(map(mouseX,0,width,0,TWO_PI)),c_y -200 ,c_z + 200*cos(map(mouseX,0,width,0,TWO_PI)),
0.0, 1.0, 0.0);
}
void keyPressed() {
float move = +500;
if (key == CODED) {
if (keyCode == UP) {
c_z = c_z + move;
} else if (keyCode == DOWN) {
c_z = c_z - move;
} else if (keyCode == LEFT) {
c_x = c_x + move;
}else if (keyCode == RIGHT) {
c_x = c_x - move;
}
}
}
class ground {
int x_size = 100;
int z_size = 100;
int h_m_a = x_size * z_size;
float d = 1500; //distance between
float x[] = new float[x_size * z_size + 10];
float y[] = new float[x_size * z_size + 10];
float z[] = new float[x_size * z_size + 10];
int c[] = new color[x_size * z_size + 10];
int h_m_m = 20;
float m_x[] = new float[h_m_m+1];
float m_z[] = new float[h_m_m+1];
float m_e[] = new float[h_m_m+1];
void setup() {
setup_mountains();
setup_points();
setup_colors();
}
void setup_mountains() {
for(int i = 1;i<=h_m_m;i++) {
m_x[i] = random(-x_size*d,x_size*d);
m_z[i] = random(-z_size*d,z_size*d);
m_e[i] = 1;//random(1,10);
}
}
void setup_colors() {
float r_x = random(-x_size*d,x_size*d);
float r_z = random(-z_size*d,z_size*d);
float g_x = random(-x_size*d,x_size*d);
float g_z = random(-z_size*d,z_size*d);
float b_x = random(-x_size*d,x_size*d);
float b_z = random(-z_size*d,z_size*d);
for(int i = 1;i<=h_m_a;i++) {
c[i] = color(map(dist(x[i],z[i],r_x,r_z),0,d*x_size,0,255),
map(dist(x[i],z[i],g_x,g_z),0,d*x_size,0,255),
map(dist(x[i],z[i],b_x,b_z),0,d*x_size,0,255)
);
}
}
void setup_points() {
int a = 0;
float b = 0;
for(int i = 1;i<=h_m_a;i++) {
z[i] = -z_size*d/2 + a*d;
x[i] = -x_size*d/2 + b;
float ee = 0;
for(int j = 1;j<=h_m_m;j++) {
if(dist(x[i],z[i],m_x[j],m_z[j]) < d*10) { ee = map(dist(x[i],z[i],m_x[j],m_z[j]),0,5000,0,-
5000);}
}
// ee = ee/h_m_m;
y[i] = ee;//random(0,1000);
if(a>=x_size) {
a=0;
b = b + d;
}
a++;
}
}
void draw() {
for(int i = 1;i<h_m_a-x_size;i++) {
if(x[i] != -x_size*d/2 & z[i] != -z_size*d/2 & x[i] != +x_size*d/2 & z[i] != +z_size*d/2) {
fill(c[i]);
noStroke();
//line(x[i],y[i],z[i],x[i+1],y[i+1],z[1+i]);
beginShape(QUADS);
make_vertex(i);
make_vertex(i+1);
make_vertex(i+x_size+1);
make_vertex(i+z_size);
endShape();
}
}
}
void make_vertex(int i) {
vertex(x[i],y[i],z[i]);
}
}