// Terrain viewer // Written by Jarek Rossignac August 2007 // for the scientific visualizatoin class // Loads a 64x64 terrain from file // Shades it either using color computed from height or using a texture with iso-level lines // Provides a tool for picking a vertex and changing its height import processing.opengl.*; // comment out if not using OpenGL PImage myImage; // image used as tecture int n=64; // size of grid. Must be >2! pt[][] G = new pt [n][n]; // array of vertices vec[][] L = new vec [n][n]; // laplace vectors for smoothing int pi=2,pj=2; // indices of vertex being dragged when mouse is pressed pt Mouse = new pt(0,0,0); // current mouse position boolean showLight=true; // flags to toggle the light color red = color(200, 10, 10), blue = color(10, 10, 200), green = color(10, 200, 20), yellow = color(250, 250, 100), magenta = color(200, 50, 200), black = color(10, 10, 10); float w,h,ww,hh; // width, height of cell in absolute and normalized units vec offset = new vec (0,0,0); // offset vector from mouse to clicked vertex float ax=342, az=1557; // camera angles float zmax=10, zmin=0; String [] S= new String [n*n+1]; boolean pick=false; // semaphor to render once for picking boolean showEdges=false; // toggle to show edges boolean useTexture=true; // toggle to show edges boolean showMenu=true; boolean showImage=false; boolean colors=true; color cc = green; // color for picking float r=100; // square of the radius of the Region of Influence int showROI=0; int fn=1, fnm=4; float waterLevel = 5; // ** SETUP ** void setup() { size(800, 800, OPENGL); //for OpenGL use: void setup() { size(800, 800, OPENGL); PFont font = loadFont("Courier-14.vlw"); textFont(font, 12); // load font for writing on window myImage = loadImage("ramp.jpg"); // load image for texture of level curves ww=1.0/(n-1); hh=1.0/(n-1); // set intial width and height of a cell w=width*ww; h=height*hh; // set intial width and height of a cell in normalized [0,1]x[0,1] resetVertices(); S=loadStrings("F0.hts"); hFromString(); } void resetVertices() { for (int i=0; i=0) && (ppi=0) && (ppj0) {showROI--; fill(red,80); G[pi][pj].show(sqrt(r)*w); }; translate(0,0,waterLevel); fill(blue,80); rect(0,0,n*w,n*h); }; void paintTexturedTerrain() { // renders the terrain using the texture with level lines noStroke(); fill(255); textureMode(NORMALIZED); // texture parameters in [0,1]x[0,1] beginShape(QUADS); for (int i=0; izmax) zmax=G[i][j].z; }; } void drawEdges() { // draws the edges between neighboring vertices stroke(black); noFill(); beginShape(QUADS); for (int i=0; i