Normand Briere
2019-08-28 547c9203ab5d8e4bee36d1cbb453dfa36bbec4ef
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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;
}