public class Box extends Object3D implements java.io.Serializable { static final long serialVersionUID = 0; boolean open; Box() { inPnt = new cVector(); name = "Box"; minima = LA.newVector(-0.5, 0, -0.5); maxima = LA.newVector(0.5, 1, 0.5); bRep = new BoundaryRep(); recalculate(); CreateMaterial(); } Object3D deepCopy() { Box rec = new Box(); deepCopySelf(rec); return rec; } protected void deepCopySelf(Object3D other) { super.deepCopySelf(other); // Box rec = (Box)other; // rec.minima = new cVector(); // LA.vecCopy(minima, rec.minima); // rec.maxima = new cVector(); // LA.vecCopy(maxima, rec.maxima); } void createEditWindow(GroupEditor callee, boolean newWindow) { //editWindow = new BoxEditor(this, deepCopy(), callee); /**/ if (newWindow) objectUI = new BoxEditor(this, deepCopy(), callee); else objectUI = new BoxEditor(this, callee); editWindow = objectUI.GetEditor(); // if (!newWindow) // ((ObjEditor)objectUI).SetupUI2(callee); /**/ } void generatePOV(StringBuffer buffer) { generateNameComment(buffer); generateIndent(buffer); buffer.append("box { "); LA.toPOVRay(minima, buffer); buffer.append(", "); LA.toPOVRay(maxima, buffer); buffer.append("\n"); generateTransform(buffer); generateIndent(buffer); buffer.append("}\n"); } void recalculate() { if (open) { bRep.redimension(8, 8); for (int i=0; i < 8; i++) bRep.setFace(i, facesopen[i]); } else { bRep.redimension(8, 12); for (int i=0; i < 12; i++) bRep.setFace(i, faces[i]); } for (int i=0; i < 8; i++) { double x = i >= 4 ? maxima.x : minima.x; double y = (i / 2) % 2 != 0 ? maxima.y : minima.y; double z = i % 2 != 0 ? maxima.z : minima.z; bRep.setVertex(i, x, y, z, umap[i], vmap[i]); } // bRep.Trim(false, false); super.recalculate(); } void getBounds(cVector min, cVector max, boolean xform) { super.getBounds(min, max, xform); // july 2014 LA.vecCopy(minima, min); // LA.vecCopy(maxima, max); // if (xform) // transformBounds(min, max); } boolean inside(double x, double y, double z, boolean xform) { if (xform) untransform(x, y, z, inPnt); else LA.setVector(inPnt, x, y, z); for (int i=0; i < 3; i++) { if (inPnt.get(i) < minima.get(i)) return false; if (inPnt.get(i) > maxima.get(i)) return false; } return true; } cVector minima; cVector maxima; static float umap[] = { 0, 1, 0, 1, 1, 0, 1, 0, }; static float vmap[] = { 1, 1, 0, 0, 1, 1, 0, 0, }; static int faces[][] = { { 0, 1, 3 }, { 0, 3, 2 }, { 2, 3, 7 }, { 2, 7, 6 }, { 1, 5, 7 }, { 1, 7, 3 }, { 4, 6, 7 }, { 4, 7, 5 }, { 0, 4, 5 }, { 0, 5, 1 }, { 0, 2, 6 }, { 0, 6, 4 } }; static int facesopen[][] = { { 0, 1, 3 }, { 0, 3, 2 }, { // 2, 3, 7 // }, { // 2, 7, 6 // }, { 1, 5, 7 }, { 1, 7, 3 }, { 4, 6, 7 }, { 4, 7, 5 }, { // 0, 4, 5 // }, { // 0, 5, 1 // }, { 0, 2, 6 }, { 0, 6, 4 } }; protected cVector inPnt; }