public TreeTemplate(
                int sliceCount,
                int stackDivision,
                int coneCount,
                float height,
                float radius,
                float radAdd
                )
            {
                var          attributePosition = new Attribute(VertexUsage.Position, VertexAttribPointerType.Float, 0, 3);
                var          attributeNormal   = new Attribute(VertexUsage.Normal, VertexAttribPointerType.Float, 0, 3); /*  content normals     */
                VertexFormat vertexFormat      = new VertexFormat();

                vertexFormat.Add(attributePosition);
                vertexFormat.Add(attributeNormal);

                this.sliceCount    = sliceCount;
                this.stackDivision = stackDivision;
                this.coneCount     = coneCount;
                this.height        = height;
                this.radius        = radius;
                this.radAdd        = radAdd;
                float   coneHeight = height / (float)coneCount;
                Matrix4 rotZ       = Matrix4.CreateRotation(
                    RenderStack.Math.Conversions.DegreesToRadians(90.0f),
                    Vector3.UnitZ
                    );
                float    cylHeight        = coneHeight;
                float    cylRadius        = height / 20.0f;
                Geometry cylinderGeometry = new RenderStack.Geometry.Shapes.Cylinder(-cylHeight, cylHeight, cylRadius, sliceCount);

                cylinderGeometry.Transform(rotZ);
                GeometryMesh cylinderMesh  = new GeometryMesh(cylinderGeometry, NormalStyle.CornerNormals, vertexFormat);
                Shape        cylinderShape = new CylinderShape(cylHeight, cylRadius);

                cylinderMesh.GetMesh.Name = "cylinder";
                meshes.Add(cylinderMesh);
                shapes.Add(cylinderShape);
                for (int c = 0; c < coneCount; c++)
                {
                    float    topRadius      = (coneCount - 1 - c) * radius / (float)coneCount;
                    float    bottomRadius   = topRadius + radAdd;
                    float    R              = bottomRadius;
                    float    r              = topRadius;
                    float    fullConeHeight = (R * coneHeight) / (R - r);
                    float    minX           = -fullConeHeight / 3.0f;
                    float    maxX           = 2.0f * fullConeHeight / 3.0f;
                    float    offset         = -minX;
                    Geometry coneGeometry   = new RenderStack.Geometry.Shapes.Cone(minX, maxX, bottomRadius, 0.0f, true, true, sliceCount, stackDivision);
                    coneGeometry.Transform(rotZ);
                    GeometryMesh coneMesh  = new GeometryMesh(coneGeometry, NormalStyle.CornerNormals, vertexFormat);
                    Shape        coneShape = new ConeShape(fullConeHeight, R);
                    coneMesh.GetMesh.Name = "cone" + c.ToString();
                    meshes.Add(coneMesh);
                    shapes.Add(coneShape);
                }
            }
示例#2
0
        public void AddSimpleScene()
        {
            //  Shapes here have local 0,0,0 at center of mass
            Geometry     cubeGeometry = new RenderStack.Geometry.Shapes.Cube(1.0f, 1.0f, 1.0f);
            GeometryMesh cubeMesh     = new GeometryMesh(cubeGeometry, NormalStyle.PolygonNormals);

            GeometryMesh sphereMesh = new GeometryMesh(
                new RenderStack.Geometry.Shapes.Sphere(0.75, 20, 12),
                NormalStyle.CornerNormals
                );
            Geometry cylinderGeometry = new RenderStack.Geometry.Shapes.Cylinder(-0.5f, 0.5f, 0.5f, 24);

            cylinderGeometry.Transform(
                Matrix4.CreateRotation(
                    Conversions.DegreesToRadians(90.0f),
                    Vector3.UnitZ
                    )
                );
            GeometryMesh cylinderMesh = new GeometryMesh(cylinderGeometry, NormalStyle.CornerNormals);
            Geometry     coneGeometry = new RenderStack.Geometry.Shapes.Cone(-1.0f / 3.0f, 2.0f / 3.0f, 0.75f, 0.0f, true, false, 24, 10);

            coneGeometry.Transform(
                Matrix4.CreateRotation(
                    Conversions.DegreesToRadians(90.0f),
                    Vector3.UnitZ
                    )
                );
            GeometryMesh coneMesh = new GeometryMesh(coneGeometry, NormalStyle.CornerNormals);

            /*  Models  */
            float    gap     = 2.5f;
            Material pearl   = materialManager["pearl"];
            Material gold    = materialManager["gold"];
            Material red     = materialManager["red"];
            Material green   = materialManager["green"];
            Material cyan    = materialManager["cyan"];
            Material blue    = materialManager["blue"];
            Material magenta = materialManager["magenta"];
            Material pink    = materialManager["pink"];

            AddModel(new Model("cube", cubeMesh, pearl, -3.5f * gap, 0.5f, 0.0f));
            AddModel(new Model("box", cubeMesh, gold, -2.5f * gap, 0.5f, 0.0f));
            AddModel(new Model("sphere", sphereMesh, red, -1.5f * gap, 0.75f, 0.0f));
            AddModel(new Model("sphere", sphereMesh, green, -0.5f * gap, 0.75f, 0.0f));
            AddModel(new Model("cylinder", cylinderMesh, cyan, 0.5f * gap, 0.5f, 0.0f));
            AddModel(new Model("cylinder", cylinderMesh, blue, 1.5f * gap, 0.5f, 0.0f));
            AddModel(new Model("cone", coneMesh, magenta, 2.5f * gap, 1.0f / 3.0f, 0.0f));
            AddModel(new Model("cone", coneMesh, pink, 3.5f * gap, 1.0f / 3.0f, 0.0f));
        }