// Seung Joon Choi // http://epicure.graffity.net // epicure@hanmail.net // 2005.10.14. Vec3 eyeFrom; Vec3 eyeTo; Bldg[] bs; PLife[] pls; boolean b_pause = true; float wx = 0; float wy = 0; float wrx = 0; float wry = PI / 4; float dd = 200; int trace_id = -1; int trace_id2 = 0; boolean show_blds = true; boolean show_terrain = false; boolean lifestyle1 = false; boolean lifestyle2 = false; boolean lifestyle3 = true; boolean show_line_black = true; boolean show_line_red = false; boolean mode_friendly = true; boolean mode_intimate = true; void setup() { size(640, 480, P3D); noStroke(); colorMode(HSB, 1.0); ellipseMode(CENTER_RADIUS); eyeFrom = new Vec3(0, 0, 500); eyeTo = new Vec3(0, 0, 0); bs = new Bldg[30]; for(int i = 0; i < bs.length; i++) { bs[i] = new Bldg(); bs[i].x = (1 - random(2)) * 400; bs[i].y = (1 - random(2)) * 400; } for(int j = 0; j < 10; j++) for(int i = 0; i < bs.length; i++) { Bldg bld = bs[i]; bld.Init(bs); } pls = new PLife[200]; for(int i = 0; i < pls.length; i++) { pls[i] = new PLife(); PLife pl = pls[i]; pl.x = (1 - random(2)) * 500; pl.y = (1 - random(2)) * 500; int j = int(random(bs.length)); pl.X = bs[j].x; pl.Y = bs[j].y; //pl.x = bs[j].x; //pl.y = bs[j].y; } //------------------- SL Part for the Terrain sl_width = 32; sl_height = 32; canvas = new PImage(sl_width, sl_height); hmap = new float[sl_width * sl_height]; buildCanvas(); buildHeightField(); } void Camera() { if(trace_id == -1) { float dt = 0.1; float dx = width * 0.5 - mouseX; float dy = height * 0.5 - mouseY; float d = sqrt(dx*dx + dy*dy); if(d > 0) { wx = dx / d; wy = dy / d; } if(mousePressed) { dd += 10; } camera(eyeFrom.x, eyeFrom.y, eyeFrom.z, eyeTo.x, eyeTo.y, eyeTo.z, 0, 1, 0); if(!b_pause) { wrx += -wx * PI * 0.002; wry += -wy * PI * 0.002; } translate(0, 0, dd); rotateY(wrx); rotateX(wry); } else { PLife pl = pls[trace_id]; PLife pl2 = pls[trace_id2]; camera(pl.x, pl.y, pl.h, pl2.x, pl2.y, pl2.h, 0, 0, -1); } } void keyPressed() { if(key == 'z') { dd += 10; } if(key == 'x') { dd -= 10; } if(keyCode == 32) // SPACE { b_pause = !b_pause; } if(key == 'c') { trace_id = -1; } if(key == 't') { trace_id = int(random(pls.length)); trace_id2 = int(random(pls.length)); } if(key == 'q') { show_blds = !show_blds; } if(key == 'w') { show_terrain = !show_terrain; } if(key == '1') { lifestyle1 = !lifestyle1; println("lifestyle1 : " + lifestyle1); } if(key == '2') { lifestyle2 = !lifestyle2; println("lifestyle2 : " + lifestyle2); } if(key == '3') { lifestyle3 = !lifestyle3; println("lifestyle3 : " + lifestyle3); } if(key == '9') { show_line_black = !show_line_black; } if(key == '0') { show_line_red = !show_line_red; } if(key == 'f') { mode_friendly = !mode_friendly; } if(key == 'i') { mode_intimate = !mode_intimate; } } void draw() { background(0.7, 1, 0.5); lights(); Camera(); /* fill(0.7, 1, 0.4); sphere(2500); */ scale(0.25); stroke(0,0,0,0.1); if(show_terrain) { buildHeightField(); pointLight(0, 0, 1, 0, 0, 200); pushMatrix(); drawHField(50); popMatrix(); sss += 0.02; } for(int i = 0; i < bs.length; i++) { bs[i].Interact(pls); if(show_blds) bs[i].Render(); } for(int i = 0; i < pls.length; i++) { PLife pl = pls[i]; pl.Interact(pls); pl.Live(); //------------------- int xx = int(pl.y / 600.0 * 16) + 15; int yy = int(pl.y / 600.0 * 16) + 15; if(xx < 0) xx = 0; if(yy < 0) yy = 0; if(xx > 31) xx = 31; if(yy > 31) yy = 31; int ii = yy * 31 + xx; float v = hmap[ii]; pl.z = v * 10; //------------------- pl.Render(); } }