-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzome3d.java
2551 lines (2070 loc) · 98.9 KB
/
zome3d.java
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// By C.W. Bennett
// 05/24/02
//
// Best viewed with WordPad, no Wrap
//
// This Program create the the 3D scene and
// handles most of the user interaction
// Utilizes kitUI, and zomeUI
//////////////////////////////////////
// Java Core
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
// Java Swing
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.JOptionPane;
import javax.swing.JDialog;
//Property change stuff
import java.beans.*;
// Applet stuff
import java.applet.*;
import java.applet.Applet;
// utility libraries
import java.util.Enumeration;
import java.util.Arrays;
// Java3D
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.image.TextureLoader;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.behaviors.mouse.*;
import com.sun.j3d.utils.picking.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
// URL handling
import java.net.URL;
import java.net.MalformedURLException;
public class zome3d extends JPanel implements ActionListener, MouseListener, MouseMotionListener
{
//-----------------------------------------------------------------------------------------------------
// ATTRIBUTE CONSTANTS - One stop shop for changing the settings
//-----------------------------------------------------------------------------------------------------
// the maximum number of components ( strut-balls or struts )
private static final int MAXITEMS = 500;
// These attributes should keep the same ratio (else the balls and struts will not
// align properly)
private static final double BALLSCALE = 0.0316; // Size of the ball
private static final int STRUTSCALE = 6; // Size of the Strut
private static final int POSTSCALE = 3; // Scalar for the positions
private static final double HIGHLIGHTSCALE = 1.50; // Use to set the size of the ball highlight
// Utility Colors
private static final Color3f WHITE = new Color3f(1.0f, 1.0f, 1.0f);
private static final Color3f LGREY = new Color3f(8.0f, 8.0f, 8.0f);
private static final Color3f GREY = new Color3f(5.0f, 5.0f, 5.0f);
private static final Color3f BLACK = new Color3f(0.0f, 0.0f, 0.0f);
private static final Color3f AMBIENT = new Color3f(0.2f, 0.2f, 0.2f);
// Strut Colors
private static final Color3f BLUE = new Color3f(0.0f, 0.0f, 1.0f);
private static final Color3f RED = new Color3f(1.0f, 0.0f, 0.0f);
private static final Color3f YELLOW = new Color3f(1.0f, 0.8f, 0.0f);
// BackGround Colors
private static final Color3f SKY = new Color3f(0.4f, 0.7f, 0.9f);
private static final Color3f DARKSKY = new Color3f(0.1f, 0.19f, 0.21f );
// Highlight Colors
private static final Color3f LHIGHLIGHT = new Color3f(0.0f, 1.0f, 0.0f );
private static final Color3f DHIGHLIGHT = new Color3f(0.1f, 0.2f, 0.0f );
// Light Color
private static final Color3f LIGHT = WHITE;
private static final float BACKGROUNDSIZE = 200.0f; // the size of the backgrouns sphere
private static final float BACKGROUNDSHINE = 64.0f; // the magnitude of the background shine (0-128)
private static final float ACTIVATIONRADIUS = 100.0f; // the activation radius of the view
private static final int CANVASWIDTH = 300; // the intial size of the canvas
private static final int CANVASHEIGHT = 300; // these dont really matter as the canvas size is
// Usurped by the frame layout
// the main light direction
private static final Vector3f LIGHTDIRECTION = new Vector3f( 1.0f, -1.0f, -1.0f );
// the location of the point light and its atenuation - unsused as of now
private static final Point3f LIGHTLOCATION = new Point3f( -20.0f,-20.0f,-20.0f );
private static final Point3f LIGHTATTENUATION = new Point3f( 1.0f, 0.0f, 0.0f );
private static final float PHANTOMTRANSPARENCY = 0.6f; // transparency of phantom objects (0-1)
private static final float HIGHLIGHTTRANSPARENCY = 0.6f; // transparency of phantom objects (0-1)
private static final float HIGHLIGHTSIZE = 0.6f; // Highlight size
private static final int CREASEANGLE = 5; // controls how sharp the edges are on the ball and struts
// a higher number will smooth the edges
//-----------------------------------------------------------------------------------------------------
// FINAL CONSTANTS - DO NOT CHANGE!!
//-----------------------------------------------------------------------------------------------------
// the Golden Ratio and the Golden Ratio squared
private static final double TAU = 1.618034;
private static final double TAU2 = 2.618034;
private static final float TAUF = 1.6180339887499f;
// Strut widths
private static final float SIDE = 0.0450849710000f;
private static final float SIDE2 = TAUF * SIDE;
// Yellow Strut Constants
private static final float SHORTYELLOWLENGTH = .866025f;
private static final float YELLOWRADIUS = .118308f;
private static final float COS60F = .500000f;
private static final float SIN60F = .866025f;
// Red Strut Constants
private static final float SHORTREDLENGTH = .951057f;
private static final float REDRADIUS = .119581f;
// X, Y, Z coordinates
private static final int X = 0;
private static final int Y = 1;
private static final int Z = 2;
// Shape constants
private static final int RECT = 0;
private static final int TRI = 1;
private static final int PENT = 2;
// Length constants
private static final int SHORT = 0;
private static final int MED = 1;
private static final int LONG = 2;
// the endpoints of a strut
private static final int START = 0;
private static final int END = 1;
// Used by addOrder
private static final int BALL = 1;
private static final int STRUT = 2;
// The cardinal axes
private static final Vector3d XAXIS = new Vector3d( 1.0, 0.0, 0.0 );
private static final Vector3d YAXIS = new Vector3d( 0.0, 1.0, 0.0 );
private static final Vector3d ZAXIS = new Vector3d( 0.0, 0.0, 1.0 );
// phantom states
public static final boolean GHOST = true;
public static final boolean REAL = false;
// common strings
public static final String HIGHLIGHT = new String("highlight");
public static final String PHANTOM = new String("phantom");
// reset transform (used to clear transforms)
public static final Transform3D RESET = new Transform3D();
// Used to change the current kit message
private static final String[] KITMESSAGE = { "Pioneer Kit!!!",
"Adventurer Kit!!!",
"Explorer Kit!!!",
"Creator Kit!!!",
"Advanced Math Kit!!!" };
// The number of parts in each kit (advanced math is maxed so anything greater than the creator kit will
// show advanced math kit)
private static final int[][] KIT = { { 25, 16, 10, 6 }, { 50, 32, 20, 12 }, { 100, 64, 40, 24 },
{200, 128, 80, 48 }, { 500, 500, 500, 500 } };
//-----------------------------------------------------------------------------------------------------
// Ball Positions (from origin)
// NOTE: All numbers should be halved if the base length is 1.0
// R = Rectangle T = Triangle P = Pentagon
// A = TAU component B = integer component
// S = Short M = Medium L = Long
//-----------------------------------------------------------------------------------------------------
// Rectangle 0 1 2 3 4 5
// x y z x y z x y z x y z x y z x y z
private static final int[][] ASR = {{ 0, 0, 0},{-1, 0, 1},{ 1, 0, 1},{ 1, 0, 1},{-1, 0, 1},{ 0, 1, 1},
{ 0, 1, 1},{ 1, 1, 0},{ 1,-1, 0},{ 0,-1, 1},{ 0,-1, 1},{-1,-1, 0},
{-1, 1, 0},{ 0, 0, 0},{ 0, 0, 0},{ 0, 0, 0},{ 0, 0, 0},{ 0, 1,-1},
{ 1, 1, 0},{ 1,-1, 0},{ 0,-1,-1},{ 0,-1,-1},{-1,-1, 0},{-1, 1, 0},
{ 0, 1,-1},{ 1, 0,-1},{ 1, 0,-1},{-1, 0,-1},{-1, 0,-1},{ 0, 0, 0}};
private static final int[][] BSR = {{ 0, 0, 2},{ 1, 1, 0},{-1, 1, 0},{-1,-1, 0},{ 1,-1, 0},{-1, 0,-1},
{ 1, 0,-1},{ 0,-1, 1},{ 0, 1, 1},{ 1, 0,-1},{-1, 0,-1},{ 0, 1, 1},
{ 0,-1, 1},{ 0, 2, 0},{ 2, 0, 0},{ 0,-2, 0},{-2, 0, 0},{ 1, 0, 1},
{ 0,-1,-1},{ 0, 1,-1},{ 1, 0, 1},{-1, 0, 1},{ 0, 1,-1},{ 0,-1,-1},
{-1, 0, 1},{-1, 1, 0},{-1,-1, 0},{ 1,-1, 0},{ 1, 1, 0},{ 0, 0,-2}};
private static final int[][] AMR = {{ 0, 0, 2},{ 0, 1, 1},{ 0, 1, 1},{ 0,-1, 1},{ 0,-1, 1},{-1, 1, 0},
{ 1, 1, 0},{ 1, 0, 1},{ 1, 0, 1},{ 1,-1, 0},{-1,-1, 0},{-1, 0, 1},
{-1, 0, 1},{ 0, 2, 0},{ 2, 0, 0},{ 0,-2, 0},{-2, 0, 0},{ 1, 1, 0},
{ 1, 0,-1},{ 1, 0,-1},{ 1,-1, 0},{-1,-1, 0},{-1, 0,-1},{-1, 0,-1},
{-1, 1, 0},{ 0, 1,-1},{ 0,-1,-1},{ 0,-1,-1},{ 0, 1,-1},{ 0, 0,-2}};
private static final int[][] BMR = {{ 0, 0, 0},{-1, 0, 1},{ 1, 0, 1},{ 1, 0, 1},{-1, 0, 1},{ 0, 1, 1},
{ 0, 1, 1},{ 1, 1, 0},{ 1,-1, 0},{ 0,-1, 1},{ 0,-1, 1},{-1,-1, 0},
{-1, 1, 0},{ 0, 0, 0},{ 0, 0, 0},{ 0, 0, 0},{ 0, 0, 0},{ 0, 1,-1},
{ 1, 1, 0},{ 1,-1, 0},{ 0,-1,-1},{ 0,-1,-1},{-1,-1, 0},{-1, 1, 0},
{ 0, 1,-1},{ 1, 0,-1},{ 1, 0,-1},{-1, 0,-1},{-1, 0,-1},{ 0, 0, 0}};
private static final int[][] ALR = {{ 0, 0, 2},{-1, 1, 2},{ 1, 1, 2},{ 1,-1, 2},{-1,-1, 2},{-1, 2, 1},
{ 1, 2, 1},{ 2, 1, 1},{ 2,-1, 1},{ 1,-2, 1},{-1,-2, 1},{-2,-1, 1},
{-2, 1, 1},{ 0, 2, 0},{ 2, 0, 0},{ 0,-2, 0},{-2, 0, 0},{ 1, 2,-1},
{ 2, 1,-1},{ 2,-1,-1},{ 1,-2,-1},{-1,-2,-1},{-2,-1,-1},{-2, 1,-1},
{-1, 2,-1},{ 1, 1,-2},{ 1,-1,-2},{-1,-1,-2},{-1, 1,-2},{ 0, 0,-2}};
private static final int[][] BLR = {{ 0, 0, 2},{ 0, 1, 1},{ 0, 1, 1},{ 0,-1, 1},{ 0,-1, 1},{-1, 1, 0},
{ 1, 1, 0},{ 1, 0, 1},{ 1, 0, 1},{ 1,-1, 0},{-1,-1, 0},{-1, 0, 1},
{-1, 0, 1},{ 0, 2, 0},{ 2, 0, 0},{ 0,-2, 0},{-2, 0, 0},{ 1, 1, 0},
{ 1, 0,-1},{ 1, 0,-1},{ 1,-1, 0},{-1,-1, 0},{-1,-0,-1},{-1, 0,-1},
{-1, 1, 0},{ 0, 1,-1},{ 0,-1,-1},{ 0,-1,-1},{ 0, 1,-1},{ 0, 0,-2}};
//-----------------------------------------------------------------------------------------------------
// Triangle 0 1 2 3 4
// x y z x y z x y z x y z x y z
private static final int[][] AST = {{ 0, 1, 1},{ 0,-1, 1},{ 0, 0, 0},{ 0, 0, 0},{ 1, 0, 1},
{ 0, 0, 0},{ 0, 0, 0},{-1, 0, 1},{-1, 1, 0},{ 1, 1, 0},
{ 1,-1, 0},{-1,-1, 0},{ 0, 0, 0},{ 0, 0, 0},{ 1, 0,-1},
{ 0, 0, 0},{ 0, 0, 0},{-1, 0,-1},{ 0, 1,-1},{ 0,-1,-1}};
private static final int[][] BST = {{ 0,-1, 0},{ 0, 1, 0},{-1, 1, 1},{ 1, 1, 1},{ 0, 0,-1},
{ 1,-1, 1},{-1,-1, 1},{ 0, 0,-1},{ 1, 0, 0},{-1, 0, 0},
{-1, 0, 0},{ 1, 0, 0},{-1, 1,-1},{ 1, 1,-1},{ 0, 0, 1},
{ 1,-1,-1},{-1,-1,-1},{ 0, 0, 1},{ 0,-1, 0},{ 0, 1, 0}};
private static final int[][] AMT = {{ 0, 0, 1},{ 0, 0, 1},{-1, 1, 1},{ 1, 1, 1},{ 1, 0, 0},
{ 1,-1, 1},{-1,-1, 1},{-1, 0, 0},{ 0, 1, 0},{ 0, 1, 0},
{ 0,-1, 0},{ 0,-1, 0},{-1, 1,-1},{ 1, 1,-1},{ 1, 0, 0},
{ 1,-1,-1},{-1,-1,-1},{-1, 0, 0},{ 0, 0,-1},{ 0, 0,-1}};
private static final int[][] BMT = {{ 0, 1, 1},{ 0,-1, 1},{ 0, 0, 0},{ 0, 0, 0},{ 1, 0, 1},
{ 0, 0, 0},{ 0, 0, 0},{-1, 0, 1},{-1, 1, 0},{ 1, 1, 0},
{ 1,-1, 0},{-1,-1, 0},{ 0, 0, 0},{ 0, 0, 0},{ 1, 0,-1},
{ 0, 0, 0},{ 0, 0, 0},{-1, 0,-1},{ 0, 1,-1},{ 0,-1,-1}};
private static final int[][] ALT = {{ 0, 1, 2},{ 0,-1, 2},{-1, 1, 1},{ 1, 1, 1},{ 2, 0, 1},
{ 1,-1, 1},{-1,-1, 1},{-2, 0, 1},{-1, 2, 0},{ 1, 2, 0},
{ 1,-2, 0},{-1,-2, 0},{-1, 1,-1},{ 1, 1,-1},{ 2, 0,-1},
{ 1,-1,-1},{-1,-1,-1},{-2, 0,-1},{ 0, 1,-2},{ 0,-1,-2}};
private static final int[][] BLT = {{ 0, 0, 1},{ 0, 0, 1},{-1, 1, 1},{ 1, 1, 1},{ 1, 0, 0},
{ 1,-1, 1},{-1,-1, 1},{-1, 0, 0},{ 0, 1, 0},{ 0, 1, 0},
{ 0,-1, 0},{ 0,-1, 0},{-1, 1,-1},{ 1, 1,-1},{ 1, 0, 0},
{ 1,-1,-1},{-1,-1,-1},{-1, 0, 0},{ 0, 0,-1},{ 0, 0,-1}};
//-----------------------------------------------------------------------------------------------------
// Pentagon: 0 1 2 3
// x y z x y z x y z x y z
private static final int[][] ASP = {{ 0, 1, 0},{ 0, 0, 1},{ 0,-1, 0},{ 0, 0, 1},
{-1, 0, 0},{ 1, 0, 0},{ 1, 0, 0},{-1, 0, 0},
{ 0, 1, 0},{ 0, 0,-1},{ 0,-1,-0},{ 0, 0,-1}};
private static final int[][] BSP = {{ 0, 0, 1},{ 1, 0, 0},{ 0, 0, 1},{-1, 0, 0},
{ 0, 1, 0},{ 0, 1, 0},{ 0,-1, 0},{ 0,-1, 0},
{ 0, 0,-1},{ 1, 0, 0},{ 0, 0,-1},{-1, 0, 0}};
private static final int[][] AMP = {{ 0, 1, 1},{ 1, 0, 1},{ 0,-1, 1},{-1, 0, 1},
{-1, 1, 0},{ 1, 1, 0},{ 1,-1, 0},{-1,-1, 0},
{ 0, 1,-1},{ 1, 0,-1},{ 0,-1,-1},{-1, 0,-1}};
private static final int[][] BMP = {{ 0, 1, 0},{ 0, 0, 1},{ 0,-1, 0},{ 0, 0, 1},
{-1, 0, 0},{ 1, 0, 0},{ 1, 0, 0},{-1, 0, 0},
{ 0, 1, 0},{ 0, 0,-1},{ 0,-1, 0},{ 0, 0,-1}};
private static final int[][] ALP = {{ 0, 2, 1},{ 1, 0, 2},{ 0,-2, 1},{-1, 0, 2},
{-2, 1, 0},{ 2, 1, 0},{ 2,-1, 0},{-2,-1, 0},
{ 0, 2,-1},{ 1, 0,-2},{ 0,-2,-1},{-1, 0,-2}};
private static final int[][] BLP = {{ 0, 1, 1},{ 1, 0, 1},{ 0,-1, 1},{-1, 0, 1},
{-1, 1, 0},{ 1, 1, 0},{ 1,-1, 0},{-1,-1, 0},
{ 0, 1,-1},{ 1, 0,-1},{ 0,-1,-1},{-1, 0,-1}};
//-----------------------------------------------------------------------------------------------------
// Directional Data
// VECTOR is a vector in the direction of the rotational axis, ANGLE is the angle rotated in radians
//-----------------------------------------------------------------------------------------------------
// Rectangle:
private static final double[] ANGLER = { 1.570796, 1.047198, 1.047198, 2.094395, 2.094395,
0.628319, 0.628319, 1.256664, 1.884956, 2.513274,
2.513274, 1.884956, 1.256664, 0.000000,-1.570796,
3.141593, 1.570796,-0.628319,-1.256664,-1.884956,
-2.513274,-2.513274,-1.884956,-1.256664,-0.628319,
-1.047198,-2.094395,-2.094395,-1.047198,-1.570796 };
private static final Vector3d RECT1 = new Vector3d( TAU2, 0.0, 1.0 );
private static final Vector3d RECT2 = new Vector3d( TAU2, 0.0,-1.0 );
private static final Vector3d RECT3 = new Vector3d( 1.0, 0.0, TAU );
private static final Vector3d RECT4 = new Vector3d( 1.0, 0.0,-TAU );
private static final Vector3d RECT5 = new Vector3d( TAU , 0.0, TAU2);
private static final Vector3d RECT6 = new Vector3d( TAU , 0.0,-TAU2);
private static final Vector3d[] VECTORR = { XAXIS, RECT1, RECT2, RECT2, RECT1,
RECT3, RECT4, RECT6, RECT6, RECT4,
RECT3, RECT5, RECT5, ZAXIS, ZAXIS,
ZAXIS, ZAXIS, RECT3, RECT5, RECT5,
RECT3, RECT4, RECT6, RECT6, RECT4,
RECT1, RECT1, RECT2, RECT2, XAXIS };
//-----------------------------------------------------------------------------------------------------
// Triangle:
private static final double[] ANGLET = { 1.205932, 1.935660, 0.955317,-0.955317,
-1.570796,-2.186276, 2.186276, 1.570796,
0.364864,-0.364864,-2.776729, 2.776729,
0.955317,-0.955317,-1.570796,-2.186276,
2.186276, 1.570796,-1.205932,-1.935660 };
private static final Vector3d TRIG1 = new Vector3d( 1.0, 0.0, 1.0 );
private static final Vector3d TRIG2 = new Vector3d(-1.0, 0.0, 1.0 );
private static final Vector3d TRIG3 = new Vector3d(-1.0, 0.0, TAU2);
private static final Vector3d TRIG4 = new Vector3d( 1.0, 0.0, TAU2);
private static final Vector3d[] VECTORT = { XAXIS, XAXIS, TRIG1, TRIG2, TRIG3,
TRIG2, TRIG1, TRIG4, ZAXIS, ZAXIS,
ZAXIS, ZAXIS, TRIG2, TRIG1, TRIG4,
TRIG1, TRIG2, TRIG3, XAXIS, XAXIS };
//-----------------------------------------------------------------------------------------------------
// Pentagon
private static final double[] ANGLEP = { 0.553574,-1.570796, 2.588018, 1.570796,
1.017222,-1.017222,-2.124370, 2.124370,
-0.553574,-1.570796,-2.588018, 1.570796};
private static final Vector3d PENT1 = new Vector3d(-TAU2, 0.0, TAU );
private static final Vector3d PENT2 = new Vector3d( TAU2, 0.0, TAU );
private static final Vector3d[] VECTORP = { XAXIS, PENT1, XAXIS, PENT2,
ZAXIS, ZAXIS, ZAXIS, ZAXIS,
XAXIS, PENT2, XAXIS, PENT1};
//-----------------------------------------------------------------------------------------------------
// Spin Data
// Some struts need to be rotated about their own axis to fit properly, the angle rotated in radians
//-----------------------------------------------------------------------------------------------------
private static final double[] RSPIN = { 1.571,-0.728, 0.728, 0.000, 0.000, 1.100,
-1.100, 0.000,-1.100, 0.000, 0.000, 1.100,
0.000, 0.000, 1.571, 0.000, 1.571, 1.100,
0.000, 1.100, 0.000, 0.000,-1.100, 0.000,
-1.100,-0.728, 0.000, 0.000, 0.728, 1.571 };
private static final double[] TSPIN = { 3.142, 0.000, 1.691,-1.691,-0.350,
0.120,-0.120, 0.350,-1.571, 1.571,
-1.571, 1.571, 1.451,-1.451,-2.792,
3.022,-3.022, 2.792, 0.000, 3.142 };
private static final double[] PSPIN = { 3.142, 0.250, 0.000,-0.250,-0.300, 0.300,
-0.300, 0.300, 0.000, 0.400, 3.142,-0.400 };
//-----------------------------------------------------------------------------------------------------
// Geometry Data
// for 3d objects
//-----------------------------------------------------------------------------------------------------
// Zome Ball:
// ball coordinates
private static final Point3f[] BALLC = {new Point3f( -2*TAUF-1, 10*TAUF+6, -3*TAUF-2 ),new Point3f( -3*TAUF-2, 8*TAUF+5, -6*TAUF-4 ),
new Point3f( 2*TAUF+1, 10*TAUF+6, -3*TAUF-2 ),new Point3f( 3*TAUF+2, 8*TAUF+5, -6*TAUF-4 ),
new Point3f( 0, 7*TAUF+4, -8*TAUF-5 ),new Point3f( 2*TAUF+1,-10*TAUF-6, 3*TAUF+2 ),
new Point3f( 3*TAUF+2, -8*TAUF-5, 6*TAUF+4 ),new Point3f( 0, -7*TAUF-4, 8*TAUF+5 ),
new Point3f( -3*TAUF-2, -8*TAUF-5, 6*TAUF+4 ),new Point3f( -2*TAUF-1,-10*TAUF-6, 3*TAUF+2 ),
new Point3f( -3*TAUF-2, -2*TAUF-1,-10*TAUF-6 ),new Point3f( -3*TAUF-2, 2*TAUF+1,-10*TAUF-6 ),
new Point3f( -6*TAUF-4, -3*TAUF-2, -8*TAUF-5 ),new Point3f( -8*TAUF-5, 0, -7*TAUF-4 ),
new Point3f( -6*TAUF-4, 3*TAUF+2, -8*TAUF-5 ),new Point3f( 3*TAUF+2, 2*TAUF+1, 10*TAUF+6 ),
new Point3f( 3*TAUF+2, -2*TAUF-1, 10*TAUF+6 ),new Point3f( 6*TAUF+4, -3*TAUF-2, 8*TAUF+5 ),
new Point3f( 8*TAUF+5, 0, 7*TAUF+4 ),new Point3f( 6*TAUF+4, 3*TAUF+2, 8*TAUF+5 ),
new Point3f( 10*TAUF+6, -3*TAUF-2, 2*TAUF+1 ),new Point3f( 10*TAUF+6, -3*TAUF-2, -2*TAUF-1 ),
new Point3f( 8*TAUF+5, -6*TAUF-4, 3*TAUF+2 ),new Point3f( 7*TAUF+4, -8*TAUF-5, 0 ),
new Point3f( 8*TAUF+5, -6*TAUF-4, -3*TAUF-2 ),new Point3f(-10*TAUF-6, 3*TAUF+2, -2*TAUF-1 ),
new Point3f(-10*TAUF-6, 3*TAUF+2, 2*TAUF+1 ),new Point3f( -8*TAUF-5, 6*TAUF+4, 3*TAUF+2 ),
new Point3f( -7*TAUF-4, 8*TAUF+5, 0 ),new Point3f( -8*TAUF-5, 6*TAUF+4, -3*TAUF-2 ),
new Point3f( 3*TAUF+2, -2*TAUF-1,-10*TAUF-6 ),new Point3f( 6*TAUF+4, -3*TAUF-2, -8*TAUF-5 ),
new Point3f( 3*TAUF+2, 2*TAUF+1,-10*TAUF-6 ),new Point3f( 6*TAUF+4, 3*TAUF+2, -8*TAUF-5 ),
new Point3f( 8*TAUF+5, 0, -7*TAUF-4 ),new Point3f( -3*TAUF-2, 2*TAUF+1, 10*TAUF+6 ),
new Point3f( -6*TAUF-4, 3*TAUF+2, 8*TAUF+5 ),new Point3f( -8*TAUF-5, 0, 7*TAUF+4 ),
new Point3f( -6*TAUF-4, -3*TAUF-2, 8*TAUF+5 ),new Point3f( -3*TAUF-2, -2*TAUF-1, 10*TAUF+6 ),
new Point3f( -8*TAUF-5, -6*TAUF-4, 3*TAUF+2 ),new Point3f( -7*TAUF-4, -8*TAUF-5, 0 ),
new Point3f(-10*TAUF-6, -3*TAUF-2, 2*TAUF+1 ),new Point3f(-10*TAUF-6, -3*TAUF-2, -2*TAUF-1 ),
new Point3f( -8*TAUF-5, -6*TAUF-4, -3*TAUF-2 ),new Point3f( 8*TAUF+5, 6*TAUF+4, -3*TAUF-2 ),
new Point3f( 7*TAUF+4, 8*TAUF+5, 0 ),new Point3f( 8*TAUF+5, 6*TAUF+4, 3*TAUF+2 ),
new Point3f( 10*TAUF+6, 3*TAUF+2, 2*TAUF+1 ),new Point3f( 10*TAUF+6, 3*TAUF+2, -2*TAUF-1 ),
new Point3f( 0, -7*TAUF-4, -8*TAUF-5 ),new Point3f( -3*TAUF-2, -8*TAUF-5, -6*TAUF-4 ),
new Point3f( 3*TAUF+2, -8*TAUF-5, -6*TAUF-4 ),new Point3f( 2*TAUF+1,-10*TAUF-6, -3*TAUF-2 ),
new Point3f( -2*TAUF-1,-10*TAUF-6, -3*TAUF-2 ),new Point3f( 0, 7*TAUF+4, 8*TAUF+5 ),
new Point3f( 3*TAUF+2, 8*TAUF+5, 6*TAUF+4 ),new Point3f( 2*TAUF+1, 10*TAUF+6, 3*TAUF+2 ),
new Point3f( -2*TAUF-1, 10*TAUF+6, 3*TAUF+2 ),new Point3f( -3*TAUF-2, 8*TAUF+5, 6*TAUF+4 )};
// Ball Strip Counts
private static final int[] BALLSC = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 };
//Ball Coordinate Indices
private static final int[] BALLCI = { 2, 3, 0, 4, 1, //P0+
6, 7, 5, 8, 9, //P0-
32,33,30,34,31, //P1+
36,37,35,38,39, //P1-
12,13,10,14,11, //P2+
16,17,15,18,19, //P2-
26,27,25,28,29, //P3+
22,23,20,24,21, //P3-
56,57,55,58,59, //P4+
52,53,50,54,51, //P4-
46,47,45,48,49, //P5+
42,43,40,44,41, //P5-
3,45,33, //T0+
8,38,40, //T0-
32,11, 4, //T1+
39, 7,16, //T1-
1,14,29, //T2+
6,22,17, //T2-
28,58, 0, //T3+
23, 5,53, //T3-
57,46, 2, //T4+
54, 9,41, //T4-
49,21,34, //T5+
42,37,26, //T5-
50,10,30, //T6+
55,35,15, //T6-
25,13,43, //T7+
20,48,18, //T7-
36,59,27, //T8+
31,24,52, //T8-
47,56,19, //T9+
44,12,51, //T9-
32, 4,33, 3, //R0+
38, 8,39, 7, //R0-
14, 1,11, 4, //R1+
16, 7,17, 6, //R1-
28, 0,29, 1, //R2+
57, 2,58, 0, //R3+
53, 5,54, 9, //R3-
45, 3,46, 2, //R4+
41, 9,40, 8, //R4-
49,34,45,33, //R5+
40,38,42,37, //R5-
30,10,32,11, //R6+
39,16,35,15, //R6-
13,25,14,29, //R7+
17,22,18,20, //R7-
27,59,28,58, //R8+
23,53,24,52, //R8-
56,47,57,46, //R9+
54,41,51,44, //R9-
48,20,49,21, //R10+
42,26,43,25, //R10-
24,31,21,34, //R11+
26,37,27,36, //R11-
31,52,30,50, //R12+
35,55,36,59, //R12-
51,12,50,10, //R13+
55,15,56,19, //R13-
12,44,13,43, //R14+
18,48,19,47, //R14-
22, 6,23, 5, //R2-
};
// Strut Geometry Data
//-----------------------------------------------------------------------------------------------------
// Blue strut face counts
private static final int[] BLUESC = {4,4,4,4,4,4};
// Blue Strut Coordinate Indices
private static final int[] BLUECI = {4,5,7,6,
1,5,0,4,
0,4,3,7,
7,6,3,2,
2,6,1,5,
3,2,0,1};
// Yellow Strut Face Counts
private static final int[] YELLOWSC = {3,4,4,4,3,4,4,4,3,3,3,3,3,3};
// Yellow Strut Coordinate Indices
private static final int[] YELLOWCI = {0, 2, 1,
0, 1, 3, 4,
0, 3, 2, 5,
2, 5, 1, 4,
9,10,11,
6, 9, 8,11,
8,11, 7,10,
7,10, 6, 9,
3, 7, 5,
3, 8, 7,
4, 8, 3,
4, 6, 8,
5, 6, 4,
7, 6, 5};
// Red Strut Face Counts
private static final int[] REDSC = {5,4,4,4,4,4, 5,4,4,4,4,4, 3,3,3,3,3, 3,3,3,3,3};
// Red Strut Coordinate Indices
private static final int[] REDCI = { 1, 0, 2, 4, 3,
0, 5, 4, 9,
4, 9, 3, 8,
3, 8, 2, 7,
2, 7, 1, 6,
1, 6, 0, 5,
15,16,19,17,18,
10,15,14,19,
14,19,13,18,
13,18,12,17,
12,17,11,16,
11,16,10,15,
5,13,12,
6,14,13,
7,10,14,
8,11,10,
9,12,11,
10, 7, 8,
11, 8, 9,
12, 9, 5,
13, 5, 6,
14, 6, 7};
//-----------------------------------------------------------------------------------------------------
// GLOBALS
//-----------------------------------------------------------------------------------------------------
// Arrays
private static gold3d[] pointIndex = new gold3d[MAXITEMS]; // holds the locations of all endpoints
private static int[][] strutIndex = new int[MAXITEMS][2]; // holds the endpoint pair for each strut
public static int strutCount[][] = new int[3][3]; // Strut Counter for the kitUI
private static final int addOrder[][] = new int[MAXITEMS][3]; // Keeps the order and type of parts added
// used by undo function
// BranchGroups
public static BranchGroup scenebg = null; // main branch group
private static TransformGroup movetg = null; // move transform (used to focus)
private static TransformGroup zoomtg = null; // view transfrom (used to zoom)
private static TransformGroup rotatetg = null; // rotation transform
private static TransformGroup alphatg = null; // used by the rotation interpolator
// control integers
private static int current = 0; // current ball
public static int currentKit = 0; // current kit type
private static int indexLength = 0; // number of components (not counting origin ball)
public static int ballCount = 1; // number of balls
private static int oldcurrent = -1; // the last picked position ( used by the mouseClicked listener )
// holds the last mouse location during a mouse drag
private int oldX = 0;
private int oldY = 0;
// Swing parts
private static JSlider zslider; // zoom slider
private static JSlider xslider; // x rotate slider
private static JSlider yslider; // y rotate slider
private static JButton undoJB; // undo button
private static JButton focusJB; // focus button
private static JButton resetJB; // reset button
private static JButton rotateJB; // rotate button
private static JFrame frame = null; // the Frame
// user interface panel
public static zomeUI ui = new zomeUI();
public static kitUI kui = new kitUI();
// Canvases
private static PickCanvas pickCanvas = null; // canvas where picking is enabled
private static Canvas3D c3d = null; // 3d canvas for rendering
// used to rotate the scene graph
private static RotationInterpolator rotator = null;
//-----------------------------------------------------------------------------------------------------
// INITIALIZATION FUNCTIONS
//-----------------------------------------------------------------------------------------------------
// init
//-----------------------------------------------------------------------------------------------------
// initializes java3d
public void init()
{
// initialize the all arrays to zero
//---------------------------------------------------
for ( int i = 0; i < MAXITEMS; i++ )
{
pointIndex[i] = new gold3d();
addOrder[i][0] = 0;
addOrder[i][1] = 0;
addOrder[i][2] = 0;
strutIndex[i][START] = 0;
strutIndex[i][END] = 0;
}
for ( int i = RECT; i <= PENT; i++ )
{
for ( int j = SHORT; j <= LONG; j++ )
{
strutCount[i][j] = 0;
}
}
// Basics - This sets up the 3d universe
//---------------------------------------------------
// create universe
VirtualUniverse universe = new VirtualUniverse();
// create locale
Locale locale = new Locale(universe);
// create an infinite bounding sphere
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), Double.MAX_VALUE);
// creates the root of the scene (main viewing tramsforms are added to this)
BranchGroup sceneroot = createSceneBG();
// create the view platform
//---------------------------------------------------
// create a branch group to hold the view platform
BranchGroup viewbg = new BranchGroup();
ViewPlatform vp = new ViewPlatform();
vp.setViewAttachPolicy( View.RELATIVE_TO_FIELD_OF_VIEW );
vp.setActivationRadius( ACTIVATIONRADIUS );
// move the view back (so the initial view isn't inside the ball)
Transform3D viewZoom = new Transform3D();
viewZoom.setScale( 1.0f );
viewZoom.setTranslation( new Vector3d( 0.0, 0.0, 40.0 ) );
// create the zoom TransformGroup and set intitial value
zoomtg = new TransformGroup( viewZoom );
zoomtg.setCapability( TransformGroup.ALLOW_TRANSFORM_READ );
zoomtg.setCapability( TransformGroup.ALLOW_TRANSFORM_WRITE );
// wire it back to the view branch group
zoomtg.addChild( vp );
viewbg.addChild( zoomtg );
// create the view
//---------------------------------------------------
View view = new View();
// crap you have to do with every view
PhysicalBody pb = new PhysicalBody();
PhysicalEnvironment pe = new PhysicalEnvironment();
view.setPhysicalBody( pb );
view.setPhysicalEnvironment( pe );
view.attachViewPlatform( vp );
// set the clip distances
view.setBackClipDistance( 100 );
view.setFrontClipDistance( 0.1 );
// find the best graphics setting
GraphicsConfigTemplate3D gc3D = new GraphicsConfigTemplate3D();
gc3D.setSceneAntialiasing( GraphicsConfigTemplate.PREFERRED );
//list of all the screen devices for the local graphics environment
GraphicsDevice gd[] = GraphicsEnvironment.
getLocalGraphicsEnvironment().
getScreenDevices();
// select the best configuration and create a canvas
c3d = new Canvas3D( gd[0].getBestConfiguration( gc3D ) );
// set the canvas size
// c3d.setSize( CANVASWIDTH, CANVASHEIGHT );
// attach the canvas to the view
view.addCanvas3D( c3d );
// wire everything back to the locale
//---------------------------------------------------
locale.addBranchGraph( sceneroot );
locale.addBranchGraph( viewbg );
} // end Init
//-------------------------------------------------------------------
//Callback to allow the Canvas3D to be added to a Panel
protected void addCanvas3D( Canvas3D c3d )
{
add( "center", c3d );
}
// createSceneBG
//-----------------------------------------------------------------------------------------------------
// creates the initial scenegraph
protected BranchGroup createSceneBG()
{
// create the root node
BranchGroup root = new BranchGroup();
//Create an infinite spherical bounding volume that will define the volume.
BoundingSphere bounds = new BoundingSphere( new Point3d(0.0,0.0,0.0), Double.MAX_VALUE );
// create trasformgroups (used by the sliders, mouse rotate, and focus)
//---------------------------------------------------
rotatetg = new TransformGroup();
rotatetg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
rotatetg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
movetg = new TransformGroup();
movetg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
movetg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
// create the rotation interpolator (spins the structure)
//---------------------------------------------------
// interpolator transfromgroup
alphatg = new TransformGroup();
alphatg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
alphatg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
//Create a transformation matrix for the interpolator
Transform3D yAxis = new Transform3D();
// alpha is a time function to make rotation automatic
Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);
// rotator controls the rotation effect
rotator = new RotationInterpolator( rotationAlpha, alphatg, yAxis, 0.0f, (float) Math.PI*2.0f );
//Set the scheduling bounds on the behavior. This defines the
//volume within which this behavior will be active.
rotator.setSchedulingBounds( bounds );
rotator.setEnable(false);
//Add the behavior to the scenegraph so that Java 3D
//can schedule it for activation.
alphatg.addChild(rotator);
// initialize the main branchgroup off which all others will be built
//-----------------------------------------------------------------------
scenebg = new BranchGroup();
//Allow the BranchGroup to have children added and removed at runtime
scenebg.setCapability( Group.ALLOW_CHILDREN_EXTEND );
scenebg.setCapability( Group.ALLOW_CHILDREN_READ );
scenebg.setCapability( Group.ALLOW_CHILDREN_WRITE );
// Create Origin Ball - that first ball in the middle of the sceen
//---------------------------------------------------
Vector3d origin = new Vector3d( 0, 0, 0 );
Group originBall = createBall ( origin, REAL );
scenebg.addChild( originBall );
// highlight it
Highlight();
// Create lighting elements
//---------------------------------------------------
/* - These lights suck
//Create an ambient light
AmbientLight ambientLight = new AmbientLight( AMBIENT );
ambientLight.setInfluencingBounds( bounds );
// create a point light
//PointLight pointLight = new PointLight( LGREY, LIGHTLOCATION, LIGHTATTENUATION );
//pointLight.setInfluencingBounds( bounds );
*/
//Create a directional light
DirectionalLight directionLight = new DirectionalLight( LIGHT, LIGHTDIRECTION );
directionLight.setInfluencingBounds( bounds );
//Add the lights to the scenegraph
//root.addChild(ambientLight); // yuck!
//root.addChild(pointLight); // bleh!
root.addChild(directionLight);
// Create a background - A giant sphere which we are inside
//---------------------------------------------------
// create a BranchGroup that will hold the background geometry
BranchGroup bgGeometry = new BranchGroup();
// create appearance for the background sphere
Appearance appearance = new Appearance();
appearance.setCapability(Appearance.ALLOW_MATERIAL_READ);
appearance.setCapability(Appearance.ALLOW_MATERIAL_WRITE);
// set the attributes
PolygonAttributes pa = new PolygonAttributes(PolygonAttributes.POLYGON_FILL,
PolygonAttributes.CULL_BACK, 0.0f );
RenderingAttributes ra = new RenderingAttributes(true, true, 0.0f,
RenderingAttributes.ALWAYS,
true, true, false,
RenderingAttributes.ROP_COPY );
appearance.setPolygonAttributes(pa);
appearance.setRenderingAttributes(ra);
// create a material for the appearance
Material m = new Material(DARKSKY, DARKSKY, SKY, WHITE, BACKGROUNDSHINE );
m.setCapability( Material.ALLOW_COMPONENT_READ);
m.setCapability( Material.ALLOW_COMPONENT_WRITE);
m.setLightingEnable(true);
appearance.setMaterial(m);
// create the sphere
Sphere sphere = new Sphere( BACKGROUNDSIZE,
Sphere.GENERATE_NORMALS_INWARD |
Sphere.GENERATE_NORMALS , appearance );
// add the sphere to a branchgroup
bgGeometry.addChild( sphere );
// Wire it all together
//---------------------------------------------------
movetg.addChild( scenebg );
rotatetg.addChild( movetg );
alphatg.addChild( rotatetg );
root.addChild( alphatg );
root.addChild( bgGeometry );
//Return the root of the scene side of the scenegraph
return root;
} // end createSceneBG
//-----------------------------------------------------------------------------------------------------
// MAIN
//-----------------------------------------------------------------------------------------------------
public zome3d(JFrame frame)
{
// uses the provided frame
this.frame = frame;
// initialize java3d
init();
// set the frame layout
frame.getContentPane().setLayout(new BorderLayout());
// create the menu
//-------------------------------------------------------------------
JPopupMenu.setDefaultLightWeightPopupEnabled( false );
ToolTipManager ttm = ToolTipManager.sharedInstance();
ttm.setLightWeightPopupEnabled( false );
JMenuBar menuBar = new JMenuBar();
JMenu menu = null;
//Create some menu items and add them to the JMenuBar
menu = new JMenu( "File" );
menu.add( createMenuItem( "File", "Clear", this ) );
menu.add( createMenuItem( "File", "Exit", this ) );
menuBar.add( menu );
menu = new JMenu( "Add" );
menu.add( createMenuItem( "Add", "Rectangle Burst", this ) );
menu.add( createMenuItem( "Add", "Triangle Burst", this ) );
menu.add( createMenuItem( "Add", "Pentagon Burst", this ) );
menuBar.add( menu );
menu = new JMenu( "Help" );
menu.add( createMenuItem( "Help", "Instructions", this ) );
menu.add( createMenuItem( "Help", "Tips", this ) );
menu.add( createMenuItem( "Help", "About", this ) );
menuBar.add( menu );
//Assign the JMenuBar to the parent frame.
frame.setJMenuBar( menuBar );
// create the left bottom panel
//-------------------------------------------------------------------
// create border types
Border raisedBevel = BorderFactory.createRaisedBevelBorder();
Border etched = BorderFactory.createEtchedBorder();
// the buttons
undoJB = new JButton( "Undo" );
undoJB.setBorder(etched);
undoJB.addActionListener(this);
undoJB.setToolTipText("Click to undo stick additions.");
focusJB = new JButton( " Focus " );
focusJB.setBorder(etched);
focusJB.addActionListener(this);
focusJB.setToolTipText( "Centers the view on the hightlighted ball." );
resetJB = new JButton( "Re-Center" );
resetJB.setBorder(etched);
resetJB.addActionListener(this);
resetJB.setToolTipText( "Re-centers the view on the first ball and brings rotations back to Zero." );
// add buttons to panel
JPanel buttonpanel = new JPanel();
buttonpanel.setLayout( new BorderLayout() );
buttonpanel.add( undoJB, BorderLayout.CENTER );
buttonpanel.add( focusJB, BorderLayout.NORTH );
buttonpanel.add( resetJB, BorderLayout.SOUTH );
// the y rotation slider
yslider = new JSlider(JSlider.HORIZONTAL, -180, 180, 0);
yslider.addChangeListener( new SliderListener() );
yslider.setBorder(BorderFactory.createTitledBorder("Rotate") );
yslider.setMajorTickSpacing(45);
yslider.setMinorTickSpacing(15);
yslider.setPaintTicks(true);
yslider.setPaintLabels(true);
yslider.setToolTipText("Rotates the model left and right.");
// add buttonpanel and slider to panel
JPanel ypanel = new JPanel();
ypanel.setLayout( new BorderLayout() );
ypanel.add(yslider, BorderLayout.CENTER);
ypanel.add(buttonpanel, BorderLayout.WEST );
ypanel.setBorder(raisedBevel);
// create right bottom panel
//------------------------------------------------------------------
// the zoom slider
zslider = new JSlider(JSlider.HORIZONTAL, 0, 200, 40);
zslider.addChangeListener( new SliderListener() );
zslider.setBorder(BorderFactory.createTitledBorder("Zoom") );
zslider.setMajorTickSpacing(20);
zslider.setMinorTickSpacing(5);
zslider.setPaintTicks(false);
zslider.setToolTipText("Zooms in and Out.");
// the button
rotateJB = new JButton( "Rotation On" );
rotateJB.setBorder(etched);
rotateJB.addActionListener(this);
rotateJB.setToolTipText("Turns automatic rotation on.");
rotateJB.setMnemonic(KeyEvent.VK_R);
// add to panel
JPanel zpanel = new JPanel();
zpanel.setLayout( new BorderLayout() );
zpanel.setBorder(raisedBevel);
zpanel.add( zslider, BorderLayout.NORTH );
zpanel.add( rotateJB, BorderLayout.SOUTH );
// wire both bottom panels together
//-------------------------------------------------------------------
JPanel bottompanel = new JPanel();
bottompanel.setLayout( new BorderLayout() );
bottompanel.add( ypanel, BorderLayout.CENTER );
bottompanel.add( zpanel, BorderLayout.EAST );
bottompanel.add( kui, BorderLayout.SOUTH );
// create the right panel
//-------------------------------------------------------------------
// the x slider
xslider = new JSlider(JSlider.VERTICAL, -180, 180, 0);
xslider.addChangeListener( new SliderListener() );
xslider.setBorder(BorderFactory.createTitledBorder("Rotate") );
xslider.setMajorTickSpacing(45);
xslider.setMinorTickSpacing(15);
xslider.setPaintTicks(true);
xslider.setPaintLabels(true);
xslider.setToolTipText("Rotates the model up and down.");
// panel for the slider
JPanel xpanel = new JPanel();
xpanel.setLayout( new BorderLayout() );
xpanel.add(xslider, BorderLayout.CENTER);
xpanel.setBorder(raisedBevel);
// panel for the canavs
JPanel c3dp = new JPanel();
c3dp.setLayout( new BorderLayout() );
c3dp.add(c3d, BorderLayout.CENTER);
c3dp.setBorder(raisedBevel);
c3dp.setSize( 300, 300 );
// add panels, canvas, and user interface to frame
//-------------------------------------------------------------------