// default behavior is to read LDraw lines as comments class LDrawPrimitive{ Integer col; LDrawPrimitive(){ super(); }; Integer getType(){ return 0; }; void readln(String input){ }; void writeln(){ }; void draw(int basecol){ }; // nothing to draw() }; class LDrawLine extends LDrawPrimitive{ Vector3D p1; Vector3D p2; int col; LDrawLine(){ p1 = new Vector3D(); p2 = new Vector3D(); col = 0; }; void readln(String input){ String[] t = splitTokens( input.trim(), " "); col = new Integer( t[ 1]); p1 = new Vector3D( new Float( t[ 2]), new Float( t[ 3]), new Float( t[ 4])); p2 = new Vector3D( new Float( t[ 5]), new Float( t[ 6]), new Float( t[ 7])); }; void draw( int basecol){ // if( col != 16 && col != 24){ colorlib.findByCode( col).setColorEdge(); // }; line( p1.x, p1.y, p1.z, p2.x, p2.y, p2.z); }; }; class LDrawTri extends LDrawPrimitive{ Vector3D p1, p2, p3; void readln( String input){ String[] t = splitTokens( input.trim(), " "); col = new Integer( t[ 1]); p1 = new Vector3D( new Float( t[ 2]), new Float( t[ 3]), new Float( t[ 4])); p2 = new Vector3D( new Float( t[ 5]), new Float( t[ 6]), new Float( t[ 7])); p3 = new Vector3D( new Float( t[ 8]), new Float( t[ 9]), new Float( t[ 10])); }; void draw( int basecol){ if( col == 16){ colorlib.findByCode( basecol).setColorFill(); }else if( col != 24){ colorlib.findByCode( col).setColorFill(); }; noStroke(); beginShape(TRIANGLES); vertex( p1.x, p1.y, p1.z); vertex( p2.x, p2.y, p2.z); vertex( p3.x, p3.y, p3.z); endShape(); }; }; class LDrawQuad extends LDrawPrimitive{ Vector3D p1, p2, p3, p4; void readln( String input){ String[] t = splitTokens( input.trim(), " "); col = new Integer( t[ 1]); p1 = new Vector3D( new Float( t[ 2]), new Float( t[ 3]), new Float( t[ 4])); p2 = new Vector3D( new Float( t[ 5]), new Float( t[ 6]), new Float( t[ 7])); p3 = new Vector3D( new Float( t[ 8]), new Float( t[ 9]), new Float( t[ 10])); p4 = new Vector3D( new Float( t[ 11]), new Float( t[ 12]), new Float( t[ 13])); }; void draw( int basecol){ // println( "Drew a Quad"); if( col == 16){ colorlib.findByCode( basecol).setColorFill(); }else if( col != 24){ colorlib.findByCode( col).setColorFill(); }; noStroke(); beginShape(QUADS); vertex( p1.x, p1.y, p1.z); vertex( p2.x, p2.y, p2.z); vertex( p3.x, p3.y, p3.z); vertex( p4.x, p4.y, p4.z); endShape(); }; }; class LDrawOptLine extends LDrawPrimitive{ Vector3D p1; Vector3D p2; Vector3D p3; Vector3D p4; Vector3D s1; Vector3D s2; Vector3D s3; Vector3D s4; LDrawOptLine(){ p1 = new Vector3D(); p2 = new Vector3D(); p3 = new Vector3D(); p4 = new Vector3D(); col = 0; s1 = new Vector3D(); s2 = new Vector3D(); s3 = new Vector3D(); s4 = new Vector3D(); }; void readln( String input){ String[] t = splitTokens( input.trim(), " "); col = new Integer( t[ 1]); p1 = new Vector3D( new Float( t[ 2]), new Float( t[ 3]), new Float( t[ 4])); p2 = new Vector3D( new Float( t[ 5]), new Float( t[ 6]), new Float( t[ 7])); p3 = new Vector3D( new Float( t[ 8]), new Float( t[ 9]), new Float( t[ 10])); p4 = new Vector3D( new Float( t[ 11]), new Float( t[ 12]), new Float( t[ 13])); }; void draw( int basecol){ if( basecol != -1) return; /* E1x = P1x-P2x E1y = P1y-P2y E2x = P3x-P2x E2y = P3y-P2y if ((E1x * E2y - E1y * E2x) >= 0) clockwise = TRUE; else clockwise = FALSE; */ s1.setXYZ( screenX( p1.x, p1.y, p1.z), screenY( p1.x, p1.y, p1.z), 0.0); s2.setXYZ( screenX( p2.x, p2.y, p2.z), screenY( p2.y, p2.y, p2.z), 0.0); s3.setXYZ( screenX( p3.x, p3.y, p3.z), screenY( p3.y, p3.y, p3.z), 0.0); s4.setXYZ( screenX( p4.x, p4.y, p4.z), screenY( p4.y, p4.y, p4.z), 0.0); /* s1.setXYZ( screenX( p1.x, p1.y, p1.z), screenY( p1.x, p1.y, p1.z), screenZ( p1.x, p1.y, p1.z)); s2.setXYZ( screenX( p2.x, p2.y, p2.z), screenY( p2.y, p2.y, p2.z), screenZ( p2.y, p2.y, p2.z)); s3.setXYZ( screenX( p3.x, p3.y, p3.z), screenY( p3.y, p3.y, p3.z), screenZ( p3.y, p3.y, p3.z)); s4.setXYZ( screenX( p4.x, p4.y, p4.z), screenY( p4.y, p4.y, p4.z), screenZ( p4.y, p4.y, p4.z)); */ /* float E1x = s2.x - s1.x; float E1y = s2.y - s1.y; float E2x = s3.x - s1.x; float E2y = s3.y - s1.y; float r1 = E1x * E2y - E1y * E2x; E1x = s1.x - s2.x; E1y = s1.y - s2.y; E2x = s4.x - s2.x; E2y = s4.y - s2.y; float r2 = E1x * E2y - E1y * E2x; */ /* (xi - xi-1) * (yi+1 - yi) - (yi - yi-1) * (xi+1 - xi) */ float r1 = (s1.x - s2.x) * (s3.y - s1.y) - (s1.y - s2.y) * (s3.x - s1.x); float r2 = (s1.x - s2.x) * (s4.y - s1.y) - (s1.y - s2.y) * (s4.x - s1.x); if( r1 <= 0 == r2 <= 0){ // ^ == XOR // colorlib.findByCode( col).setColorEdge(); stroke( color( 255, 0, 255)); line( p1.x, p1.y, p1.z, p2.x, p2.y, p2.z); }; }; };