Normand Briere
2019-11-07 dbbcbd6f6bd5b9c6eb194130ab471045faaf4955
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
 
public class Skybox extends Object3D implements java.io.Serializable
{
 
    Skybox()
    {
        name = "Skybox";
        minima = LA.newVector(-5, -5, -5);
        maxima = LA.newVector(5, 5, 5);
       bRep = new BoundaryRep();
        bRep.redimension(24, 12);
        
        for (int i=0; i < 12; i++)
            bRep.setFace(i, faces[i]);
 
        recalculate();
        CreateMaterial();
    }
 
    Object3D deepCopy()
    {
        Box rec = new Box();
        deepCopySelf(rec);
        return rec;
    }
 
    protected void deepCopyNode(Object3D other)
    {
        super.deepCopyNode(other);
        Skybox rec = (Skybox)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 ObjEditor(this, deepCopy(), callee);
       else
           objectUI = new ObjEditor(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()
    {
        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)
    {
        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[] = {
        0, 0, 1, 1, 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 cVector inPnt = new cVector();
}