当前位置: 首页>>代码示例>>C#>>正文


C# PixelBuffer.WriteToXPM方法代码示例

本文整理汇总了C#中PixelBuffer.WriteToXPM方法的典型用法代码示例。如果您正苦于以下问题:C# PixelBuffer.WriteToXPM方法的具体用法?C# PixelBuffer.WriteToXPM怎么用?C# PixelBuffer.WriteToXPM使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PixelBuffer的用法示例。


在下文中一共展示了PixelBuffer.WriteToXPM方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main


//.........这里部分代码省略.........
            double normalizerVPN = System.Math.Sqrt(System.Math.Pow(a.VPN_X, 2) + System.Math.Pow(a.VPN_Y, 2) + System.Math.Pow(a.VPN_Z, 2));
            double VPN_X = a.VPN_X / normalizerVPN;
            double VPN_Y = a.VPN_Y / normalizerVPN;
            double VPN_Z = a.VPN_Z / normalizerVPN;
            Matrix4<double> cameraRotation = new Matrix4<double>
                (
                VRR_X, VRR_Y, VRR_Z, 0,
                VUP_X, VUP_Y, VUP_Z, 0,
                VPN_X, VPN_Y, VPN_Z, 0,
                0, 0, 0, 1
                );

            Matrix4<double> projection;
            if (a.IsParallelProjection)
            {
                projection = Matrix4<double>.GetParallelProjectionMatrix(a.VRC_UMIN, a.VRC_UMAX, a.VRC_VMIN, a.VRC_VMAX, a.PRP_X, a.PRP_Y, a.PRP_Z, 0.6, -0.6);
                //projection *= Matrix4<double>.GetPerspectiveProjectionMatrix(a.VRC_UMIN, a.VRC_UMAX, a.VRC_VMIN, a.VRC_VMAX, a.PRP_X, a.PRP_Y, a.PRP_Z, -0.6);
            }
            else
            {
                projection = Matrix4<double>.GetPerspectiveProjectionMatrix(a.VRC_UMIN, a.VRC_UMAX, a.VRC_VMIN, a.VRC_VMAX, a.PRP_X, a.PRP_Y, a.PRP_Z, -0.6);
                //projection *= Matrix4<double>.GetParallelProjectionMatrix(a.VRC_UMIN, a.VRC_UMAX, a.VRC_VMIN, a.VRC_VMAX, a.PRP_X, a.PRP_Y, a.PRP_Z, 0.6, -0.6);
            }
            foreach (var p in prims)
            {
                //Transfrom into canonical orthogonal view volume to perform clipping?? Tried it and didn't get correct results. But this doesn't work either so something else must be wrong...
                p.ProjectAndView(cameraTranslation);
                p.ProjectAndView(cameraRotation);
                p.ProjectAndView(projection);
            }
            List<Polygon3D> acceptedPolys = new List<Polygon3D>();
            //Clip polygons -- this doesn't work
            foreach (var p in prims)
            {
                bool accept = false;
                foreach (var v in p)
                {
                    if (v.X > 1 || v.X < -1)
                    {
                        accept = false;
                    }
                    else if (v.Y > 1 || v.Y < -1)
                    {
                        accept = false;
                    }
                    else
                    {
                        accept = true;
                    }
                }

                if (accept)
                    acceptedPolys.Add(p);
            }
            //This is the part that I think is wrong but i'm not sure how to correct it. The scaling seems to be fine for parallel but not for perspective and the translation
            //is definitely wrong but i'm not sure what it should be. I have these as separate statements instead of matrix multiplication to make it easier to debug
            foreach (var p in acceptedPolys)
            {
                if (a.IsParallelProjection)
                {
                    foreach (var v in p)
                    {
                        v.X += 1;
                        v.Y += 1;
                        v.X *= (a.XUpper - a.XLower)/2;
                        v.Y *= (a.YUpper - a.YLower)/2;
                        v.X += a.VRC_UMIN;
                        v.Y += a.VRC_VMIN;
                    }
                }
                else
                {
                    //p.ProjectAndView(projection);
                    foreach (var v in p)
                    {
                        //Perspective division
                        v.X /= -v.Z;
                        v.Y /= -v.Z;
                        v.X += 1;
                        v.Y += 1;
                        v.X *= (a.VP_XUpper - a.VP_XLower) / 2;
                        v.Y *= (a.VP_YUpper - a.VP_YLower) / 2;
                        v.X += a.VRC_UMIN;
                        v.Y += a.VRC_VMIN;

                    }
                }

            }
            PixelBuffer pb = new PixelBuffer(a.XLower, a.XUpper, a.YLower, a.YUpper, a.VP_XLower, a.VP_XUpper, a.VP_YLower, a.VP_YUpper, a.BackPlaneVRC, a.FrontPlaneVRC);
            foreach (var p in acceptedPolys)
            {
                p.MapToViewPort(PixelBuffer.GetVPMatrix(a.XLower, a.XUpper, a.YLower, a.YUpper, a.VP_XLower, a.VP_XUpper, a.VP_YLower, a.VP_YUpper));
                pb.FillPolygon(p);
            }
            ////Draw lines

            pb.DrawPolygon3D(acceptedPolys);
            Console.Write(pb.WriteToXPM());
        }
开发者ID:abramowitzK,项目名称:Software-Renderer,代码行数:101,代码来源:Driver.cs


注:本文中的PixelBuffer.WriteToXPM方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。