예제 #1
0
파일: Form1.cs 프로젝트: AndrewSerb/cg-lr3
        private void DefaultTransformVals()
        {
            objCentre        = InitObjCentre;
            SurfCentre       = InitSurfCentre;
            OldScalVal       = ScalVal = 1;
            ScalValBox.Value = 1;
            if (PyramidRB.Checked)
            {
                OldTransVals.X = TransVals.X = objCentre.X;
                OldTransVals.Y = TransVals.Y = objCentre.Y;
                OldTransVals.Z = TransVals.Z = objCentre.Z;
            }
            else
            {
                OldTransVals.X = TransVals.X = SurfCentre.X;
                OldTransVals.Y = TransVals.Y = SurfCentre.Y;
                OldTransVals.Z = TransVals.Z = SurfCentre.Z;
            }
            XTransBox.Value = (decimal)OldTransVals.X;
            YTransBox.Value = (decimal)OldTransVals.Y;
            ZTransBox.Value = (decimal)OldTransVals.Z;

            XRotValue        = YRotValue = ZRotValue = OldXRotValue = OldYRotValue = OldZRotValue = 0;
            ZRotBox.Value    = YRotBox.Value = XRotBox.Value = 0;
            obj              = (Polygon3D[])InitObj.Clone();
            bs.ControlPoints = (PointF3D[, ])InitCntrlPoints.Clone();
        }
예제 #2
0
        public static PointF3D[] Translate3D(PointF3D[] obj, double x, double y, double z)
        {
            PointF3D[] TranslatedtedObj = new PointF3D[obj.Length];
            obj.CopyTo(TranslatedtedObj, 0);
            Matrix CurPoint;

            for (int i = 0; i < TranslatedtedObj.Length; i++)
            {
                CurPoint = Form3DCoordsMatrix(obj[i].X, obj[i].Y, obj[i].Z);
                CurPoint = Get3DTranslationMatrix(x, y, z).Multiply(CurPoint);
                TranslatedtedObj[i].X = (float)CurPoint.GetElementValue(0, 0);
                TranslatedtedObj[i].Y = (float)CurPoint.GetElementValue(1, 0);
                TranslatedtedObj[i].Z = (float)CurPoint.GetElementValue(2, 0);
            }

            return(TranslatedtedObj);
        }
예제 #3
0
        public static PointF3D[] RotateZ3D(PointF3D[] obj, double angle, PointF3D RotationCentre)
        {
            PointF3D[] RotatedObj = new PointF3D[obj.Length];
            obj.CopyTo(RotatedObj, 0);

            RotatedObj = Translate3D(RotatedObj, -RotationCentre.X, -RotationCentre.Y, -RotationCentre.Z);

            Matrix CurPoint;

            for (int i = 0; i < RotatedObj.Length; i++)
            {
                CurPoint        = Form3DCoordsMatrix(RotatedObj[i].X, RotatedObj[i].Y, RotatedObj[i].Z);
                CurPoint        = GetZRotation3DMatrix(angle).Multiply(CurPoint);
                RotatedObj[i].X = (float)CurPoint.GetElementValue(0, 0);
                RotatedObj[i].Y = (float)CurPoint.GetElementValue(1, 0);
                RotatedObj[i].Z = (float)CurPoint.GetElementValue(2, 0);
            }

            RotatedObj = Translate3D(RotatedObj, RotationCentre.X, RotationCentre.Y, RotationCentre.Z);
            return(RotatedObj);
        }
예제 #4
0
        public static PointF3D[] Scale3D(PointF3D[] obj, double xScal, double yScal, double zScal, PointF3D ScalingCentre)
        {
            PointF3D[] ScaledtedObj = new PointF3D[obj.Length];
            obj.CopyTo(ScaledtedObj, 0);

            ScaledtedObj = Translate3D(ScaledtedObj, -ScalingCentre.X, -ScalingCentre.Y, -ScalingCentre.Z);

            Matrix CurPoint;

            for (int i = 0; i < ScaledtedObj.Length; i++)
            {
                CurPoint          = Form3DCoordsMatrix(ScaledtedObj[i].X, ScaledtedObj[i].Y, ScaledtedObj[i].Z);
                CurPoint          = Get3DScalingMatrix(xScal, yScal, zScal).Multiply(CurPoint);
                ScaledtedObj[i].X = (float)CurPoint.GetElementValue(0, 0);
                ScaledtedObj[i].Y = (float)CurPoint.GetElementValue(1, 0);
                ScaledtedObj[i].Z = (float)CurPoint.GetElementValue(2, 0);
            }

            ScaledtedObj = Translate3D(ScaledtedObj, ScalingCentre.X, ScalingCentre.Y, ScalingCentre.Z);

            return(ScaledtedObj);
        }
