import javax.media.j3d.*; import javax.vecmath.*; // Origin at center of solid. Sides of length 2. public class ColorTetra extends Shape3D { private static final float ycenter = (float)Math.sqrt(1.0/6.0); private static final float zcenter = (float)Math.sqrt(1.0/3.0); private static final float sqrt3 = (float)Math.sqrt(3.0); private static final float sqrt24_3 = (float)Math.sqrt ( 8.0/3.0); private static final Point3f p1 = new Point3f ( -1.0f, -ycenter, zcenter ); private static final Point3f p2 = new Point3f ( 1.0f, -ycenter, zcenter ); private static final Point3f p3 = new Point3f ( 0.0f, -ycenter, -sqrt3 + zcenter ); private static final Point3f p4 = new Point3f ( 0.0f, sqrt24_3 -ycenter, 0.0f ); private static final Point3f[] verts = { p1, p2, p4, // front face p1, p4, p3, // left back face p2, p3, p4, // right back face p1, p3, p2, // bottom face }; private static final Color3f c1 = new Color3f ( 1.0f, 0.0f, 0.0f ); private static final Color3f c2 = new Color3f ( 0.0f, 1.0f, 0.0f ); private static final Color3f c3 = new Color3f ( 1.0f, 1.0f, 1.0f ); private static final Color3f c4 = new Color3f ( 0.0f, 0.0f, 1.0f ); private static final Color3f[] colors = { c1, c2, c4, c1, c4, c3, c2, c3, c4, c1, c3, c2, }; public ColorTetra() { TriangleArray tetra = new TriangleArray ( 12, TriangleArray.COORDINATES | TriangleArray.COLOR_3 ); tetra.setCoordinates (0, verts ); tetra.setColors (0, colors ); this.setGeometry ( tetra ); this.setAppearance ( null ); } }