示例#1
0
        private void UpdatePoints()
        {
            int    quater = Math.Max(SegmentsCount / 4 - 1, 1);
            double angle  = 360.0 / SegmentsCount;
            double sin    = Math.Sin(MathHelp.DegreesToRadians(-angle));
            double cos    = Math.Cos(MathHelp.DegreesToRadians(-angle));

            Point3D[,] points = new Point3D[quater, SegmentsCount + 1];
            points[0, 0]      = new Point3D(-Radius, 0, 0);
            for (int i = 1; i < quater; ++i)
            {
                double x = points[i - 1, 0].X * cos - points[i - 1, 0].Y * sin;
                double y = points[i - 1, 0].X * sin + points[i - 1, 0].Y * cos;
                points[i, 0] = new Point3D(x, y, 0);
            }
            Faces.Clear();

            for (int i = 1; i <= SegmentsCount; ++i)
            {
                for (int j = 0; j < quater; ++j)
                {
                    double x = points[j, i - 1].X * cos - points[j, i - 1].Z * sin;
                    double z = points[j, i - 1].X * sin + points[j, i - 1].Z * cos;
                    points[j, i] = new Point3D(x, points[j, i - 1].Y, z);
                    if (i > 0)
                    {
                        if (j > 0)
                        {
                            Faces.Add(new Face(new Point3D[] {
                                new Point3D(points[j - 1, i - 1].X, points[j - 1, i - 1].Y, points[j - 1, i - 1].Z),
                                new Point3D(points[j - 1, i].X, points[j - 1, i].Y, points[j - 1, i].Z),
                                new Point3D(points[j, i - 1].X, points[j, i - 1].Y, points[j, i - 1].Z)
                            }));
                            Faces.Add(new Face(new Point3D[] {
                                new Point3D(points[j, i - 1].X, points[j, i - 1].Y, points[j, i - 1].Z),
                                new Point3D(points[j, i].X, points[j, i].Y, points[j, i].Z),
                                new Point3D(points[j - 1, i].X, points[j - 1, i].Y, points[j - 1, i].Z)
                            }));
                        }
                        else if (closeBottom)
                        {
                            Faces.Add(new Face(new Point3D[] {
                                new Point3D(points[j, i - 1].X, points[j, i - 1].Y, points[j, i - 1].Z),
                                new Point3D(points[j, i].X, points[j, i].Y, points[j, i].Z),
                                new Point3D(0, 0, 0)
                            }));
                        }
                        if (j == quater - 1)
                        {
                            Faces.Add(new Face(new Point3D[] {
                                new Point3D(points[j, i - 1].X, points[j, i - 1].Y, points[j, i - 1].Z),
                                new Point3D(points[j, i].X, points[j, i].Y, points[j, i].Z),
                                new Point3D(0, Radius, 0)
                            }));
                        }
                    }
                }
            }
        }
示例#2
0
        public Matrix GetGizmoModificationMatrix()
        {
            Matrix matrix = ModificationMatrix.GetIdentityMatrix(4);

            matrix = matrix.Multiply(ModificationMatrix.GetRotateXMatrix(MathHelp.DegreesToRadians(AngleX)));
            matrix = matrix.Multiply(ModificationMatrix.GetRotateYMatrix(MathHelp.DegreesToRadians(AngleY)));
            matrix = matrix.Multiply(ModificationMatrix.GetRotateZMatrix(MathHelp.DegreesToRadians(AngleZ)));
            return(matrix);
        }
示例#3
0
        public void RotatePositionUpDown(double angle)
        {
            Matrix rotateMatrix = ModificationMatrix.GetMoveMatrix(-Target.X, -Target.Y, -Target.Z);

            rotateMatrix = rotateMatrix.Multiply(Position.GetProjectiveCoordinates());
            Position.Set(rotateMatrix[0, 0], rotateMatrix[1, 0], rotateMatrix[2, 0]);

            angle += MathHelp.RadiansToDegrees(Position.Theta);
            angle  = Math.Min(Math.Max(angle, MIN_THETA), MAX_THETA);
            Position.SetTheta(MathHelp.DegreesToRadians(angle));
            AngleTheta = 180 - (int)angle;

            rotateMatrix = ModificationMatrix.GetMoveMatrix(Target.X, Target.Y, Target.Z);
            rotateMatrix = rotateMatrix.Multiply(Position.GetProjectiveCoordinates());
            Position.Set(rotateMatrix[0, 0], rotateMatrix[1, 0], rotateMatrix[2, 0]);
        }
示例#4
0
        public void RotateTargetLeftRight(double angle)
        {
            Matrix rotateMatrix = ModificationMatrix.GetMoveMatrix(-Position.X, -Position.Y, -Position.Z);

            rotateMatrix = rotateMatrix.Multiply(Target.GetProjectiveCoordinates());
            Target.Set(rotateMatrix[0, 0], rotateMatrix[1, 0], rotateMatrix[2, 0]);

            angle += MathHelp.RadiansToDegrees(Target.Phi);
            angle %= 360;
            angle  = angle < 0 ? 360 + angle : angle;

            Target.SetPhi(MathHelp.DegreesToRadians(angle));
            AnglePhi = (int)angle;

            rotateMatrix = ModificationMatrix.GetMoveMatrix(Position.X, Position.Y, Position.Z);
            rotateMatrix = rotateMatrix.Multiply(Target.GetProjectiveCoordinates());
            Target.Set(rotateMatrix[0, 0], rotateMatrix[1, 0], rotateMatrix[2, 0]);
        }
