Normand Briere
2018-07-01 89c1ad67bc65d24ceadfa9e95f8c5515283f1e97
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
package mocap.figure;
 
import java.awt.Color;
 
import javax.media.j3d.Appearance;
import javax.media.j3d.ColoringAttributes;
import javax.media.j3d.Geometry;
import javax.media.j3d.LineStripArray;
import javax.media.j3d.Material;
import javax.media.j3d.Shape3D;
import javax.media.j3d.TransparencyAttributes;
import javax.vecmath.Color3f;
import javax.vecmath.Point3f;
 
import com.sun.j3d.utils.geometry.Primitive;
 
/**
 * Create a Circle for the 3d scene
 * 
 * @author Quan
 * 
 */
public class Circle extends Primitive
{
   private Shape3D _shape3DForm;
   private Appearance _appearance;
 
   public Circle(float radius, int divisions, Color color)
   {
       super();
       _appearance = initAppearance(color);
 
       _shape3DForm = new Shape3D(createCircleGeometry(radius, divisions),
               _appearance);
       this.addChild(_shape3DForm);
   }
 
   private Appearance initAppearance(Color color)
   {
       Material materialStandard = new Material(new Color3f(color),
               new Color3f(color), new Color3f(color), new Color3f(0.7f, 0.7f,
                       0.7f), 10.0f);
       Appearance appearance = new Appearance();
       TransparencyAttributes attrTransparency = new TransparencyAttributes(
               TransparencyAttributes.NICEST, 0.2f);
       appearance.setTransparencyAttributes(attrTransparency);
       appearance.setMaterial(materialStandard);
       ColoringAttributes ca = new ColoringAttributes(new Color3f(color),
               ColoringAttributes.FASTEST);
       appearance.setColoringAttributes(ca);
       return appearance;
   }
 
   private Point3f[] createCircleCoords(float radius, int divisions)
   {
       Point3f[] coords = new Point3f[divisions];
       double dAngle = 0;
       float x, z;
 
       for (int i = 0; i < divisions; dAngle = 2.0 * Math.PI / (divisions - 1)
               * ++i) {
           x = (float) (radius * Math.sin(dAngle));
           z = (float) (radius * Math.cos(dAngle));
           coords[i] = new Point3f(x, 0f, z);
       }
       return coords;
   }
 
   /**
    * Generates the geometry of a circle
    * 
    * @param radius
    * @param divisions
    * @return
    */
   private Geometry createCircleGeometry(float radius, int divisions)
   {
       int[] stripCounts = {divisions};
       LineStripArray lsArray = new LineStripArray(divisions,
               LineStripArray.COORDINATES, stripCounts);
       lsArray.setCoordinates(0, createCircleCoords(radius, divisions));
       return lsArray;
   } //
 
   @Override
   public Appearance getAppearance(int arg0)
   {
       return _appearance;
       //        return null;
 
   }
 
   @Override
   public Shape3D getShape(int arg0)
   {
       return _shape3DForm;
   }
 
   @Override
   public void setAppearance(Appearance appearance)
   {
       _appearance = appearance;
       _shape3DForm.setAppearance(_appearance);
 
   }
}