float[] vertexs={ 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,-2.0f, 0.0f, // 面1 0.0f, 0.0f, 1.0f,-1.0f, 0.0f, 0.0f, 0.0f,-2.0f, 0.0f, // 面2 -1.0f, 0.0f, 0.0f, 0.0f, 0.0f,-1.0f, 0.0f,-2.0f, 0.0f, 0.0f, 0.0f,-1.0f, 1.0f, 0.0f, 0.0f, 0.0f,-2.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 2.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 2.0f, 0.0f, 0.0f, 0.0f,-1.0f,-1.0f, 0.0f, 0.0f, 0.0f, 2.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,-1.0f, 0.0f, 2.0f, 0.0f}; // 面8 float[] colors={ 0.5f,0.2f,1.0f,0.2f,0.5f,1.0f,0.2f,0.5f,1.0f, 0.2f,0.5f,1.0f,0.5f,0.2f,1.0f,0.5f,0.2f,1.0f, 0.5f,0.2f,1.0f,0.2f,0.5f,1.0f,0.2f,0.5f,1.0f, 0.2f,0.5f,1.0f,0.5f,0.2f,1.0f,0.5f,0.2f,1.0f, 0.2f,0.5f,1.0f,0.5f,0.2f,1.0f,0.5f,0.2f,1.0f, 0.5f,0.2f,1.0f,0.2f,0.5f,1.0f,0.2f,0.5f,1.0f, 0.2f,0.5f,1.0f,0.5f,0.2f,1.0f,0.5f,0.2f,1.0f, 0.5f,0.2f,1.0f,0.2f,0.5f,1.0f,0.2f,0.5f,1.0f}; TriangleArray geometry=new TriangleArray( 24,TriangleArray.COORDINATES | TriangleArray.COLOR_3); // 3 (面を構成する頂点の数) ×8 (面の数) geometry.setCoordinates(0,vertexs); // 頂点座標の設定 geometry.setColors(0,colors); // 頂点の色の設定 Shape3D shape=new Shape3D(geometry); // 水晶の形をした物体
Primitive primitive=new Sphere(1.0f,Sphere.GENERATE_NORMALS,appearance); // 法線
BranchGroup root=new BranchGroup(); Primitive primitive=new Sphere(); // 球 root.addChild(primitive);
Primitive primitive=new Sphere(); // 球 Shape3D shape=primitive.getShape(Sphere.BODY);
Primitive primitive=new Cylinder(); // 円柱 Shape3D shape=primitive.getShape(Cylinder.BODY); // 側面を取り出す
root.addChild(shape.cloneNode(true));
戻る