如何在C#GDI +中正确着色?

问题描述 投票:0回答:1

我有这个任务,我需要使用C#GDI +创建一个带有Color的旋转3D城堡。我挤满了,决定在这里下载一个已经建成的程序:https://code.msdn.microsoft.com/windowsdesktop/3D-Modeling-using-GDI-b93937b9

我用我的顶点,边和面替换了VectorShape.cs中的形状。另外,我已经添加了一些额外的代码来使形状着色。

for (int i = 0; i < 6; i++)
        {
            Point[] point2D = new Point[m_face[i].Length]; //I added this
            //iterate each edges in that face
            for (int j = 0; j < m_face[i].Length; j++)
            {

                int k=m_face[i][j];

                GraphicsState _s1 = g.Save();
                GraphicsContainer a = g.BeginContainer();
                Point3d p1 =m_vertex[m_edges[k][0]];
                Point3d p2 = m_vertex[m_edges[k][1]];
                double[] _p1 = ProjMatrix.ApplyTransform(p1.X,p1.Y,p1.Z, 1);
                double[] _p2 = ProjMatrix.ApplyTransform(p2.X, p2.Y, p2.Z, 1);
                P1.X = (int)_p1[0]; P1.Y = -(int)_p1[1];
                P2.X = (int)_p2[0]; P2.Y = -(int)_p2[1];

                point2D[j].X = P2.X; //I added this
                point2D[j].Y = P2.Y; //I added this
                g.DrawLine(m_pen,P1, P2);
                g.ResetTransform();
                g.EndContainer(a); 
                g.Restore(_s1);
            }
            g.FillPolygon(Brushes.Gray, point2D); //I added this.
        }

正面和背面都可以,但是当渲染侧面,顶面和底面时,着色看起来像这样:Badly Colored Side Badly Colored Castle

我试图给程序附带的立方体上色。输出类似。正面和背面都没问题。其他面孔都很糟糕。所以,我认为问题是我下载它的代码。我已经尝试过使用类似的GDI +程序,但这是唯一可以手动放置顶点,边和面的程序。我也无法从零开始构建程序,因为我对3D内容知之甚少,老实说。

c# colors 3d gdi+
1个回答
0
投票

尝试使用Antialiasing SmoothingMode

mygraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
© www.soinside.com 2019 - 2024. All rights reserved.