예제 #5
0
파일: Form1.cs 프로젝트: AndrewSerb/cg-lr3
        public cg_lr3()
        {
            InitializeComponent();

            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

            OldTransVals = new PointF3D();
            TransVals    = new PointF3D();
            ScalVal      = OldScalVal = 1;
            XRotValue    = ZRotValue = YRotValue = OldXRotValue = OldYRotValue = OldZRotValue = 0;

            // Lower pentagon
            PointF3D LowerP1 = new PointF3D(1, 0, 0);
            PointF3D LowerP2 = new PointF3D(0, 0, 3);
            PointF3D LowerP3 = new PointF3D(2.5f, 0, 4.8f);
            PointF3D LowerP4 = new PointF3D(5, 0, 3);
            PointF3D LowerP5 = new PointF3D(4, 0, 0);

            // Upper pentagon
            PointF3D UpperP1 = new PointF3D(1.5f, 5, 1);
            PointF3D UpperP2 = new PointF3D(1.1f, 5, 2.6f);
            PointF3D UpperP3 = new PointF3D(2.5f, 5, 3.9f);
            PointF3D UpperP4 = new PointF3D(4.1f, 5, 2.6f);
            PointF3D UpperP5 = new PointF3D(3.5f, 5, 1f);

            InitObj = new Polygon3D[]   //pyramid
            {
                // lower pentagon
                new Polygon3D(new PointF3D[] { LowerP1, LowerP2, LowerP3, LowerP4, LowerP5 }),
                // lines connecting the pentagons
                new Polygon3D(new PointF3D[] { LowerP1, UpperP1 }),
                new Polygon3D(new PointF3D[] { LowerP2, UpperP2 }),
                new Polygon3D(new PointF3D[] { LowerP3, UpperP3 }),
                new Polygon3D(new PointF3D[] { LowerP4, UpperP4 }),
                new Polygon3D(new PointF3D[] { LowerP5, UpperP5 }),
                //upper pentagon
                new Polygon3D(new PointF3D[] { UpperP1, UpperP2, UpperP3, UpperP4, UpperP5 })
            };
            obj = (Polygon3D[])InitObj.Clone();

            InitObjCentre = new PointF3D(2, 2, 2);
            objCentre     = InitObjCentre;

            InitCntrlPoints = new PointF3D[4, 4]
            {
                { new PointF3D(0, 0, 0), new PointF3D(1, 0, 0), new PointF3D(2, 0, 0), new PointF3D(3, 0, 0) },
                { new PointF3D(0, 0, 1), new PointF3D(1, 0, 1), new PointF3D(2, 0, 1), new PointF3D(3, 0, 1) },
                { new PointF3D(0, 0, 2), new PointF3D(1, 0, 2), new PointF3D(2, 0, 2), new PointF3D(3, 0, 2) },
                { new PointF3D(0, 0, 3), new PointF3D(1, 0, 3), new PointF3D(2, 0, 3), new PointF3D(3, 0, 3) }
            };

            bs             = new BezierSurface(InitCntrlPoints, 0.2);
            InitSurfCentre = new PointF3D(1.5f, 0, 1.5f);
            SurfCentre     = InitSurfCentre;
            RedactCPIndex  = new Point(-1, -1);
            DefaultTransformVals();

            PointF[] ProjectedDimAxes = Affinity3D.ProjectDimetric(CoordinateLines);
            PointF[] ProjectedXYAxes  = Affinity3D.ProjectToXY(CoordinateLines);
            PointF[] ProjectedYZAxes  = Affinity3D.ProjectToYZ(CoordinateLines);
            PointF[] ProjectedZXAxes  = Affinity3D.ProjectToZX(CoordinateLines);

            NormalisedDimetricAxes = new Point[ProjectedDimAxes.Length];
            NormalisedXYAxes       = new Point[ProjectedXYAxes.Length];
            NormalisedYZAxes       = new Point[ProjectedYZAxes.Length];
            NormalisedZXAxes       = new Point[ProjectedZXAxes.Length];

            for (int i = 0; i < CoordinateLines.Length; i++)
            {
                NormalisedDimetricAxes[i].X = Normalisation.NormaliseX(ProjectedDimAxes[i].X, DimetricMinBorder, DimetricMaxBorder, paneldimetric.Width);
                NormalisedDimetricAxes[i].Y = Normalisation.NormaliseY(ProjectedDimAxes[i].Y, DimetricMinBorder, DimetricMaxBorder, paneldimetric.Height);
                NormalisedXYAxes[i].X       = Normalisation.NormaliseX(ProjectedXYAxes[i].X, SideProjMinBorder, SideProjMaxBorder, panelxy.Width);
                NormalisedXYAxes[i].Y       = Normalisation.NormaliseY(ProjectedXYAxes[i].Y, SideProjMinBorder, SideProjMaxBorder, panelxy.Height);
                NormalisedYZAxes[i].X       = Normalisation.NormaliseX(ProjectedYZAxes[i].X, SideProjMinBorder, SideProjMaxBorder, panelyz.Width);
                NormalisedYZAxes[i].Y       = Normalisation.NormaliseY(ProjectedYZAxes[i].Y, SideProjMinBorder, SideProjMaxBorder, panelyz.Height);
                NormalisedZXAxes[i].X       = Normalisation.NormaliseX(ProjectedZXAxes[i].X, SideProjMinBorder, SideProjMaxBorder, panelzx.Width);
                NormalisedZXAxes[i].Y       = Normalisation.NormaliseY(ProjectedZXAxes[i].Y, SideProjMinBorder, SideProjMaxBorder, panelzx.Height);
            }
        }
