// Define the model.
        private void DefineModel(Model3DGroup group)
        {
            // Define a polygon in the XZ plane.
            Point3D center = new Point3D(0, 0, 4.5);

            Point3D[] polygon = G3.MakePolygonPoints(6, center,
                                                     new Vector3D(1, 0, 0), new Vector3D(0, 0, -1));

            // Make a transform to move the polygon in the -Z direction.
            TranslateTransform3D translate = new TranslateTransform3D(0, 0, -3);

            // Make a right cone.
            MeshGeometry3D mesh1 = new MeshGeometry3D();

            mesh1.AddCone(center, polygon, new Vector3D(0, 3, 0));
            group.Children.Add(mesh1.MakeModel(Brushes.Pink));

            // Make a skewed cone.
            translate.Transform(polygon);
            center = translate.Transform(center);
            MeshGeometry3D mesh2 = new MeshGeometry3D();

            mesh2.AddCone(center, polygon, new Vector3D(0, 3, 2));
            group.Children.Add(mesh2.MakeModel(Brushes.LightBlue));

            // Make a conic frustum with cutting plane parallel to the base.
            translate.Transform(polygon);
            center = translate.Transform(center);
            MeshGeometry3D mesh3 = new MeshGeometry3D();

            mesh3.AddConeFrustum(center, polygon, new Vector3D(0, 4, 0), 2);
            group.Children.Add(mesh3.MakeModel(Brushes.LightGreen));

            // Make a conic frustum with cutting plane not parallel to the base.
            translate.Transform(polygon);
            center = translate.Transform(center);
            MeshGeometry3D mesh4   = new MeshGeometry3D();
            Point3D        planePt = center + new Vector3D(0, 2, 0);
            Vector3D       planeN  = new Vector3D(1, 1, 1);

            mesh4.AddConeFrustum(center, polygon, new Vector3D(0, 4, 0), planePt, planeN);
            group.Children.Add(mesh4.MakeModel(Brushes.Orange));

            // Show the axes.
            MeshExtensions.AddAxes(group);
        }
Esempio n. 2
0
        // Define the model.
        private void DefineModel(Model3DGroup group)
        {
            // Define a polygon in the XZ plane.
            Point3D center = new Point3D(0, -1, 0);

            Point3D[] polygon = G3.MakePolygonPoints(20, center,
                                                     new Vector3D(1, 0, 0), new Vector3D(0, 0, -1));

            // Make a conic frustum with cutting plane parallel to the base.
            MeshGeometry3D mesh3 = new MeshGeometry3D();

            mesh3.AddConeFrustum(center, polygon, new Vector3D(0, 3, 0), 2);
            group.Children.Add(mesh3.MakeModel(Brushes.LightBlue));

            //// Define a polygon in the XZ plane.
            //Point3D center = new Point3D(0, -1, 1.25);
            //Point3D[] polygon = G3.MakePolygonPoints(20, center,
            //    new Vector3D(1, 0, 0), new Vector3D(0, 0, -1));

            //// Make a transform to move the polygon in the -Z direction.
            //TranslateTransform3D translate = new TranslateTransform3D(0, 0, -2.5);

            //// Make a pyramidal frustum.
            //MeshGeometry3D mesh1 = new MeshGeometry3D();
            //mesh1.AddFrustum(center, polygon, new Vector3D(0, 3, 0), 2);
            //group.Children.Add(mesh1.MakeModel(Brushes.LightBlue));

            //// Make a conic frustum with cutting plane parallel to the base.
            //translate.Transform(polygon);
            //center = translate.Transform(center);
            //MeshGeometry3D mesh3 = new MeshGeometry3D();
            //mesh3.AddConeFrustum(center, polygon, new Vector3D(0, 3, 0), 2);
            //group.Children.Add(mesh3.MakeModel(Brushes.LightBlue));

            // Show the axes.
            //MeshExtensions.AddAxes(group);
        }
