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
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
217
218
219
220
221
222
223
224
225
226
227
import java.awt.*;
 
class BlobComponent extends Sphere implements java.io.Serializable
{
    static final long serialVersionUID = 8329366050568734699L;
    
   BlobComponent()
   {
       name = "Component";
       //center = new cVector();
       //radius = 1;
       //radius2 = radius * radius;
       strength = 100;
   }
   
   Object3D deepCopy()
   {
       BlobComponent comp = new BlobComponent();
       deepCopySelf(comp);
       return comp;
   }
   
   protected void deepCopyNode(Object3D other)
   {
       super.deepCopyNode(other);
       BlobComponent b = (BlobComponent)other;
       //b.center = new cVector();
       //LA.vecCopy(center, b.center);
       //b.radius = radius;
       //b.radius2 = radius2;
       b.strength = strength;
   }
   
   void generatePOV(StringBuffer buffer)
   {
       generateIndent(buffer);
       buffer.append("    component ");
       buffer.append(strength);
       buffer.append(", ");
       //buffer.append(radius);
       buffer.append(", ");
       //LA.toPOVRay(center, buffer);
       buffer.append("\n");
   }
   
   double getFieldStrength(double x, double y, double z)
   {
            untransform(x, y, z, cStatic.point1);
            x = cStatic.point1.x;
            y = cStatic.point1.y;
            z = cStatic.point1.z;
            //untransform(inpnt.x, inpnt.y, inpnt.z, buffer);
            
            //LA.vecSub(inpnt,center, point);
            double rad = x*x + y*y + z*z; // LA.vecLen2(buffer); // / radius2;
            if (rad >= 1)
            {
                    return 0;
            } else
            {
                    //rad *= rad;
                    return strength * (1 - rad) * (1 - rad);
            }
   }
   
   double xx[] = new double[2];
   double yy[] = new double[2];
   double zz[] = new double[2];
   double x2[] = new double[2];
   double y2[] = new double[2];
   double z2[] = new double[2];
   double sum[] = new double[2];
   
   void boxFieldStrength(double x[], double y[], double z[], double range[])
   {
       xx[0] = x[0]; // - center.x;
       xx[1] = x[1]; // - center.x;
       yy[0] = y[0]; // - center.y;
       yy[1] = y[1]; // - center.y;
       zz[0] = z[0]; // - center.z;
       zz[1] = z[1]; // - center.z;
       Interval.boxSquare(xx, x2);
       Interval.boxSquare(yy, y2);
       Interval.boxSquare(zz, z2);
       
       Interval.boxAdd(x2, y2, sum);
       Interval.boxAdd(sum, z2, sum);
 
       for (int i=0; i < 2; i++)
       {
           //sum[i] /= radius2;
           if (sum[i] > 1)
               range[i] = 0;
           else
               range[i] = strength * (1 - sum[i]) * (1 - sum[i]);
       }
       
       if (range[0] > range[1])
       {
           double t = range[0];
           range[0] = range[1];
           range[1] = t;
       }
   }
   
   Point ctr = new Point(0, 0);
   Rectangle dummy = new Rectangle();
   
        /*
   boolean doSelection(ClickInfo info, Rectangle r, int level)
   {
       calcHotSpot(center, info, ctr, dummy);
       double x[] = new double[2];
       double y[] = new double[2];
       x[0] = r.x - ctr.x;
       x[1] = x[0] + (double)r.width;
       y[0] = r.y - ctr.y;
       y[1] = y[0] + (double)r.height;
       //double x2[] = new double[2];
       //double y2[] = new double[2];
       Interval.boxSquare(x, x2);
       Interval.boxSquare(y, y2);
       //double sum[] = new double[2];
       Interval.boxAdd(x2, y2, sum);
       //return sum[0] < radius2 && sum[1] > radius2;
   }
   
   void draw(ClickInfo info, int level, boolean select)
   {
       if (select)
           info.g.setColor(Color.black);
       else
           info.g.setColor(Color.gray);
       Rectangle spot = calcHotSpot(center, info);
       spot.x -= (int)radius - 2;
       spot.y -= (int)radius - 2;
       spot.width = (int)(radius * 2);
       spot.height = (int)(radius * 2);
       info.g.drawArc(spot.x, spot.y, spot.width, spot.height, 0, 360);
       info.g.drawArc(spot.x + 1, spot.y + 1, spot.width - 2, spot.height - 2, 0, 360);
   }
   
   void draw(iCameraPane display, boolean selected)
   {
   }
   */
        
        /*
   void drawEditHandles(ClickInfo info, int level)
   {
       Rectangle spot = calcHotSpot(center, info);
       info.g.setColor(Color.red);
       info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
   }
   
   boolean doEditClick(ClickInfo info, int level)
   {
       hitSomething = false;
       Rectangle spot = calcHotSpot(center, info);
       if (!spot.contains(info.x, info.y))
       {
           return false;
       } else
       {
           hitSomething = true;
           modified = (info.modifiers & CameraPane.META) != 0;
           startX = info.x;
           startY = info.y;
           LA.vecCopy(center, startVec);
           startRad = radius;
           return true;
       }
   }
   
   void doEditDrag(ClickInfo info)
   {
       if (!hitSomething)
           return;
       if (modified)
       {
           double deltaR = info.x - startX;
           deltaR /= 100 * info.camera.SCALE / info.camera.Distance();
           double newRad = startRad + deltaR;
           if (newRad < 0)
               newRad = 0;
           radius = newRad;
           //radius2 = radius*radius;
       } else
       {
           cVector delta = LA.newVector(info.x - startX, startY - info.y, 0);
           LA.xformDir(delta, info.camera.fromScreen, delta);
           delta.x /= 100 * info.camera.SCALE / info.camera.Distance();
           delta.y /= 100 * info.camera.SCALE / info.camera.Distance();
           delta.z /= 100 * info.camera.SCALE / info.camera.Distance();
           LA.vecAdd(startVec, delta, center);
       }
       info.pane.repaint();
   }
   */
        
        public void getBounds(cVector minima, cVector maxima, boolean xform)
        {
            //double rad = radius * 1.1;
            for (int i=0; i < 3; i++)
            {
                //minima.set(i, center.get(i) - radius);
                //maxima.set(i, center.get(i) + radius);
                minima.set(i, -1);
                maxima.set(i, 1);
            }
            
            if (xform)
                transformBounds(minima, maxima);
        }
        
   //cVector center;
   //double radius;
   //double radius2;
   double strength;
   private static boolean hitSomething;
   private static boolean modified;
   private static int startX;
   private static int startY;
   private static cVector startVec = new cVector();
   private static cVector point = new cVector();
   private static double startRad;
}