예제 #6
0
파일: Form1.cs 프로젝트: AndrewSerb/cg-lr3
        private void TransformObject()
        {
            if (OldXRotValue != XRotValue)
            {
                if (PyramidRB.Checked)
                {
                    for (int i = 0; i < obj.Length; i++)
                    {
                        obj[i].Outline = obj[i].RotateX(XRotValue - OldXRotValue, objCentre);
                    }
                }
                else
                {
                    bs.ControlPoints = bs.RotateX(XRotValue - OldXRotValue, SurfCentre);
                }
                OldXRotValue = XRotValue;
            }
            if (OldYRotValue != YRotValue)
            {
                if (PyramidRB.Checked)
                {
                    for (int i = 0; i < obj.Length; i++)
                    {
                        obj[i].Outline = obj[i].RotateY(YRotValue - OldYRotValue, objCentre);
                    }
                }
                else
                {
                    bs.ControlPoints = bs.RotateY(YRotValue - OldYRotValue, SurfCentre);
                }
                OldYRotValue = YRotValue;
            }
            if (OldZRotValue != ZRotValue)
            {
                if (PyramidRB.Checked)
                {
                    for (int i = 0; i < obj.Length; i++)
                    {
                        obj[i].Outline = obj[i].RotateZ(ZRotValue - OldZRotValue, objCentre);
                    }
                }
                else
                {
                    bs.ControlPoints = bs.RotateZ(ZRotValue - OldZRotValue, SurfCentre);
                }
                OldZRotValue = ZRotValue;
            }
            if (OldTransVals != TransVals)
            {
                if (PyramidRB.Checked)
                {
                    for (int i = 0; i < obj.Length; i++)
                    {
                        obj[i].Outline = obj[i].Translate(new PointF3D(TransVals.X - OldTransVals.X, TransVals.Y - OldTransVals.Y, TransVals.Z - OldTransVals.Z));
                    }
                    objCentre.X += TransVals.X - OldTransVals.X;
                    objCentre.Y += TransVals.Y - OldTransVals.Y;
                    objCentre.Z += TransVals.Z - OldTransVals.Z;
                }
                else
                {
                    bs.ControlPoints = bs.Translate(new PointF3D(TransVals.X - OldTransVals.X, TransVals.Y - OldTransVals.Y, TransVals.Z - OldTransVals.Z));
                    SurfCentre.X    += TransVals.X - OldTransVals.X;
                    SurfCentre.Y    += TransVals.Y - OldTransVals.Y;
                    SurfCentre.Z    += TransVals.Z - OldTransVals.Z;
                }

                OldTransVals = TransVals;
            }
            if (OldScalVal != ScalVal)
            {
                float curscalval = ScalVal / OldScalVal;
                if (PyramidRB.Checked)
                {
                    for (int i = 0; i < obj.Length; i++)
                    {
                        obj[i].Outline = obj[i].Scale(new PointF3D(curscalval, curscalval, curscalval), objCentre);
                    }
                }
                else
                {
                    bs.ControlPoints = bs.Scale(new PointF3D(curscalval, curscalval, curscalval), SurfCentre);
                }
                OldScalVal = ScalVal;
            }
        }