示例#5
0
        private void DrawLine(FastBitmap bitmap, double[,] buffer, Point3D start, Point3D end, Color color)
        {
            double dx = end.X - start.X;
            double dy = end.Y - start.Y;

            if (Math.Abs(dx) > Math.Abs(dy))
            {
                if (dx < 0)
                {
                    MathHelp.Swap(ref start, ref end);
                }
                double[] ys = MathHelp.Interpolate(start.X, start.Y, end.X, end.Y);
                double[] zs = MathHelp.Interpolate(start.X, start.Z, end.X, end.Z);
                Parallel.For((int)start.X, (int)end.X, x =>
                {
                    int y    = (int)ys[(int)(x - start.X)];
                    double z = zs[(int)(x - start.X)];
                    if (IsOnImage((int)x, y) && buffer[(int)x, y] >= z)
                    {
                        buffer[(int)x, y] = z;
                        bitmap.SetPixel((int)x, y, color);
                    }
                });
            }
            else
            {
                if (dy < 0)
                {
                    MathHelp.Swap(ref start, ref end);
                }
                double[] xs = MathHelp.Interpolate(start.Y, start.X, end.Y, end.X);
                double[] zs = MathHelp.Interpolate(start.Y, start.Z, end.Y, end.Z);
                Parallel.For((int)start.Y, (int)end.Y, y =>
                {
                    int x    = (int)xs[(int)(y - start.Y)];
                    double z = zs[(int)(y - start.Y)];
                    if (IsOnImage(x, (int)y) && buffer[x, (int)y] >= z)
                    {
                        buffer[x, (int)y] = z;
                        bitmap.SetPixel(x, (int)y, color);
                    }
                });
            }
        }
示例#6
0
 private void Triangle(Vector3D p0, Vector3D p1, Vector3D p2, Color color, FastBitmap bitmap, double[,] buffer)
 {
     if (p0.Y != p1.Y || p0.Y != p2.Y)
     {
         if (p0.Y > p1.Y)
         {
             MathHelp.Swap(ref p0, ref p1);
         }
         if (p0.Y > p2.Y)
         {
             MathHelp.Swap(ref p0, ref p2);
         }
         if (p1.Y > p2.Y)
         {
             MathHelp.Swap(ref p1, ref p2);
         }
         int totalHeight = (int)Math.Round(p2.Y - p0.Y);
         Parallel.For(0, totalHeight - 1, i =>
         {
             bool secondHalf   = i > p1.Y - p0.Y || p1.Y == p0.Y;
             int segmentHeight = (int)Math.Round(secondHalf ? p2.Y - p1.Y : p1.Y - p0.Y);
             double alpha      = (double)i / totalHeight;
             double beta       = (i - (secondHalf ? p1.Y - p0.Y : 0.0)) / segmentHeight;
             Vector3D a        = p0 + (p2 - p0) * alpha;
             Vector3D b        = (secondHalf ? p1 + (p2 - p1) * beta : p0 + (p1 - p0) * beta);
             if (a.X > b.X)
             {
                 MathHelp.Swap(ref a, ref b);
             }
             for (int j = (int)Math.Round(a.X); j <= (int)Math.Round(b.X); ++j)
             {
                 double scale = (a.X == b.X) ? 1 : (j - a.X) / (b.X - a.X);
                 Vector3D p   = a + (b - a) * scale;
                 int x        = (int)Math.Round(p.X);
                 int y        = (int)Math.Round(p.Y);
                 if (IsOnImage(x, y) && buffer[x, y] >= p.Z)
                 {
                     buffer[x, y] = p.Z;
                     bitmap.SetPixel(x, y, color);
                 }
             }
         });
     }
 }
示例#7
0
        private void UpdatePoints()
        {
            double angle = 360.0 / SegmentsCount;
            double sin   = Math.Sin(MathHelp.DegreesToRadians(angle));
            double cos   = Math.Cos(MathHelp.DegreesToRadians(angle));

            Point3D[] points = new Point3D[SegmentsCount + 1];
            points[0] = new Point3D(-Radius, 0, 0);
            Faces.Clear();

            for (int i = 1; i <= SegmentsCount; ++i)
            {
                double x = points[i - 1].X * cos - points[i - 1].Z * sin;
                double z = points[i - 1].X * sin + points[i - 1].Z * cos;
                points[i] = new Point3D(x, 0, z);
                if (i > 0)
                {
                    Faces.Add(new Face(new Point3D[] {
                        new Point3D(points[i - 1].X, 0, points[i - 1].Z),
                        new Point3D(points[i].X, 0, points[i].Z),
                        new Point3D(0, 0, 0)
                    }));
                    Faces.Add(new Face(new Point3D[] {
                        new Point3D(points[i - 1].X, Height, points[i - 1].Z),
                        new Point3D(points[i].X, Height, points[i].Z),
                        new Point3D(0, Height, 0)
                    }));
                    Faces.Add(new Face(new Point3D[] {
                        new Point3D(points[i - 1].X, Height, points[i - 1].Z),
                        new Point3D(points[i].X, Height, points[i].Z),
                        new Point3D(points[i - 1].X, 0, points[i - 1].Z)
                    }));
                    Faces.Add(new Face(new Point3D[] {
                        new Point3D(points[i - 1].X, 0, points[i - 1].Z),
                        new Point3D(points[i].X, 0, points[i].Z),
                        new Point3D(points[i].X, Height, points[i].Z)
                    }));
                }
            }
        }
