/*A building where the upper corners are cut away.*/ SIZE = 1.0; FLOORS = 55; CUT = 35;//number of floors cut away WIDTH = 18;//even number SQRT2 = Math.sqrt(2); TODEG = 180/Math.PI; //textures win = new UniformTexture(); win.diffuseColor.setRGB(0.6,0.6,0.6); win.specularity = 0.5f; win.shininess = 1.0f; bar = new UniformTexture(); bar.diffuseColor.setRGB(0.3,0.3,0.3); spire = new UniformTexture(); spire.diffuseColor.setRGB(0.6,0.6,0.6); spire.shininess = 1.0f; TriangleMesh top(double xsize, double ysize, double zsize) { //a triangular with the top chopped off, width of the top cut is top double x = xsize/2; double y = ysize; double z = zsize/2; vertices = new Vec3[8]; // 8 vertices + 6 faces vertices[0] = new Vec3(-x, 0.0, -z); vertices[1] = new Vec3(x, 0.0, -z); vertices[4] = new Vec3(-x, 0.0, z); vertices[5] = new Vec3(x, 0.0, z); vertices[2] = new Vec3(x, y, -z*0); vertices[3] = new Vec3(-x*0, y, -z); vertices[6] = new Vec3(x*0, y, z); vertices[7] = new Vec3(-x, y, z*0); //triangular faces int[][] faces = { { 0, 1, 5}, { 0, 5, 4}, { 6, 2, 3}, { 6, 3, 7}, {6, 4, 5}, { 0, 4, 7}, {0, 7, 3}, { 6, 7, 4}, {1, 0, 3}, {5, 1, 2}, {6, 5, 2}, {2, 1, 3} }; mesh = new TriangleMesh(vertices, faces); mesh.setSmoothingMethod(0); return(mesh); } //bottom floors box = new Cube(WIDTH*SIZE,(FLOORS-CUT)*SIZE,WIDTH*SIZE); box.setTexture(win, win.getDefaultMapping(box)); p = new Vec3(0,(FLOORS-CUT)*SIZE/2,0); script.addObject(box, new CoordinateSystem(p, 0,0,0)); x = (WIDTH+0.1)*SIZE; box = new Cube(x,0.1*SIZE,x); box.setTexture(bar, bar.getDefaultMapping(box)); for (i=0;i<=FLOORS-CUT;i++) { p = new Vec3(0,i*SIZE,0); script.addObject(box, new CoordinateSystem(p, 0,0,0)); } //top floors box = top(WIDTH*SIZE,CUT*SIZE,WIDTH*SIZE); box.setTexture(win, win.getDefaultMapping(box)); p = new Vec3(0,(FLOORS-CUT)*SIZE,0); script.addObject(box, new CoordinateSystem(p, 0,0,0)); for (i=FLOORS-CUT+1;i=0;i=i-5) { m = (FLOORS*SIZE - i*SIZE)/(-WIDTH/2*SIZE);//eqn of line y = m*x + FLOORS*SIZE x = (ylim-FLOORS*SIZE)/m; //first point (x,ylim) second point (WIDTH/2*SIZE,i*SIZE) temp = new Vec3(x-WIDTH/2*SIZE,ylim-i*SIZE,0); d = temp.length(); box = new Cube(d,0.1*SIZE,0.1*SIZE); box.setTexture(bar, bar.getDefaultMapping(box)); th = Math.atan2(-temp.y,temp.x); p = new Vec3( (x+WIDTH/2*SIZE)/2, (ylim+i*SIZE)/2, WIDTH*SIZE/2); script.addObject(box, new CoordinateSystem(p, 0,0,th*TODEG)); p = new Vec3( (x+WIDTH/2*SIZE)/2, (ylim+i*SIZE)/2, -WIDTH*SIZE/2); script.addObject(box, new CoordinateSystem(p, 0,0,th*TODEG)); p = new Vec3( -(x+WIDTH/2*SIZE)/2, (ylim+i*SIZE)/2, WIDTH*SIZE/2); script.addObject(box, new CoordinateSystem(p, 0,0,-th*TODEG)); p = new Vec3( -(x+WIDTH/2*SIZE)/2, (ylim+i*SIZE)/2, -WIDTH*SIZE/2); script.addObject(box, new CoordinateSystem(p, 0,0,-th*TODEG)); p = new Vec3( WIDTH*SIZE/2, (ylim+i*SIZE)/2, (x+WIDTH/2*SIZE)/2); script.addObject(box, new CoordinateSystem(p, 0,90,th*TODEG)); p = new Vec3( -WIDTH*SIZE/2, (ylim+i*SIZE)/2, (x+WIDTH/2*SIZE)/2); script.addObject(box, new CoordinateSystem(p, 0,90,th*TODEG)); p = new Vec3( WIDTH*SIZE/2, (ylim+i*SIZE)/2, -(x+WIDTH/2*SIZE)/2); script.addObject(box, new CoordinateSystem(p, 0,90,-th*TODEG)); p = new Vec3( -WIDTH*SIZE/2, (ylim+i*SIZE)/2, -(x+WIDTH/2*SIZE)/2); script.addObject(box, new CoordinateSystem(p, 0,90,-th*TODEG)); } kk = (int) Math.floor(WIDTH/2); for (i=kk;i>=0;i=i-2) { m = (FLOORS*SIZE)/(-i*SIZE);//eqn of line y = m*x + FLOORS*SIZE x = (ylim-FLOORS*SIZE)/m; //first point (x,ylim) second point (i*SIZE,0) temp = new Vec3(x-i*SIZE,ylim,0); d = temp.length(); box = new Cube(d,0.1*SIZE,(WIDTH+0.1)*SIZE); box.setTexture(bar, bar.getDefaultMapping(box)); th = Math.atan2(-temp.y,temp.x); p = new Vec3( (x+i*SIZE)/2, ylim/2, 0); script.addObject(box, new CoordinateSystem(p, 0,0,th*TODEG)); p = new Vec3( -(x+i*SIZE)/2, ylim/2, 0); script.addObject(box, new CoordinateSystem(p, 0,0,-th*TODEG)); p = new Vec3( 0, ylim/2, (x+i*SIZE)/2); script.addObject(box, new CoordinateSystem(p, 0,90,th*TODEG)); p = new Vec3( 0, ylim/2, -(x+i*SIZE)/2); script.addObject(box, new CoordinateSystem(p, 0,90,-th*TODEG)); } //corners box = new Cube(0.1*SIZE,(FLOORS-CUT)*SIZE,0.1*SIZE); box.setTexture(bar, bar.getDefaultMapping(box)); p = new Vec3(WIDTH*SIZE/2,(FLOORS-CUT)*SIZE/2,WIDTH*SIZE/2); script.addObject(box, new CoordinateSystem(p, 0,0,0)); p = new Vec3(-WIDTH*SIZE/2,(FLOORS-CUT)*SIZE/2,WIDTH*SIZE/2); script.addObject(box, new CoordinateSystem(p, 0,0,0)); p = new Vec3(WIDTH*SIZE/2,(FLOORS-CUT)*SIZE/2,-WIDTH*SIZE/2); script.addObject(box, new CoordinateSystem(p, 0,0,0)); p = new Vec3(-WIDTH*SIZE/2,(FLOORS-CUT)*SIZE/2,-WIDTH*SIZE/2); script.addObject(box, new CoordinateSystem(p, 0,0,0)); //spire on top box = new Cube(0.6*SIZE,10*SIZE,0.6*SIZE); box.setTexture(spire, spire.getDefaultMapping(box)); p = new Vec3(0,(FLOORS+5)*SIZE,6*SIZE); script.addObject(box, new CoordinateSystem(p, 0,45,0)); c = new Cylinder(9*SIZE,0.2*SIZE,0.2*SIZE,0.7f); c.setTexture(spire, spire.getDefaultMapping(c)); p = new Vec3(0,(FLOORS+14.5)*SIZE,6*SIZE); script.addObject(c, new CoordinateSystem(p, 0,0,0));