예제 #7
0
파일: Form1.cs 프로젝트: AndrewSerb/cg-lr3
        /// <summary>
        /// Draws Bezier surface to the Graphics object.
        /// </summary>
        /// <param name="g">0 - dimetric, 1 - xy, 2 - yz, 3 - zx</param>
        private void DrawSurface(Graphics g, int drawTo)
        {
            int PointCount = bs.DrawPoints.GetLength(0);

            PointF3D[] Surfpoints = new PointF3D[PointCount * PointCount];
            PointF[]   prSurfPoints;
            Point[]    nPrSurfPoints = new Point[Surfpoints.Length];

            switch (drawTo)
            {
            case 0:
                prSurfPoints = bs.ProjectDimetric();
                for (int i = 0; i < nPrSurfPoints.Length; i++)
                {
                    nPrSurfPoints[i].X = Normalisation.NormaliseX(prSurfPoints[i].X, DimetricMinBorder, DimetricMaxBorder, paneldimetric.Width);
                    nPrSurfPoints[i].Y = Normalisation.NormaliseY(prSurfPoints[i].Y, DimetricMinBorder, DimetricMaxBorder, paneldimetric.Height);
                }
                break;

            case 1:
                prSurfPoints = bs.ProjectXY();
                for (int i = 0; i < nPrSurfPoints.Length; i++)
                {
                    nPrSurfPoints[i].X = Normalisation.NormaliseX(prSurfPoints[i].X, SideProjMinBorder, SideProjMaxBorder, panelxy.Width);
                    nPrSurfPoints[i].Y = Normalisation.NormaliseY(prSurfPoints[i].Y, SideProjMinBorder, SideProjMaxBorder, panelxy.Height);
                }
                break;

            case 2:
                prSurfPoints = bs.ProjectYZ();
                for (int i = 0; i < nPrSurfPoints.Length; i++)
                {
                    nPrSurfPoints[i].X = Normalisation.NormaliseX(prSurfPoints[i].X, SideProjMinBorder, SideProjMaxBorder, panelyz.Width);
                    nPrSurfPoints[i].Y = Normalisation.NormaliseY(prSurfPoints[i].Y, SideProjMinBorder, SideProjMaxBorder, panelyz.Height);
                }
                break;

            case 3:
                prSurfPoints = bs.ProjectZX();
                for (int i = 0; i < nPrSurfPoints.Length; i++)
                {
                    nPrSurfPoints[i].X = Normalisation.NormaliseX(prSurfPoints[i].X, SideProjMinBorder, SideProjMaxBorder, panelzx.Width);
                    nPrSurfPoints[i].Y = Normalisation.NormaliseY(prSurfPoints[i].Y, SideProjMinBorder, SideProjMaxBorder, panelzx.Height);
                }
                break;
            }

            Point[,] nPrSP2Dim = new Point[PointCount, PointCount];
            for (int r = 0; r < PointCount; r++)
            {
                for (int c = 0; c < PointCount; c++)
                {
                    nPrSP2Dim[r, c] = nPrSurfPoints[r * PointCount + c];
                }
            }

            Pen pen = new Pen(Color.Red);

            for (int r = 0; r < PointCount - 1; r++)
            {
                for (int c = 0; c < PointCount - 1; c++)
                {
                    g.DrawLine(pen, nPrSP2Dim[r, c], nPrSP2Dim[r, c + 1]);
                    g.DrawLine(pen, nPrSP2Dim[r, c], nPrSP2Dim[r + 1, c]);
                }
            }
            for (int i = 0; i < PointCount - 1; i++)
            {
                g.DrawLine(pen, nPrSP2Dim[i, PointCount - 1], nPrSP2Dim[i + 1, PointCount - 1]);
                g.DrawLine(pen, nPrSP2Dim[PointCount - 1, i], nPrSP2Dim[PointCount - 1, i + 1]);
            }

            if (checkBox1.Checked)
            {
                PointF     cp        = new Point();
                SolidBrush brush     = new SolidBrush(Color.Black);
                int        circleRad = 3;
                for (int r = 0; r < 4; r++)
                {
                    for (int c = 0; c < 4; c++)
                    {
                        cp   = Affinity3D.ProjectDimetric(new PointF3D[] { bs.ControlPoints[r, c] })[0];
                        cp.X = Normalisation.NormaliseX(cp.X, DimetricMinBorder, DimetricMaxBorder, paneldimetric.Width);
                        cp.Y = Normalisation.NormaliseY(cp.Y, DimetricMinBorder, DimetricMaxBorder, paneldimetric.Height);

                        g.FillEllipse(brush, cp.X - circleRad, cp.Y - circleRad, circleRad * 2, circleRad * 2);
                        g.DrawString("P" + (r + 1) + (c + 1), Font, brush, cp);
                    }
                }
            }
        }