90 likes | 245 Views
CS3451-P5. Rolling a disk on a triangle mesh. Show path. Define a data structure for the path (points+normals) pt [] gP = new pt[5000]; // path points vec [] gN = new vec[5000]; // path normaLS vec gD = new vec (1,0,0); // current direction
E N D
CS3451-P5 • Rolling a disk on a triangle mesh
Show path • Define a data structure for the path (points+normals) • pt [] gP = new pt[5000]; // path points • vec [] gN = new vec[5000]; // path normaLS • vec gD = new vec (1,0,0); // current direction • int gn = 0; // number of path points • int gm = 0; // number of last undisplayed steps • Visualize it (a bit offset from the surface) • Let the user add points • By clicking void keys() {… if (key=='r') {C.setMark(); M.hitTriangle(); M.gstart();}; if (key=='t') {C.setMark(); M.hitTriangle(); M.gextend();};
Start the path • User click selects corner c and sets mark (green) if (key=='r') {C.setMark(); M.hitTriangle(); M.gstart(); }; void gstart() { gP[0]=g(c); …… }; Compute exit point S1 on opposite edge Compute edge-normal at S1 Compute new (reflected) D Show them all
Extend the path if (key=='t') {M.gextend(); if (jumps) M.gjump(C);}; void gextend(){vec N = cross(triNormal(t(c)),gD); if (dot(N,V(gP[gn-1],g(c)))>0) c=n(c); else c=p(c); gmove(); } void gmove() {… Similar to gstart
Smooth normals if (key=='s') {M.gsmoothNormals();}; void gsmoothNormals () {vec[] L = new vec[gn];… // one line
Display a subset of the path int gn = 0; // number of path points int gm = 0; // number of last not displayed steps void keys() { if (key==',') M.gm++; if (key=='.') M.gm--; Useful to compute the path first, then smooth the normals, then roll
Follow the disk with the camera if (key==’J') jumps=!jumps; if (key=='t') {M.gextend(); if (jumps) M.gjump(C);}; void gjump (cam C) { C.F=P(gP[gn-gm-1]); C.E= S(S(C.F,-200,gD),200,gN[gn-gm-1]); C.U=S(-1,gN[gn-gm-1]); C.sD=200; C.pullE(); C.pose(); };
Display disk void gshow() {stroke(red); gshowPath(); stroke(blue); gshowNormals(); stroke(magenta); fill(blue); gshowPoints(); fill(orange); gdisk(30); } void gdisk(float d) {float L=0; // measure length of displayed path (to gm) show polygonized disk above gP[gn-gm-1] using gN[gn-gm-1] and D as basis vectors. rotate it to reflect distance traveled L I show it missing one slice to check the roll (you should put a texture)
Results • 3 hours • 40 lines of code (total)