Esempio n. 3
0
        // Define the model.
        private void DefineModel(Model3DGroup group)
        {
            // Axes.
            MeshExtensions.AddAxes(group);

            MeshGeometry3D mesh1 = new MeshGeometry3D();
            MeshGeometry3D mesh2 = new MeshGeometry3D();
            MeshGeometry3D mesh3 = new MeshGeometry3D();
            MeshGeometry3D mesh4 = new MeshGeometry3D();

            double  x0     = -5;
            Point3D center = new Point3D(x0, 0, 4.5);

            // Box.
            mesh1.AddBox(center + new Vector3D(-0.5, 0, -1),
                         D3.XVector(1), D3.YVector(3), D3.ZVector(2));
            center.X += 2;

            // Box wrapped.
            mesh2.AddBoxWrapped(center + new Vector3D(-0.5, 0, -1),
                                D3.XVector(1), D3.YVector(3), D3.ZVector(2));
            center.X += 2;

            // Cone.
            Point3D[] circle = G3.MakePolygonPoints(20, center, D3.XVector(1), D3.ZVector(-1));
            mesh1.AddCone(center, circle, D3.YVector(4));
            center.X += 2;

            // Cone frustum.
            circle = G3.MakePolygonPoints(20, center, D3.XVector(1), D3.ZVector(-1));
            mesh1.AddConeFrustum(center, circle, D3.YVector(4), 3);
            center.X += 2;

            // Cone frustum w/cutting plane.
            circle = G3.MakePolygonPoints(20, center, D3.XVector(1), D3.ZVector(-1));
            mesh1.AddConeFrustum(center, circle, D3.YVector(4),
                                 center + new Vector3D(0, 2, 0), new Vector3D(0, 1, 1));
            center.X += 2;

            // Start a new row.
            center.X  = x0;
            center.Z -= 3;

            // Cube.
            MeshGeometry3D cubeMesh = new MeshGeometry3D();

            cubeMesh.AddCube();
            cubeMesh.ApplyTransformation(new ScaleTransform3D(1, 1.5, 0.5));
            cubeMesh.ApplyTransformation(
                new TranslateTransform3D(center.X, center.Y + 1.5, 0));
            mesh3.Merge(cubeMesh);
            center.X += 2;

            // Cylinder.
            Point3D[] polygon = G3.MakePolygonPoints(7, center, D3.XVector(1), D3.ZVector(-1));
            mesh1.AddCylinder(polygon, new Vector3D(0, 2, -1));
            center.X += 2;

            // Cylinder.
            circle = G3.MakePolygonPoints(20, center, D3.XVector(1), D3.ZVector(-1));
            mesh1.AddCylinder(circle, new Vector3D(0, 2, -1), true);
            center.X += 2;

            // Cylinder w/cutting planes.
            polygon = G3.MakePolygonPoints(7, center, D3.XVector(1), D3.ZVector(-1));
            mesh1.AddCylinder(polygon, new Vector3D(0, 1, 0),
                              center + new Vector3D(0, 2, 0), new Vector3D(0, 2, 1),
                              center + new Vector3D(0, -2, 0), new Vector3D(0, 2, -1));
            center.X += 2;

            // Cylinder w/cutting planes.
            polygon = G3.MakePolygonPoints(7, center, D3.XVector(1), D3.ZVector(-1));
            mesh1.AddCylinder(polygon, new Vector3D(0, 1, 0),
                              center + new Vector3D(0, 2, 0), new Vector3D(0, 2, 1),
                              center + new Vector3D(0, -2, 0), new Vector3D(0, 2, -1), true);
            center.X += 2;

            // Start a new row.
            center.X  = x0;
            center.Z -= 3;

            // Dodecahedron.
            MeshGeometry3D dodMesh = new MeshGeometry3D();

            dodMesh.AddDodecahedron();
            double dodScale = 1 / G3.DodecahedronCircumradius();

            dodMesh.ApplyTransformation(new ScaleTransform3D(dodScale, dodScale, dodScale));
            dodMesh.ApplyTransformation(
                new TranslateTransform3D(center.X, center.Y + 0.5, center.Z));
            mesh3.Merge(dodMesh);
            center.X += 2;

            // Frustum.
            polygon = G3.MakePolygonPoints(5, center, D3.XVector(1), D3.ZVector(-1));
            mesh1.AddFrustum(center, polygon, D3.YVector(4), 2);
            center.X += 2;

            // Icosahedron.
            MeshGeometry3D icoMesh = new MeshGeometry3D();

            icoMesh.AddIcosahedron();
            double icoScale = 1 / G3.IcosahedronCircumradius();

            icoMesh.ApplyTransformation(new ScaleTransform3D(icoScale, icoScale, icoScale));
            icoMesh.ApplyTransformation(
                new TranslateTransform3D(center.X, center.Y + 0.5, center.Z));
            mesh3.Merge(icoMesh);
            center.X += 2;

            // Octahedron.
            MeshGeometry3D octMesh = new MeshGeometry3D();

            octMesh.AddOctahedron();
            double octScale = 1 / G3.OctahedronCircumradius();

            octMesh.ApplyTransformation(new ScaleTransform3D(octScale, octScale, octScale));
            octMesh.ApplyTransformation(
                new TranslateTransform3D(center.X, center.Y + 0.5, center.Z));
            mesh3.Merge(octMesh);
            center.X += 2;

            // Pyramid.
            polygon = G3.MakePolygonPoints(6, center, D3.XVector(1), D3.ZVector(-1));
            mesh1.AddPyramid(center, polygon, D3.YVector(3));
            center.X += 2;

            // Start a new row.
            center.X  = x0;
            center.Z -= 3;

            // Sphere.
            mesh1.AddSphere(center + new Vector3D(0, 1, 0), 1, 20, 10);
            center.X += 2;

            // Tetrahedron.
            MeshGeometry3D tetMesh = new MeshGeometry3D();

            tetMesh.AddTetrahedron();
            double tetScale = 1 / G3.TetrahedronCircumradius();

            tetMesh.ApplyTransformation(new ScaleTransform3D(tetScale, tetScale, tetScale));
            tetMesh.ApplyTransformation(
                new TranslateTransform3D(center.X, center.Y + 0.5, center.Z));
            mesh3.Merge(tetMesh);
            center.X += 2;

            // Textured sphere.
            mesh4.Positions.Add(new Point3D());
            mesh4.TextureCoordinates.Add(new Point(1.01, 1.01));
            mesh4.AddTexturedSphere(center + new Vector3D(0, 1, 0), 1, 20, 10);
            center.X += 2;

            // Textured torus.
            mesh4.AddTexturedTorus(center + new Vector3D(0, 1, 0), 0.6, 0.4, 30, 15);
            center.X += 2;

            // Torus.
            mesh1.AddTorus(center + new Vector3D(0, 1, 0), 0.6, 0.4, 30, 15);
            center.X += 2;

            // Start a new row.
            center.X  = x0;
            center.Z -= 3;

            group.Children.Add(mesh1.MakeModel(Brushes.LightGreen));
            group.Children.Add(mesh2.MakeModel("wrapper.png"));
            group.Children.Add(mesh3.MakeModel(Brushes.LightBlue));
            group.Children.Add(mesh4.MakeModel("world.jpg"));
        }
