Normand Briere
2019-09-22 e96132853038f55cdb6e27f116852cff0e813f00
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
 
public class cLinker extends Composite
{
   static final long serialVersionUID = 2676790134285089534L;
        
    cLinker()
    {
        super("Linker");
        
        count = 4;
        
        height = 1;
        depth = 0;
    }
    
    Object3D deepCopy()
    {
        cLinker t = new cLinker();
        deepCopySelf(t);
        return t;
    }
 
    void createEditWindow(GroupEditor callee, boolean newWindow)
    {
       if (newWindow)
           objectUI = new LinkerEditor(this, deepCopy(), callee);
       else
           objectUI = new LinkerEditor(this, callee);
        editWindow = objectUI.GetEditor();
    }
 
    void draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
    {
        //if(count <= 0)
          //  return;
        
        if(display.DrawMode() == display.SELECTION || display.IsDebugSelection())
        {
            super.draw(display, root, selected, blocked);
            return;
        }
        
        //System.out.println("cLinker = " + this);
        //new Exception().printStackTrace();
            
        stack.push(cStatic.getVector()); // new cVector());
        
        if(stack.size() > 1)
        {
            cStatic.point7.set(stack.peek());
            /**/
            //javax.media.opengl.GL gl = display.GetGL();
       
            //gl.glBegin(gl.GL_LINES);
            //gl.glVertex3d(stack.peek().x, stack.peek().y, stack.peek().z);
            //System.out.println("line = " + stack.peek());
            cVector keep = stack.pop();
            //System.out.println("to = " + stack.peek());
            cStatic.point7.sub(stack.peek());
            //gl.glVertex3d(stack.peek().x, stack.peek().y, stack.peek().z);
            //gl.glEnd();
             /**/
            
            stack.push(keep);
            
            cStatic.point8.set(0,-1,0);
            
            int size = 12;
            
            if(cStatic.cone == null)
            {
                cStatic.box = new Box();
                cStatic.cone = new Cone[size];
                cStatic.sphere = new Sphere[size];
                
                for (int i=0; i<size; i++)
                {
                    cStatic.cone[i] = new Cone();
                    cStatic.cone[i].uDivs = 4 + i; // 8
                    cStatic.cone[i].vDivs = 1;
                    cStatic.cone[i].endcaps = false;
                    cStatic.cone[i].baseRadius = cStatic.cone[i].apexRadius = 1; // 0.125;
                    cStatic.cone[i].mode = 1;
                    cStatic.cone[i].retile();
                    cStatic.cone[i].recalculate();
 
                    cStatic.sphere[i] = new Sphere();
                    cStatic.sphere[i].uDivs = cStatic.cone[i].uDivs;
                    cStatic.sphere[i].vDivs = (cStatic.sphere[i].uDivs+1)/2;
                    cStatic.sphere[i].endcaps = false;
                 //   cStatic.sphere[i].radius = 1; // 0.125;
                    cStatic.sphere[i].mode = 1;
                    cStatic.sphere[i].retile();
                    cStatic.sphere[i].recalculate();
                }
            }
            
            int d = size - stack.size();
            
            if (d < 0)
                d = 0;
            
            //LA.matPrint(cStatic.cone1.toParent);
            
            /**/
            double h = cStatic.point7.length(); ///2;
            if(depth < 0)
                depth = 0;
            //System.out.println("h = " + h);
            LA.matIdentity(cStatic.matrix1);
            if(height < 0)
            {
                // Box mode
                LA.matRotate(cStatic.box.fromParent, cStatic.point8, cStatic.point7);
                LA.matRotate(cStatic.box.toParent, cStatic.point7, cStatic.point8);
                //System.out.println("height = " + height);
                LA.matScale(cStatic.matrix1, -height/8,h,-height/8);
                cStatic.matrix1[1][3] = -depth/10/h;
                LA.matConcat(cStatic.matrix1, cStatic.box.toParent, cStatic.box.toParent);
                //LA.matIdentity(cStatic.matrix1);
                //LA.matScale(cStatic.matrix1, -8/height,1/h,-8/height);
                LA.matInvert(cStatic.matrix1, cStatic.matrix2);
                LA.matConcat(cStatic.box.fromParent, cStatic.matrix2, cStatic.box.fromParent);
                cStatic.box.draw(display, root, selected, blocked);
            }
            else
            {
                LA.matRotate(cStatic.cone[d].toParent, cStatic.point7, cStatic.point8);
                LA.matRotate(cStatic.sphere[d].toParent, cStatic.point7, cStatic.point8);
            
                LA.matScale(cStatic.matrix1, height/8,h,height/8);
                cStatic.matrix1[1][3] = -depth/10/h;
                //System.out.println("h = " + h);
                //System.out.println("point = " + cStatic.point7);
                LA.matConcat(cStatic.matrix1, cStatic.cone[d].toParent, cStatic.cone[d].toParent);
                
                if (false) // TODO display.matrixdepth >= display.MAXSTACK)
                {
                    LA.matRotate(cStatic.cone[d].fromParent, cStatic.point8, cStatic.point7);
                    LA.matRotate(cStatic.sphere[d].fromParent, cStatic.point8, cStatic.point7);
 
                    LA.matInvert(cStatic.matrix1, cStatic.matrix2);
                    //LA.matIdentity(cStatic.matrix1);
                    //LA.matScale(cStatic.matrix1, 8/height,1/h,8/height);
                    LA.matConcat(cStatic.cone[d].fromParent, cStatic.matrix2, cStatic.cone[d].fromParent);
 
                    LA.matIdentity(cStatic.matrix1);
                    LA.matScale(cStatic.matrix1, 8/height,8/height,8/height);
                    LA.matConcat(cStatic.sphere[d].fromParent, cStatic.matrix1, cStatic.sphere[d].fromParent);
                }
                
                LA.matIdentity(cStatic.matrix1);
                LA.matScale(cStatic.matrix1, height/8,height/8,height/8);
                LA.matConcat(cStatic.matrix1, cStatic.sphere[d].toParent, cStatic.sphere[d].toParent);
 
                cStatic.cone[d].draw(display, root, selected, blocked);
                cStatic.sphere[d].draw(display, root, selected, blocked);
            }
        }
 
        super.draw(display, root, selected, blocked);
        
        // keep cache
        cStatic.vectors.add(stack.peek());
        
        stack.pop();
    }
 
    static java.util.Stack<cVector> stack = new java.util.Stack<cVector>();
}