/Users/lyon/j4p/src/ip/raul/ObjectView.java

1    package ip.raul; 
2     
3    import ip.gui.dialog.DoubleLog; 
4    import ip.gui.frames.ImageFrame; 
5     
6    import java.awt.*; 
7    import java.awt.event.*; 
8    import java.awt.image.ColorModel; 
9     
10    
11   public class ObjectView extends ImageFrame 
12           implements MouseListener, MouseMotionListener, WindowListener { 
13    
14       MenuBar mb = new MenuBar(); 
15       Menu SettingsMenu = new Menu("Settings"); 
16       Menu ProjectionMenu = new Menu("Projection"); 
17       Menu ParallelProjectionMenu = new Menu("Parallel"); 
18       Menu PerspectiveProjectionMenu = new Menu("Perspective"); 
19       Menu AxonometricParallelProjectionMenu = new Menu("Axonometric"); 
20    
21       MenuItem wireframe_mi = addMenuItem(SettingsMenu, "[w]ireframe..."); 
22       MenuItem textured_mi = addMenuItem(SettingsMenu, "[t]extured..."); 
23    
24       MenuItem orthometric_mi = addMenuItem(ParallelProjectionMenu, "[1] Orthometric"); 
25       MenuItem oblique_mi = addMenuItem(ParallelProjectionMenu, "[2] Oblique"); 
26       MenuItem trimetric_mi = addMenuItem(AxonometricParallelProjectionMenu, "[1] Trimetric"); 
27       MenuItem dimetric_mi = addMenuItem(AxonometricParallelProjectionMenu, "[2] Dimetric"); 
28       MenuItem isometric_mi = addMenuItem(AxonometricParallelProjectionMenu, "[3] Isometric"); 
29    
30       MenuItem _1point_mi = addMenuItem(PerspectiveProjectionMenu, "[1] 1 Point "); 
31       MenuItem _2point_mi = addMenuItem(PerspectiveProjectionMenu, "[2] 2 Point "); 
32       MenuItem _3point_mi = addMenuItem(PerspectiveProjectionMenu, "[3] 3 Point "); 
33    
34    
35       private short rn[][] = new short[0][0]; 
36       private short gn[][] = new short[0][0]; 
37       private short bn[][] = new short[0][0]; 
38       private ColorModel cm = ColorModel.getRGBdefault(); 
39       public Object3D objects[]; 
40       public int maxObjects; 
41       public String textures[]; 
42       public int maxTextures; 
43       public int view; 
44       public int projection = 1; 
45       public int mode = 1; 
46       public int index = -1; 
47       public boolean hidden = true; 
48       public boolean busy = false; 
49       private Image img = null; 
50       private Image img1 = null; 
51       private Graphics imgG = null; 
52    
53   //projection related variables 
54       private double theta = 0; 
55       private double thetaC = 0; 
56       private double thetaS = 0; 
57       private double phi = 0; 
58       private double phiC = 0; 
59       private double phiS = 0; 
60       private double xProj = 1; 
61       private double yProj = 1; 
62       private double zProj = 1; 
63       private double depthFactor = 1; 
64       private DoubleLog DLog = null; 
65   //until here 
66       private float xCenter = 150; 
67       private float yCenter = 150; 
68       private float xK = 100;//the default scaling factors, so that domains of -2..2 will show big enough 
69       private float yK = 100;//same thing 
70    
71       public void projectionEvent(ActionEvent e) { 
72           try { 
73               Button b = (Button) e.getSource(); 
74               if (b == DLog.setButton) { 
75                   double d[] = DLog.getUserInputAsDouble(); 
76                   if (projection == 2) { 
77                       theta = (double) (d[0] * Math.PI / 180d); 
78                       phi = (double) (d[1] * Math.PI / 180d); 
79                       thetaC = Math.cos(theta); 
80                       thetaS = Math.sin(theta); 
81                       phiC = Math.cos(phi); 
82                       phiS = Math.sin(phi); 
83                   } 
84                   if (projection == 3) { 
85                       phi = (double) (45 * Math.PI / 180d); 
86                       phiC = Math.cos(phi); 
87                       phiS = Math.sin(phi); 
88                       theta = (double) (d[0] * Math.PI / 180d); 
89                       thetaC = Math.cos(theta); 
90                       thetaS = Math.sin(theta); 
91                   } 
92                   if (projection == 4) { 
93                       switch ((int) d[0]) { 
94                           case 1: 
95                               theta = (double) (-35d * Math.PI / 180d); 
96                               phi = (double) (45d * Math.PI / 180d); 
97                               thetaC = Math.cos(theta); 
98                               thetaS = Math.sin(theta); 
99                               phiC = Math.cos(phi); 
100                              phiS = Math.sin(phi); 
101                              break; 
102                          case 2: 
103                              theta = (double) (35d * Math.PI / 180d); 
104                              phi = (double) (-45d * Math.PI / 180d); 
105                              thetaC = Math.cos(theta); 
106                              thetaS = Math.sin(theta); 
107                              phiC = Math.cos(phi); 
108                              phiS = Math.sin(phi); 
109                              break; 
110                          case 3: 
111                              theta = (double) (35d * Math.PI / 180d); 
112                              phi = (double) (45d * Math.PI / 180d); 
113                              thetaC = Math.cos(theta); 
114                              thetaS = Math.sin(theta); 
115                              phiC = Math.cos(phi); 
116                              phiS = Math.sin(phi); 
117                              break; 
118                          case 4: 
119                              theta = (double) (-35d * Math.PI / 180d); 
120                              phi = (double) (-45d * Math.PI / 180d); 
121                              thetaC = Math.cos(theta); 
122                              thetaS = Math.sin(theta); 
123                              phiC = Math.cos(phi); 
124                              phiS = Math.sin(phi); 
125                              break; 
126                          default: 
127                              System.out.println("Your option was not understood, 1 assumed"); 
128                              theta = (double) (-35d * Math.PI / 180d); 
129                              phi = (double) (45d * Math.PI / 180d); 
130                              thetaC = Math.cos(theta); 
131                              thetaS = Math.sin(theta); 
132                              phiC = Math.cos(phi); 
133                              phiS = Math.sin(phi); 
134                              break; 
135                      } 
136                  } 
137                  if ((projection == 6)) { 
138                      if (d[0] != 0) zProj = d[0]; 
139                      yProj = 1; 
140                      xProj = 1; 
141                  } 
142                  if ((projection == 7)) { 
143                      if (d[0] != 0) xProj = d[0]; 
144                      if (d[1] != 0) zProj = d[1]; 
145                      yProj = 1; 
146                  } 
147                  if ((projection == 8)) { 
148                      if (d[0] != 0) xProj = d[0]; 
149                      if (d[1] != 0) yProj = d[1]; 
150                      if (d[2] != 0) zProj = d[2]; 
151                  } 
152                  repaint(); 
153              } 
154          } catch (Exception ex) { 
155          } 
156   
157          if (match(e, orthometric_mi)) { 
158              projection = 1; 
159              repaint(); 
160              return; 
161          } 
162          if (match(e, trimetric_mi)) { 
163              trimetricView(); 
164              return; 
165          } 
166          if (match(e, dimetric_mi)) { 
167              dimetricView(); 
168              return; 
169          } 
170          if (match(e, isometric_mi)) { 
171              isometricView(); 
172              return; 
173          } 
174          if (match(e, oblique_mi)) { 
175              projection = 5; 
176              repaint(); 
177              return; 
178          } 
179          if (match(e, _1point_mi)) { 
180              _1pointView(); 
181              return; 
182          } 
183          if (match(e, _2point_mi)) { 
184              _2pointView(); 
185              return; 
186          } 
187          if (match(e, _3point_mi)) { 
188              _3pointView(); 
189              return; 
190          } 
191      } 
192   
193      public void trimetricView() { 
194          String prompts[] = {"Theta (degrees)", "Phi (degrees)"}; 
195          String defaults[] = {"0.0", "0.0"}; 
196          DLog = new DoubleLog(this, 
197                  "Trimetric Projection Dialog", prompts, defaults, 6); 
198          DLog.setVisible(true); 
199          DLog.setButton.addActionListener(this); 
200          projection = 2; 
201          repaint(); 
202      } 
203   
204      public void dimetricView() { 
205          String prompts[] = {"Theta (degrees)"}; 
206          String defaults[] = {"0.0"}; 
207          DLog = new DoubleLog(this, 
208                  "Dimetric Projection Dialog", prompts, defaults, 6); 
209          DLog.setVisible(true); 
210          DLog.setButton.addActionListener(this); 
211          projection = 3; 
212          repaint(); 
213      } 
214   
215      public void isometricView() { 
216          System.out.println("Please select from the dialog one of the values:"); 
217          System.out.println("1: Theta=-45, Phi=35"); 
218          System.out.println("2: Theta=45, Phi=-35"); 
219          System.out.println("3: Theta=45, Phi=35"); 
220          System.out.println("4: Theta=-45, Phi=-35"); 
221          String prompts[] = {"Choose 1, 2, 3 or 4"}; 
222          String defaults[] = {"1"}; 
223          DLog = new DoubleLog(this, 
224                  "Isometric Projection Dialog", prompts, defaults, 6); 
225          DLog.setVisible(true); 
226          DLog.setButton.addActionListener(this); 
227          projection = 4; 
228          repaint(); 
229      } 
230   
231      public void _1pointView() { 
232          String prompts[] = {"Z = "}; 
233          String defaults[] = {"1.0"}; 
234          DLog = new DoubleLog(this, 
235                  "1 Point Projection Dialog", prompts, defaults, 6); 
236          DLog.setVisible(true); 
237          DLog.setButton.addActionListener(this); 
238          projection = 6; 
239          repaint(); 
240      } 
241   
242      public void _2pointView() { 
243          String prompts[] = {"X = ", "Z = "}; 
244          String defaults[] = {"1.0", "1.0"}; 
245          DLog = new DoubleLog(this, 
246                  "2 Point Projection Dialog", prompts, defaults, 6); 
247          DLog.setVisible(true); 
248          DLog.setButton.addActionListener(this); 
249          projection = 7; 
250          repaint(); 
251      } 
252   
253      public void _3pointView() { 
254          String prompts[] = {"X = ", "Y = ", "Z = "}; 
255          String defaults[] = {"1.0", "1.0", "1.0"}; 
256          DLog = new DoubleLog(this, 
257                  "3 Point Projection Dialog", prompts, defaults, 6); 
258          DLog.setVisible(true); 
259          DLog.setButton.addActionListener(this); 
260          projection = 8; 
261          repaint(); 
262      } 
263   
264      public void actionPerformed(ActionEvent e) { 
265          projectionEvent(e); 
266          if (match(e, wireframe_mi)) { 
267              mode = 1; 
268              repaint(); 
269              return; 
270          } 
271          if (match(e, textured_mi)) { 
272              mode = 2; 
273              repaint(); 
274              return; 
275          } 
276          super.actionPerformed(e); 
277      } 
278   
279      ObjectView(String title, Object3D _objects[], int _maxObjects, String _textures[], int _maxTextures, int _view) { 
280          super(title); 
281          objects = _objects; 
282          textures = _textures; 
283          maxTextures = _maxTextures; 
284          maxObjects = _maxObjects; 
285          view = _view; 
286          addMouseListener(this); 
287          addMouseMotionListener(this); 
288          addWindowListener(this); 
289   
290          ProjectionMenu.add(ParallelProjectionMenu); 
291          ProjectionMenu.add(PerspectiveProjectionMenu); 
292          ParallelProjectionMenu.add(AxonometricParallelProjectionMenu); 
293          mb.add(SettingsMenu); 
294          mb.add(ProjectionMenu); 
295          setMenuBar(mb); 
296          setSize(300, 300); 
297          hidden = false; 
298   
299      } 
300   
301      private void init() { 
302      } 
303   
304      public void update(Graphics g) { 
305          paint(g); 
306      } 
307   
308   
309      private void Line3D(Point3D p1, Point3D p2, Graphics g) { 
310          Point q1 = get2Dfrom3D(p1); 
311          Point q2 = get2Dfrom3D(p2); 
312          g.drawLine(q1.x, q1.y, q2.x, q2.y); 
313      } 
314   
315      private void setPoint3D(Point3D p, short r1, short g1, short b1, Graphics g) { 
316          Point q = get2Dfrom3D(p); 
317          g.setColor(new Color(r1, g1, b1)); 
318          g.drawLine(q.x, q.y, q.x, q.y); 
319      } 
320   
321      int Dist(Point a, Point b) { 
322          return (int) (Math.sqrt(((b.x - a.x) * (b.x - a.x)) + ((b.y - a.y) * (b.y - a.y)))); 
323      } 
324   
325      private Point3D getProjection(Point3D p) { 
326          float tmp = 0; 
327          Point3D _p = new Point3D(0, 0, 0); 
328          switch (projection) { 
329              case 1: 
330                  _p = p; 
331                  break; 
332              case 2: 
333                  _p = p; 
334                  if (thetaS != 0) { 
335                      _p.x = p.x + (float) (p.z * phiC * thetaC / thetaS); 
336                      _p.y = p.y + (float) (p.z * phiS * thetaC / thetaS); 
337                  } 
338                  break; 
339              case 3: 
340                  _p = p; 
341                  if (thetaS != 0) { 
342                      _p.x = p.x + (float) (p.z * phiC * thetaC / thetaS); 
343                      _p.y = p.y + (float) (p.z * phiS * thetaC / thetaS); 
344                  } 
345                  break; 
346              case 4: 
347                  _p = p; 
348                  if (thetaS != 0) { 
349                      _p.x = p.x + (float) (p.z * phiC * thetaC / thetaS); 
350                      _p.y = p.y + (float) (p.z * phiS * thetaC / thetaS); 
351                  } 
352                  break; 
353              case 5: 
354                  break; 
355              case 6: 
356                  depthFactor = -(p.z / zProj) + 1; 
357                  _p.x = (float) (p.x / depthFactor); 
358                  _p.y = (float) (p.y / depthFactor); 
359                  _p.z = p.z; 
360                  break; 
361              case 7: 
362                  depthFactor = (-p.x / xProj) - (p.z / zProj) + 1; 
363                  _p.x = (float) (p.x / depthFactor); 
364                  _p.y = (float) (p.y / depthFactor); 
365                  _p.z = p.z; 
366                  break; 
367              case 8: 
368                  depthFactor = -(p.x / xProj) - (p.y / yProj) - (p.z / zProj) + 1; 
369                  _p.x = (float) (p.x / depthFactor); 
370                  _p.y = (float) (p.y / depthFactor); 
371                  _p.z = p.z; 
372                  break; 
373          } 
374          return (_p); 
375      } 
376   
377      private Point get2Dfrom3D(Point3D p) { 
378          Point3D pp = new Point3D(0, 0, 0); 
379          switch (view) { 
380              case 1://front 
381                  pp.x = p.x; 
382                  pp.y = -p.z; 
383                  pp.z = p.y; 
384                  break; 
385              case 2://back 
386                  pp.x = -p.x; 
387                  pp.y = -p.z; 
388                  pp.z = -p.y; 
389                  break; 
390              case 3://top 
391                  pp.x = p.x; 
392                  pp.y = -p.y; 
393                  pp.z = p.z; 
394                  break; 
395              case 4://bottom 
396                  pp.x = p.x; 
397                  pp.y = p.y; 
398                  pp.z = -p.z; 
399                  break; 
400              case 5://left 
401                  pp.x = -p.y; 
402                  pp.y = -p.z; 
403                  pp.z = p.x; 
404                  break; 
405              case 6://right 
406                  pp.x = p.y; 
407                  pp.y = -p.z; 
408                  pp.z = -p.x; 
409                  break; 
410          } 
411          pp = getProjection(pp); 
412          pp.x = xCenter + pp.x * xK; 
413          pp.y = yCenter + pp.y * yK; 
414          return new Point((int) pp.x, (int) pp.y); 
415      } 
416   
417      private Point3D get3Dfrom2D(Point q) { 
418          float xx1 = 0; 
419          float yy1 = 0; 
420          float zz1 = 0; 
421          float x = 0; 
422          float y = 0; 
423          x = q.x; 
424          y = q.y; 
425          x = x - xCenter; 
426          y = y - yCenter; 
427          x = (float) (x / xK); 
428          y = (float) (y / yK); 
429          switch (view) { 
430              case 1://front 
431                  xx1 = x; 
432                  zz1 = -y; 
433                  break; 
434              case 2://back 
435                  xx1 = -x; 
436                  zz1 = -y; 
437                  break; 
438              case 3://top 
439                  xx1 = x; 
440                  yy1 = -y; 
441                  break; 
442              case 4://bottom 
443                  xx1 = x; 
444                  yy1 = y; 
445                  break; 
446              case 5://left 
447                  yy1 = -x; 
448                  zz1 = -y; 
449                  break; 
450              case 6://right 
451                  yy1 = x; 
452                  zz1 = -y; 
453                  break; 
454          } 
455          return new Point3D(xx1, yy1, zz1); 
456      } 
457   
458      private void drawSphere(Object3D o, Graphics g1, int mode) { 
459          float Radius = o.Radius; 
460          float deltaTheta = (float) ((float) Math.PI / 9f); 
461          float sini, cosi, sinj, cosj; 
462          Point3D s[][] = new Point3D[18][18]; 
463          switch (mode) { 
464              case 1: 
465                  for (int i = 0; i < 18; i++) 
466                      for (int j = -8; j < 10; j++) { 
467                          sini = (float) Math.sin((float) (i * deltaTheta)); 
468                          cosi = (float) Math.cos((float) (i * deltaTheta)); 
469                          sinj = (float) Math.sin((float) (j * deltaTheta)); 
470                          cosj = (float) Math.cos((float) (j * deltaTheta)); 
471                          float x = o.Pos.x + (float) (Radius * cosi * sinj); 
472                          float y = o.Pos.y + (float) (Radius * sini * sinj); 
473                          float z = o.Pos.z + (float) (Radius * cosj); 
474                          s[i][j + 8] = new Point3D(x, y, z); 
475                      } 
476                  for (int i = 0; i < 17; i++) 
477                      for (int j = 0; j < 17; j++) { 
478                          Line3D(s[i][j], s[i + 1][j], g1); 
479                          Line3D(s[i + 1][j], s[i + 1][j + 1], g1); 
480                      } 
481                  break; 
482              case 2: 
483                  break; 
484          } 
485      } 
486   
487   
488      private void drawCylinder(Object3D o, Graphics g1, int mode) { 
489          float Radius = o.Radius; 
490          float Height = o.Height; 
491          float deltaTheta = (float) ((float) Math.PI / 8.5f); 
492          float sini, cosi; 
493          Point3D s[][] = new Point3D[18][10]; 
494          switch (mode) { 
495              case 1: 
496                  for (int i = 0; i < 18; i++) 
497                      for (int j = 0; j < 10; j++) { 
498                          sini = (float) Math.sin((float) (i * deltaTheta)); 
499                          cosi = (float) Math.cos((float) (i * deltaTheta)); 
500                          float x = o.Pos.x + (float) (Radius * cosi); 
501                          float y = o.Pos.y + (float) (Height * j / 9f); 
502                          float z = o.Pos.z + (float) (Radius * sini); 
503                          s[i][j] = new Point3D(x, y, z); 
504                      } 
505                  for (int i = 0; i < 17; i++) { 
506                      for (int j = 0; j < 9; j++) { 
507                          Line3D(s[i][j], s[i + 1][j], g1); 
508                          Line3D(s[i + 1][j], s[i + 1][j + 1], g1); 
509                      } 
510                      Line3D(s[i][9], s[i + 1][9], g1); 
511                  } 
512                  break; 
513              case 2: 
514                  break; 
515          } 
516      } 
517   
518      private void drawParalelipiped(Object3D o, Graphics g1, int mode) { 
519          float W = o.Width; 
520          float H = o.Height; 
521          float L = o.Length; 
522          float x, y, z; 
523          Point3D s[][] = new Point3D[4][2]; 
524          switch (mode) { 
525              case 1: 
526                  x = o.Pos.x - (float) (W / 2f); 
527                  y = o.Pos.y - (float) (H / 2f); 
528                  z = o.Pos.z - (float) (L / 2f); 
529                  s[0][0] = new Point3D(x, y, z); 
530                  x = o.Pos.x + (float) (W / 2f); 
531                  s[1][0] = new Point3D(x, y, z); 
532                  z = o.Pos.z + (float) (L / 2f); 
533                  s[2][0] = new Point3D(x, y, z); 
534                  x = o.Pos.x - (float) (W / 2f); 
535                  s[3][0] = new Point3D(x, y, z); 
536   
537                  y = o.Pos.y + (float) (H / 2f); 
538                  s[3][1] = new Point3D(x, y, z); 
539                  x = o.Pos.x + (float) (W / 2f); 
540                  s[2][1] = new Point3D(x, y, z); 
541                  z = o.Pos.z - (float) (L / 2f); 
542                  s[1][1] = new Point3D(x, y, z); 
543                  x = o.Pos.x - (float) (W / 2f); 
544                  s[0][1] = new Point3D(x, y, z); 
545                  //upper face 
546                  Line3D(s[0][0], s[1][0], g1); 
547                  Line3D(s[1][0], s[2][0], g1); 
548                  Line3D(s[2][0], s[3][0], g1); 
549                  Line3D(s[3][0], s[0][0], g1); 
550                  //down face 
551                  Line3D(s[0][1], s[1][1], g1); 
552                  Line3D(s[1][1], s[2][1], g1); 
553                  Line3D(s[2][1], s[3][1], g1); 
554                  Line3D(s[3][1], s[0][1], g1); 
555                  //lateral stuff 
556                  Line3D(s[0][0], s[0][1], g1); 
557                  Line3D(s[1][0], s[1][1], g1); 
558                  Line3D(s[2][0], s[2][1], g1); 
559                  Line3D(s[3][0], s[3][1], g1); 
560                  break; 
561              case 2: 
562                  break; 
563          } 
564      } 
565   
566   
567      private void drawAxes(Graphics g1, Rectangle r) { 
568          switch (view) { //Axes 
569              case 1: //front 
570                  g1.drawLine(30, r.height - 30, 20, r.height - 20); 
571                  g1.drawLine(20, r.height - 20, 20, r.height - 30); 
572                  g1.drawLine(20, r.height - 20, 30, r.height - 20); 
573                  g1.drawString("z", 18, r.height - 32); 
574                  g1.drawString("x", 32, r.height - 18); 
575                  g1.drawString("y", 32, r.height - 32); 
576                  break; 
577              case 2://back 
578                  g1.drawLine(12, r.height - 12, 20, r.height - 20); 
579                  g1.drawLine(20, r.height - 20, 20, r.height - 30); 
580                  g1.drawLine(20, r.height - 20, 10, r.height - 20); 
581                  g1.drawString("z", 18, r.height - 32); 
582                  g1.drawString("x", 6, r.height - 18); 
583                  g1.drawString("y", 6, r.height - 6); 
584                  break; 
585              case 3://top 
586                  g1.drawLine(12, r.height - 12, 20, r.height - 20); 
587                  g1.drawLine(20, r.height - 20, 20, r.height - 30); 
588                  g1.drawLine(20, r.height - 20, 30, r.height - 20); 
589                  g1.drawString("y", 18, r.height - 32); 
590                  g1.drawString("x", 32, r.height - 18); 
591                  g1.drawString("z", 6, r.height - 6); 
592                  break; 
593              case 4://bottom 
594                  g1.drawLine(30, r.height - 30, 20, r.height - 20); 
595                  g1.drawLine(20, r.height - 20, 20, r.height - 10); 
596                  g1.drawLine(20, r.height - 20, 30, r.height - 20); 
597                  g1.drawString("y", 22, r.height - 6); 
598                  g1.drawString("x", 32, r.height - 18); 
599                  g1.drawString("z", 32, r.height - 32); 
600                  break; 
601              case 5://left 
602                  g1.drawLine(30, r.height - 30, 20, r.height - 20); 
603                  g1.drawLine(20, r.height - 20, 20, r.height - 30); 
604                  g1.drawLine(20, r.height - 20, 10, r.height - 20); 
605                  g1.drawString("z", 18, r.height - 32); 
606                  g1.drawString("y", 6, r.height - 18); 
607                  g1.drawString("x", 32, r.height - 32); 
608                  break; 
609              case 6://right 
610                  g1.drawLine(12, r.height - 12, 20, r.height - 20); 
611                  g1.drawLine(20, r.height - 20, 20, r.height - 30); 
612                  g1.drawLine(20, r.height - 20, 30, r.height - 20); 
613                  g1.drawString("z", 18, r.height - 32); 
614                  g1.drawString("y", 32, r.height - 18); 
615                  g1.drawString("x", 6, r.height - 6); 
616                  break; 
617          } 
618          switch (projection) { 
619              case 1: 
620                  g1.drawString("orthometric", 40, r.height - 16); 
621                  break; 
622              case 2: 
623                  g1.drawString("trimetric", 40, r.height - 16); 
624                  break; 
625              case 3: 
626                  g1.drawString("dimetric", 40, r.height - 16); 
627                  break; 
628              case 4: 
629                  g1.drawString("isometric", 40, r.height - 16); 
630                  break; 
631              case 5: 
632                  g1.drawString("oblique", 40, r.height - 16); 
633                  break; 
634              case 6: 
635                  g1.drawString("1 point", 40, r.height - 16); 
636                  break; 
637              case 7: 
638                  g1.drawString("2 point", 40, r.height - 16); 
639                  break; 
640              case 8: 
641                  g1.drawString("3 point", 40, r.height - 16); 
642                  break; 
643          } 
644      } 
645   
646      double linearY(double x1, double x2, double t) { 
647          double dx = 0; 
648          dx = (double) (x2 - x1); 
649          return (double) (x1 + (double) (dx * t)); 
650      } 
651   
652      public void paint(Graphics g) { 
653          Rectangle r = getBounds(); 
654          img = createImage(r.width, r.height); 
655          imgG = img.getGraphics(); 
656   
657          xCenter = (float) (r.width / 2); 
658          yCenter = (float) (r.height / 2); 
659          xK = (float) (r.width / 3); 
660          yK = (float) (r.height / 3); 
661          for (int i = 0; i <= maxObjects; i++) { 
662              if ((i == index) && (busy)) 
663                  imgG.setColor(new Color(255, 0, 0)); 
664              else 
665                  imgG.setColor(new Color(0, 0, 0)); 
666              switch (objects[i].Type) { 
667                  case 1: 
668                      drawSphere(objects[i], imgG, mode); 
669                      break; 
670                  case 2: 
671                      drawCylinder(objects[i], imgG, mode); 
672                      break; 
673                  case 3: 
674                      drawParalelipiped(objects[i], imgG, mode); 
675                      break; 
676              } 
677          } 
678          imgG.setColor(new Color(0, 0, 0)); 
679          drawAxes(imgG, r); 
680          if (img != null) { 
681              g.drawImage(img, 0, 0, r.width, r.height, this); 
682          } 
683      } 
684   
685      public void mouseDragged(MouseEvent e) { 
686          e.consume(); 
687          double dx = getX(e); 
688          double dy = getY(e); 
689          double sx = 0; 
690          double sy = 0; 
691          double ray = 100000; 
692          if (!busy) { 
693              busy = true; 
694              index = -1; 
695              for (int i = 0; i <= maxObjects; i++) { 
696                  Point s = get2Dfrom3D(objects[i].Pos); 
697                  sx = (double) s.x; 
698                  sy = (double) s.y; 
699                  sx = sx - dx; 
700                  sx = sx * sx; 
701                  sy = sy - dy; 
702                  sy = sy * sy; 
703                  if ((sx + sy) < ray) { 
704                      ray = sx + sy; 
705                      index = i; 
706                  } 
707              } 
708          } 
709          if (index != -1) { 
710              objects[index].Pos = get3Dfrom2D(new Point((int) dx, (int) dy)); 
711              repaint(); 
712              return; 
713          } 
714      } 
715   
716      private int getX(MouseEvent e) { 
717          return (int) (e.getX()); 
718      } 
719   
720      private int getY(MouseEvent e) { 
721          return (int) (e.getY()); 
722      } 
723   
724      public void mouseReleased(MouseEvent e) { 
725          busy = false; 
726          repaint(); 
727      } 
728   
729      public void mousePressed(MouseEvent e) { 
730      } 
731   
732      public void mouseExited(MouseEvent e) { 
733      } 
734   
735      public void mouseEntered(MouseEvent e) { 
736      } 
737   
738      public void mouseClicked(MouseEvent e) { 
739      } 
740   
741   
742      public void mouseMoved(MouseEvent e) { 
743      } 
744   
745      public void windowClosing(WindowEvent e) { 
746          hidden = true; 
747          dispose(); 
748      } 
749   
750      public void windowClosed(WindowEvent e) { 
751      }; 
752      public void windowDeiconified(WindowEvent e) { 
753      }; 
754      public void windowIconified(WindowEvent e) { 
755      }; 
756      public void windowActivated(WindowEvent e) { 
757      }; 
758      public void windowDeactivated(WindowEvent e) { 
759      }; 
760      public void windowOpened(WindowEvent e) { 
761      }; 
762   
763  }