Пример #1
0
        private void create_dodecahedron()
        {
            // Generated from icosahedron points.
            create_icosa_points();
            MFloatPoint[] my_info = new MFloatPoint[12];
            int           idx;

            for (idx = 0; idx < 12; idx++)
            {
                my_info[idx]   = new MFloatPoint();
                my_info[idx].x = iarr[idx].x;
                my_info[idx].y = iarr[idx].y;
                my_info[idx].z = iarr[idx].z;
            }

            iarr.clear();

            // now generate the dodecahedron points:
            double x1, y1, z1, x2, y2, z2, x3, y3, z3;
            double xf, yf, zf;
            double len;

            for (idx = 0; idx < 20; idx++)
            {
                x1 = my_info[icosa_gons[3 * idx] - 1].x;
                y1 = my_info[icosa_gons[3 * idx] - 1].y;
                z1 = my_info[icosa_gons[3 * idx] - 1].z;

                x2 = my_info[icosa_gons[3 * idx + 1] - 1].x;
                y2 = my_info[icosa_gons[3 * idx + 1] - 1].y;
                z2 = my_info[icosa_gons[3 * idx + 1] - 1].z;

                x3 = my_info[icosa_gons[3 * idx + 2] - 1].x;
                y3 = my_info[icosa_gons[3 * idx + 2] - 1].y;
                z3 = my_info[icosa_gons[3 * idx + 2] - 1].z;

                // the docecahedron vertex is the average of these points.
                xf = (x1 + x2 + x3) / 3.0;
                yf = (y1 + y2 + y3) / 3.0;
                zf = (z1 + z2 + z3) / 3.0;

                // One more transformation: scale this point so it lies on the
                // unit sphere...
                len = Math.Sqrt(xf * xf + yf * yf + zf * zf);
                xf /= len; yf /= len; zf /= len;

                FILL(xf, yf, zf);
            }
        }
Пример #2
0
        private void generatePrimitiveData()
        {
            // Decide which type of primitive to create
            //
            iarr.clear();
            faceCounts.clear();
            faceConnects.clear();

            switch (shapeFlag)
            {
            case 1:
            default:
                create_icosa_points();
                num_verts      = 12;
                num_faces      = 20;
                edges_per_face = 3;
                p_gons         = icosa_gons;
                break;

            case 2:
                create_dodecahedron();
                num_verts      = 20;
                num_faces      = 12;
                edges_per_face = 5;
                p_gons         = dodeca_gons;
                break;

            case 3:
                create_tetrahedron();
                num_verts      = 4;
                num_faces      = 4;
                edges_per_face = 3;
                p_gons         = tetra_gons;
                break;

            case 4:
                create_cube();
                num_verts      = 8;
                num_faces      = 6;
                edges_per_face = 4;
                p_gons         = cube_gons;
                break;

            case 5:
                create_octahedron();
                num_verts      = 6;
                num_faces      = 8;
                edges_per_face = 3;
                p_gons         = octa_gons;
                break;

            case 6:
                createPlane();
                p_gons = null;
                break;

            case 7:
                createCylinder();
                p_gons = null;
                break;

            case 8:
                create_truncated_icosahedron();
                p_gons = null;
                break;
            }

            // Construct the point array
            //
            pa.clear();
            int i;

            for (i = 0; i < num_verts; i++)
            {
                pa.append(iarr[i]);
            }

            // If we are using polygon data then set up the face connect array
            // here. Otherwise, the create function will do it.
            //
            if (null != p_gons)
            {
                num_face_connects = num_faces * edges_per_face;
                num_edges         = num_face_connects / 2;

                for (i = 0; i < num_faces; i++)
                {
                    faceCounts.append(edges_per_face);
                }

                for (i = 0; i < (num_faces * edges_per_face); i++)
                {
                    faceConnects.append(p_gons[i] - 1);
                }
            }
        }