/******************************************************************** Title: Interactive Design of Triangular Meshes Author: Anand Murugappan (anandm@cc.gatech.edu) Advisor: Prof. Jarek Rossignac (jarek@cc.gatech.edu) Date: 13th Oct 2005 Code layout: 1. Globals 1.1 Constants 1.2 Flags 1.3 Colors 1.4 Tables [These are the data structures for mesh manupalation] 2. Save/Load Routines 2.1 unloadAll 2.1.1 unloadPoints 2.1.2 unloadTriangles 2.1.3 unloadOpposites 2.2 loadAll 2.2.1 loadPoints 2.2.2 loadTriangles 2.2.3 loadOpposites 3. Navigational Routines 3.1 getNext 3.2 getPrevious 3.3 getRight 3.4 getLeft // Why isnt getOpposite here? It is as simple as O[gC] 4. Display Routines 4.1 highlightCurrentVertexGate 4.2 drawTriangularMesh 4.3 drawMenu [Needs to be extended to have a menu displayed] 4.4 setup 4.5 drawAxis 4.6 drawAtom 4.7 draw 5. Merge Routines 5.1 getNearestVertex 5.2 merge 6. Input Routines 6.1 keyPressed 6.2 // Mouse movements to be added here! *********************************************************************/ // global constants int gMinX = 10; int gMinY = 10; int gMaxX = 600-20; int gMaxY = 600-20; int gUnit = 10; int gAngleX = 0; int gAngleY = 0; int gAngleZ = 0; // flags boolean fillNeeded = false; boolean axisNeeded = true; // Colors color black = color(0, 0, 0); color red = color(200, 0, 0); color green = color(0, 200, 0); color blue = color(0, 0, 200); color yellow = color(250, 250, 130); color white = color(255,255,255); color bgWhite = color(255,255,255,0); color grey = color(220,220,220); color lightYellow = color(250,250,200); color backgroundClr = white; // Global tables float [][] G = new float[500][3]; // Geometry Table int gGLast=0; int [] V = new int[500]; // Incidence Table int gVLast=0; int gC=0; // Current Vertex! int [] O = new int[500]; // Opposite Table int gOLast=0; /*************************************************************/ /* Save/Load routines */ /*************************************************************/ void unloadPoints() { String [] dumpString = new String [3*gGLast+1]; dumpString[0] = str(gGLast); for(int i=0;i d) // This guy is lesser so update minimum distance! { min = d; di = i; // This is our closest guy so far! } } } return di; } void merge() { int gi = getNearestVertex(V[gC]); int ngC = getNext(gC); int pgC = getPrevious(gC); V[gC] = gi; // Merged the 2 vertices! gGLast--; // Remove that vertex! Not wanted! // Now put the opposite! // search in all the triangles! for(int i=0;i='A' && key<='Z' || key>='a' && key<='z') { switch (key) { // Create a new triangle! case 'C': if (O[gC] == -1) // Make sure there is no opposite vertex already! { // Set the new vertex by Parallelogram prediction! G[gGLast][0] = G[V[n]][0]+G[V[p]][0]-G[V[gC]][0]; G[gGLast][1] = G[V[n]][1]+G[V[p]][1]-G[V[gC]][1]; G[gGLast++][2] = G[V[n]][2]+G[V[p]][2]-G[V[gC]][2]; // Modify the incidence table V[gVLast++] = V[n]; V[gVLast++] = gGLast-1; V[gVLast++] = V[p]; // Modify the opposite table O[gOLast++] = -1; O[gOLast++] = gC; O[gOLast++] = -1; O[gC] = gVLast-2; // Opposite of the current vertex is our new vertex which is gVLast-2 } break; // Jump to the previous vertex case 'P': gC = getPrevious(gC); break; // Jump to the previous vertex case 'N': gC = getNext(gC); break; // Jump to the opposite vertex case 'O': if (O[gC] != -1) { gC = O[gC]; } break; // Jump to the right vertex case 'R': gC = getRight(gC); break; // Jump to the left vertex case 'L': gC = getLeft(gC); break; // Move vertex to the left case 'A': G[V[gC]][0] = G[V[gC]][0]-gUnit; break; // Move vertex to the right case 'D': G[V[gC]][0] = G[V[gC]][0]+gUnit; break; // Move vertex to the left case 'W': G[V[gC]][1] = G[V[gC]][1]-gUnit; break; // Move vertex to the right case 'S': G[V[gC]][1] = G[V[gC]][1]+gUnit; break; // Move vertex to the left case 'E': G[V[gC]][2] = G[V[gC]][2]-gUnit; break; // Move vertex to the right case 'Z': G[V[gC]][2] = G[V[gC]][2]+gUnit; break; // Rotate camera! case 'T': gAngleX = gAngleX + 5; break; case 'G': gAngleX = gAngleX - 5; break; case 'Y': gAngleY = gAngleY + 5; break; case 'H': gAngleY = gAngleY - 5; break; case 'U': gAngleZ = gAngleZ + 5; break; case 'J': gAngleZ = gAngleZ - 5; break; case 'M': // Merge merge(); break; case'X': //rotate current vertex over the gate fillNeeded = !fillNeeded; break; case 'V': axisNeeded = !axisNeeded; break; case 'a': // Move along the gate G[c][0] -= gUnit*xx; G[c][1] -= gUnit*xy; G[c][2] -= gUnit*xz; break; case 'd': // Move along the gate G[c][0] += gUnit*xx; G[c][1] += gUnit*xy; G[c][2] += gUnit*xz; break; case 'e': // Move in the perpendicular plane G[c][0] += gUnit*(zx); G[c][1] += gUnit*(zy); G[c][2] += gUnit*(zz); break; case 'z': // Move in the perpendicular plane G[c][0] -= gUnit*(zx); G[c][1] -= gUnit*(zy); G[c][2] -= gUnit*(zz); break; case 's': G[c][0] += gUnit*(yx); G[c][1] += gUnit*(yy); G[c][2] += gUnit*(yz); break; case 'w': G[c][0] -= gUnit*(yx); G[c][1] -= gUnit*(yy); G[c][2] -= gUnit*(yz); break; case 'u': // Save(Unload) the contents in a file unloadAll(); break; case 'l': // Load from the saved file loadAll(); break; }; } drawAtom(1); }