示例#8
0
        private void UpdatePoints()
        {
            double angle = 360.0 / SegmentsCount;
            double sin   = Math.Sin(MathHelp.DegreesToRadians(angle));
            double cos   = Math.Cos(MathHelp.DegreesToRadians(angle));

            Point3D[,,] points         = new Point3D[2, 2, SegmentsCount + 1];
            points[BOTTOM, INSIDE, 0]  = new Point3D(-BottomRadius, 0, 0);
            points[BOTTOM, OUTSIDE, 0] = new Point3D(-(BottomRadius + Thickness), 0, 0);
            points[TOP, INSIDE, 0]     = new Point3D(-TopRadius, Height, 0);
            points[TOP, OUTSIDE, 0]    = new Point3D(-(TopRadius + Thickness), Height, 0);
            Faces.Clear();

            for (int i = 1; i <= SegmentsCount; ++i)
            {
                double x = points[BOTTOM, INSIDE, i - 1].X * cos - points[BOTTOM, INSIDE, i - 1].Z * sin;
                double z = points[BOTTOM, INSIDE, i - 1].X * sin + points[BOTTOM, INSIDE, i - 1].Z * cos;
                points[BOTTOM, INSIDE, i] = new Point3D(x, 0, z);

                x = points[BOTTOM, OUTSIDE, i - 1].X * cos - points[BOTTOM, OUTSIDE, i - 1].Z * sin;
                z = points[BOTTOM, OUTSIDE, i - 1].X * sin + points[BOTTOM, OUTSIDE, i - 1].Z * cos;
                points[BOTTOM, OUTSIDE, i] = new Point3D(x, 0, z);

                x = points[TOP, INSIDE, i - 1].X * cos - points[TOP, INSIDE, i - 1].Z * sin;
                z = points[TOP, INSIDE, i - 1].X * sin + points[TOP, INSIDE, i - 1].Z * cos;
                points[TOP, INSIDE, i] = new Point3D(x, Height, z);

                x = points[TOP, OUTSIDE, i - 1].X * cos - points[TOP, OUTSIDE, i - 1].Z * sin;
                z = points[TOP, OUTSIDE, i - 1].X * sin + points[TOP, OUTSIDE, i - 1].Z * cos;
                points[TOP, OUTSIDE, i] = new Point3D(x, Height, z);

                if (i > 0)
                {
                    Faces.Add(new Face(new Point3D[] {
                        points[TOP, OUTSIDE, i - 1],
                        points[TOP, OUTSIDE, i],
                        points[BOTTOM, OUTSIDE, i - 1]
                    }));
                    Faces.Add(new Face(new Point3D[] {
                        points[BOTTOM, OUTSIDE, i - 1],
                        points[BOTTOM, OUTSIDE, i],
                        points[TOP, OUTSIDE, i]
                    }));

                    Faces.Add(new Face(new Point3D[] {
                        points[TOP, INSIDE, i - 1],
                        points[TOP, INSIDE, i],
                        points[BOTTOM, INSIDE, i - 1]
                    }));
                    Faces.Add(new Face(new Point3D[] {
                        points[BOTTOM, INSIDE, i - 1],
                        points[BOTTOM, INSIDE, i],
                        points[TOP, INSIDE, i]
                    }));

                    Faces.Add(new Face(new Point3D[] {
                        points[TOP, INSIDE, i - 1],
                        points[TOP, INSIDE, i],
                        points[TOP, OUTSIDE, i - 1]
                    }));
                    Faces.Add(new Face(new Point3D[] {
                        points[TOP, OUTSIDE, i - 1],
                        points[TOP, OUTSIDE, i],
                        points[TOP, INSIDE, i]
                    }));

                    Faces.Add(new Face(new Point3D[] {
                        points[BOTTOM, INSIDE, i - 1],
                        points[BOTTOM, INSIDE, i],
                        points[BOTTOM, OUTSIDE, i - 1]
                    }));
                    Faces.Add(new Face(new Point3D[] {
                        points[BOTTOM, OUTSIDE, i - 1],
                        points[BOTTOM, OUTSIDE, i],
                        points[BOTTOM, INSIDE, i]
                    }));
                }
            }
        }