Normand Briere
2019-10-20 49d9c15d375942997692f7fccfb697665d0cb59e
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
 
class Sphere extends Biparam implements java.io.Serializable
{
//    void DrawNode(CameraPane display, Object3D /*Composite*/ root, boolean selected) {}
    
    static final long serialVersionUID = -962102766850477208L;
 
    boolean handle;
    
    /**/
    Sphere(float x, float y, float z)
    {
        this(false);
 
        radius = 0.05f;
        uDivs = 11; // 7;
        vDivs = 4; // 6;
 
        center = new cVector();
        center.set(x, y, z);
 
        //refreshCenter(center);
 
        retile();
        recalculate();
    }
    /**/
 
    Sphere()
    {
        this(true);
    }
 
    Sphere(Sphere s)
    {
        s.deepCopySelf(this);
    }
 
    public Sphere(boolean recalc)
    {
        toParent = LA.newMatrix();
        fromParent = LA.newMatrix();
        
        inPnt = new cVector();
        name = "Sphere";
        //uDivs = vDivs = 16;
        uDivs = 12; // 8; // 19;
        vDivs = 6; // 8; // 18;
        minUDivs = 3;
        minVDivs = 2;
        //center = new cVector();
        radius = 0.5;
        if (recalc)
        {
            retile();
            recalculate();
        }
    }
 
    void refreshCenter(cVector c)
    {
        /**/
        toParent[3][0] = c.x; // - center.x;
        toParent[3][1] = c.y; // - center.y;
        toParent[3][2] = c.z; // - center.z;
 
        fromParent[3][0] = -c.x; // + center.x;
        fromParent[3][1] = -c.y; // + center.y;
        fromParent[3][2] = -c.z; // + center.z;
    /**/
    //center.set(0,0,0);
    }
 
    cVector getCenter()
    {
        //assert(center.x == 0);
        //assert(center.y == 0);
        //assert(center.z == 0);
        
     //   if (center == null)
     //       center = new cVector();
        
        cVector c = new cVector(center);
 
        for (int i=GetTransformCount(); --i>=0;)
            LA.xformPos(c, toParent, c);
 
        return c;
    }
 
    Object3D deepCopy()
    {
        Sphere e = new Sphere();
        deepCopySelf(e);
        return e;
    }
 
    protected void deepCopyNode(Object3D other)
    {
        super.deepCopyNode(other);
        Sphere e = (Sphere) other;
        if (center != null)
        {
            e.center = new cVector(center);
            //LA.vecCopy(center, e.center);
        }
        e.radius = radius;
    }
 
    void generatePOV(StringBuffer buffer)
    {
        generateNameComment(buffer);
        generateIndent(buffer);
        buffer.append("sphere { ");
     //   LA.toPOVRay(center, buffer);
        buffer.append(", ");
     //   buffer.append(radius);
        buffer.append("\n");
        generateTransform(buffer);
        generateIndent(buffer);
        buffer.append("}\n");
    }
 
    double uStretch()
    {
        return 2;
    }
    
    double vFlip(double v)
    {
        return 1-v;
    }
    
    Vertex biparamFunction(double u, double v)
    {
        double uAng = LA.toRadians(u * 360);
        double vAng = LA.toRadians(v * 180);
        double z = (double) (Math.sin(vAng) * Math.cos(uAng)) * radius;
        double x = (double) (Math.sin(vAng) * Math.sin(uAng)) * radius;
        double y = (double) (-Math.cos(vAng)) * radius;
        Vertex temp = new Vertex();
        temp.norm = LA.newVector(x, y, z);
        //temp.pos = new cVector();
        if (center != null)
            LA.vecAdd(temp.norm, center, temp/*.pos*/);
        else
            LA.vecCopy(temp.norm, temp/*.pos*/);
        LA.vecNormalize(temp.norm);
        
        temp.y += radius;
        
        return temp;
    }
 
    void createEditWindow(GroupEditor callee, boolean newWindow)
    {
        //editWindow = (new SphereEditor(this, deepCopy(), callee)).GetEditor();
        if (newWindow)
        {
            objectUI = new SphereEditor(this, deepCopy(), callee);
        } else
        {
            objectUI = new SphereEditor(this, callee);
        }
        editWindow = objectUI.GetEditor();
    }
 
//    void getBounds(cVector minima, cVector maxima, boolean xform)
//    {
//        //for (int i=0; i < 3; i++)
//        {
//            minima.x = /*center.x*/ - 1; // radius;
//            minima.y = /*center.y*/ - 1; // radius;
//            minima.z = /*center.z*/ - 1; // radius;
//            //maxima[i] = center[i] + radius;
//            maxima.x = /*center.x*/ + 1; // radius;
//            maxima.y = /*center.y*/ + 1; // radius;
//            maxima.z = /*center.z*/ + 1; // radius;
//        }
//
//        //System.out.println("BoundsS = " + minima + " - " + maxima);
//        if (xform)
//        {
//            transformBounds(minima, maxima);
//        }
//    //System.out.println("BoundsS2 = " + minima + " - " + maxima);
//    }
 
    boolean inside(double x, double y, double z, boolean xform)
    {
        if (xform)
        {
            untransform(x, y, z, inPnt);
        } else
        {
            LA.setVector(inPnt, x, y, z);
        }
       // LA.vecSub(inPnt, center, inPnt);
        double f = inPnt.x * inPnt.x + inPnt.y * inPnt.y + inPnt.z * inPnt.z - radius * radius;
 
        boolean inside = f <= 0;
 
        if (depth != -1 && (height <= 0 ^ inside))
        {
            Simplex.atom = this;
        }
        height = f;
        depth = 0;
 
        return inside;
    }
    
    cVector center;
    double radius;
    cVector inPnt;
}