package awa.imu; import javax.media.j3d.*; import javax.vecmath.*; public class GyroRateIndicator extends Shape3D { private Geometry voGeometry; private Appearance voAppearance; private Color3f triColor; // create Shape3D with geometry and appearance // the geometry is created in method createGeometry // the appearance is created in method createAppearance public GyroRateIndicator(Color3f color) { this.triColor = color; voGeometry = createGeometry(Math.PI); voAppearance = createAppearance(); this.setGeometry(voGeometry); this.setAppearance(voAppearance); this.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); } public void showRate(double rate) { voGeometry = createGeometry(rate); this.setGeometry(voGeometry); } private Geometry createGeometry(double angleR) { TriangleFanArray tfa; int N = 7; int totalN = 4*(N+1); Point3f coords[] = new Point3f[totalN]; Color3f colors[] = new Color3f[totalN]; int stripCounts[] = {N+1, N+1, N+1, N+1}; float r = 1.2f; float w = 0.0f; int n; double a; float x, y; // set the central points for four triangle fan strips coords[0*(N+1)] = new Point3f(0.0f, 0.0f, w); coords[1*(N+1)] = new Point3f(0.0f, 0.0f, 0.0f); coords[2*(N+1)] = new Point3f(0.0f, 0.0f, 0.0f); coords[3*(N+1)] = new Point3f(0.0f, 0.0f, -w); for (a = 0,n = 0; n < N; a = angleR/(N-1) * ++n) { x = (float) (r * Math.cos(a)); y = (float) (r * Math.sin(a)); coords[0*(N+1)+N-n] = new Point3f(x, y, w); coords[1*(N+1)+n+1] = new Point3f(x, y, w); coords[2*(N+1)+N-n] = new Point3f(x, y, -w); coords[3*(N+1)+n+1] = new Point3f(x, y, -w); } for (int i=0; i < totalN; i++) { colors[i] = triColor; } tfa = new TriangleFanArray (totalN, GeometryArray.COORDINATES|GeometryArray.COLOR_3, stripCounts); tfa.setCoordinates(0, coords); tfa.setColors(0, colors); return tfa; } Appearance createAppearance() { Appearance app = new Appearance(); //appX.setColoringAttributes(new ColoringAttributes(0.1f, 0.8f, 0.1f, ColoringAttributes.SHADE_GOURAUD)); app.setMaterial(new Material(new Color3f(0.5f, 0.5f, 0.5f), new Color3f(0.5f, 0.5f, 0.5f), new Color3f(0.2f, 0.2f, 0.2f), new Color3f(0.0f, 0.0f, 0.0f), 72)); app.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.BLENDED, 0.5f)); return app; } }