Esempio n. 4
0
        /// Define the model.
        void DefineModelRobot()
        {
            Width  = 450;
            Height = 700;

            // Axes.
            MeshExtensions.AddXAxis(_group, 15, 0.1); // red = x
            MeshExtensions.AddYAxis(_group, 12, 0.1); // green = y
            MeshExtensions.AddZAxis(_group, 15, 0.1); // blue = z
            MeshExtensions.AddOrigin(_group, 0.5);    // black

            // Make the ground.
            const double groundY = -5;

            MakeGround(groundY);

            // Various robot dimensions.
            const double headR     = 1.5;            // Head radius.
            const double neckLen   = headR;          // Neck length.
            const double backLen   = 3 * headR;      // Back length.
            const double shouW     = 3 * headR;      // Shoulder width.
            const double uaLen     = 2 * headR;      // Upper arm length.
            const double laLen     = 2 * headR;      // Lower arm length
            const double hipsW     = 2 * headR;      // Hip width.
            const double ulLen     = 2 * headR;      // Upper leg length.
            const double llLen     = 2 * headR;      // Lower leg length.
            const double boneR     = 0.3;            // Bone radius.
            const double jointR    = 0.4;            // Joint radius.
            const double height    = 2 * headR + neckLen + backLen + ulLen + llLen;
            const double headY     = height - headR; // Distance from center of head to ground.
            Brush        boneBrush = Brushes.PowderBlue;

            // This group represents the whole robot.
            _groupRobot = new Model3DGroup();
            _group.Children.Add(_groupRobot);
            _groupRobot.Transform = new TranslateTransform3D(0, headY + groundY, 0);

            // Head.
            // Skull.
            MeshGeometry3D skullMesh = new MeshGeometry3D();

            skullMesh.AddSphere(D3.Origin, headR, 20, 10, true);
            GeometryModel3D skullModel = skullMesh.MakeModel(boneBrush);

            // Nose.
            MeshGeometry3D noseMesh   = new MeshGeometry3D();
            Point3D        noseCenter = new Point3D(0, 0, headR);

            Point3D[] nosePoints = G3.MakePolygonPoints(10, noseCenter, D3.XVector(headR * 0.2), D3.YVector(headR * 0.2));
            Vector3D  noseAxis   = new Vector3D(0, 0, headR);

            noseMesh.AddConeFrustum(noseCenter, nosePoints, noseAxis, headR * 0.5);
            GeometryModel3D noseModel = noseMesh.MakeModel(Brushes.Orange);

            // Eyes and smile.
            MeshGeometry3D eyeMesh   = new MeshGeometry3D();
            Point3D        eyeCenter = SphericalToCartesian(headR, -Math.PI * 0.2, Math.PI * 0.4);

            eyeMesh.AddSphere(eyeCenter, headR * 0.2, 10, 5, false);
            eyeCenter = SphericalToCartesian(headR, Math.PI * 0.2, Math.PI * 0.4);
            eyeMesh.AddSphere(eyeCenter, headR * 0.2, 10, 5, false);
            eyeCenter = SphericalToCartesian(headR, Math.PI * 0, Math.PI * 0.7);
            eyeMesh.AddSphere(eyeCenter, headR * 0.1, 10, 5, false);
            eyeCenter = SphericalToCartesian(headR, Math.PI * 0.1, Math.PI * 0.67);
            eyeMesh.AddSphere(eyeCenter, headR * 0.1, 10, 5, false);
            eyeCenter = SphericalToCartesian(headR, -Math.PI * 0.1, Math.PI * 0.67);
            eyeMesh.AddSphere(eyeCenter, headR * 0.1, 10, 5, false);
            eyeCenter = SphericalToCartesian(headR, Math.PI * 0.15, Math.PI * 0.6);
            eyeMesh.AddSphere(eyeCenter, headR * 0.1, 10, 5, false);
            eyeCenter = SphericalToCartesian(headR, -Math.PI * 0.15, Math.PI * 0.6);
            eyeMesh.AddSphere(eyeCenter, headR * 0.1, 10, 5, false);
            GeometryModel3D eyeModel = eyeMesh.MakeModel(Brushes.Black);

            // Hat.
            MeshGeometry3D hatMesh   = new MeshGeometry3D();
            Point3D        hatCenter = new Point3D(0, headR * 0.75, 0);

            hatMesh.AddSphere(hatCenter, headR * 0.75, 20, 10, true);
            const double hatR = headR * 1.2;

            Point3D[] hatPgon = G3.MakePolygonPoints(20, hatCenter, D3.XVector(hatR), D3.ZVector(hatR));
            hatMesh.AddCylinder(hatPgon, D3.YVector(-0.2), true);

            GeometryModel3D hatModel = hatMesh.MakeModel(Brushes.SaddleBrown);

            // Head groups.
            _groupHead = JoinBones(_groupRobot, null);
            _groupHead.Children.Add(skullModel);
            _groupHead.Children.Add(noseModel);
            _groupHead.Children.Add(eyeModel);
            _groupHead.Children.Add(hatModel);

            // Neck.
            MeshGeometry3D neckMesh = new MeshGeometry3D();

            Point3D[] neckPgon = G3.MakePolygonPoints(10, D3.Origin, D3.XVector(boneR), D3.ZVector(boneR));
            neckMesh.AddCylinder(neckPgon, D3.YVector(-neckLen), true);
            GeometryModel3D neckModel = neckMesh.MakeModel(boneBrush);

            _groupNeck = JoinBones(_groupHead, new TranslateTransform3D(0, -headR, 0));
            _groupNeck.Children.Add(neckModel);

            // Shoulders.
            MeshGeometry3D shoulderMesh = new MeshGeometry3D();

            Point3D[] shouldersPgon = G3.MakePolygonPoints(10, new Point3D(-shouW / 2, 0, 0), D3.ZVector(boneR), D3.YVector(-boneR));
            shoulderMesh.AddCylinder(shouldersPgon, D3.XVector(shouW), true);
            GeometryModel3D shoulderModel = shoulderMesh.MakeModel(boneBrush);

            _groupShoulder = JoinBones(_groupNeck, new TranslateTransform3D(0, -neckLen, 0));
            _groupShoulder.Children.Add(shoulderModel);

            // Left upper arm.
            MeshGeometry3D luArmMesh = new MeshGeometry3D();

            luArmMesh.AddCylinder(neckPgon, D3.YVector(-uaLen), true);
            luArmMesh.AddSphere(D3.Origin, jointR, 10, 5, true);
            GeometryModel3D luArmModel = luArmMesh.MakeModel(boneBrush);

            _groupLeftUpperArm = JoinBones(_groupShoulder, new TranslateTransform3D(shouW / 2, 0, 0));
            _groupLeftUpperArm.Children.Add(luArmModel);

            // Right upper arm.
            MeshGeometry3D ruArmMesh = new MeshGeometry3D();

            ruArmMesh.AddCylinder(neckPgon, D3.YVector(-uaLen), true);
            ruArmMesh.AddSphere(D3.Origin, jointR, 10, 5, true);
            GeometryModel3D ruArmModel = ruArmMesh.MakeModel(boneBrush);

            _groupRightUpperArm = JoinBones(_groupShoulder, new TranslateTransform3D(-shouW / 2, 0, 0));
            _groupRightUpperArm.Children.Add(ruArmModel);

            // Left lower arm.
            MeshGeometry3D llArmMesh = new MeshGeometry3D();

            llArmMesh.AddCylinder(neckPgon, D3.YVector(-laLen), true);
            llArmMesh.AddSphere(D3.Origin, jointR, 10, 5, true);
            GeometryModel3D llArmModel = llArmMesh.MakeModel(boneBrush);

            _groupLeftLowerArm = JoinBones(_groupLeftUpperArm, new TranslateTransform3D(0, -uaLen, 0));
            _groupLeftLowerArm.Children.Add(llArmModel);

            // Right lower arm.
            MeshGeometry3D rlArmMesh = new MeshGeometry3D();

            rlArmMesh.AddCylinder(neckPgon, D3.YVector(-laLen), true);
            rlArmMesh.AddSphere(D3.Origin, jointR, 10, 5, true);
            GeometryModel3D rlArmModel = rlArmMesh.MakeModel(boneBrush);

            _groupRightLowerArm = JoinBones(_groupRightUpperArm, new TranslateTransform3D(0, -uaLen, 0));
            _groupRightLowerArm.Children.Add(rlArmModel);

            // Back and hips.
            MeshGeometry3D backMesh = new MeshGeometry3D();

            backMesh.AddCylinder(neckPgon, D3.YVector(-backLen), true);
            GeometryModel3D backModel = backMesh.MakeModel(boneBrush);

            MeshGeometry3D hipsMesh = new MeshGeometry3D();

            Point3D[] hipsPgon = G3.MakePolygonPoints(10, new Point3D(-hipsW / 2, -backLen, 0), D3.ZVector(boneR), D3.YVector(-boneR));
            hipsMesh.AddCylinder(hipsPgon, D3.XVector(hipsW), true);
            GeometryModel3D hipsModel = hipsMesh.MakeModel(boneBrush);

            _groupBack = JoinBones(_groupNeck, new TranslateTransform3D(0, -neckLen, 0));
            _groupBack.Children.Add(backModel);
            _groupBack.Children.Add(hipsModel);

            // Left upper leg.
            MeshGeometry3D luLegMesh = new MeshGeometry3D();

            luLegMesh.AddCylinder(neckPgon, D3.YVector(-ulLen), true);
            luLegMesh.AddSphere(D3.Origin, jointR, 10, 5, true);
            GeometryModel3D luLegModel = luLegMesh.MakeModel(boneBrush);

            _groupLeftUpperLeg = JoinBones(_groupBack, new TranslateTransform3D(-hipsW / 2, -backLen, 0));
            _groupLeftUpperLeg.Children.Add(luLegModel);

            // Right upper leg.
            MeshGeometry3D ruLegMesh = new MeshGeometry3D();

            ruLegMesh.AddCylinder(neckPgon, D3.YVector(-ulLen), true);
            ruLegMesh.AddSphere(D3.Origin, jointR, 10, 5, true);
            GeometryModel3D ruLegModel = ruLegMesh.MakeModel(boneBrush);

            _groupRightUpperLeg = JoinBones(_groupBack, new TranslateTransform3D(hipsW / 2, -backLen, 0));
            _groupRightUpperLeg.Children.Add(ruLegModel);

            // Left lower leg.
            MeshGeometry3D llLegMesh = new MeshGeometry3D();

            llLegMesh.AddCylinder(neckPgon, D3.YVector(-llLen), true);
            llLegMesh.AddSphere(D3.Origin, jointR, 10, 5, true);
            GeometryModel3D llLegModel = llLegMesh.MakeModel(boneBrush);

            _groupLeftLowerLeg = JoinBones(_groupLeftUpperLeg, new TranslateTransform3D(0, -ulLen, 0));
            _groupLeftLowerLeg.Children.Add(llLegModel);

            // Right lower leg.
            MeshGeometry3D rlLegMesh = new MeshGeometry3D();

            rlLegMesh.AddCylinder(neckPgon, D3.YVector(-llLen), true);
            rlLegMesh.AddSphere(D3.Origin, jointR, 10, 5, true);
            GeometryModel3D rlLegModel = rlLegMesh.MakeModel(boneBrush);

            _groupRightLowerLeg = JoinBones(_groupRightUpperLeg, new TranslateTransform3D(0, -ulLen, 0));
            _groupRightLowerLeg.Children.Add(rlLegModel);
        }