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


C# Vector3.Transform方法代码示例

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


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

示例1: DrawLine

        public void DrawLine(Vector3 v1, Vector3 v2, float width, Color color, float[,] matrix)
        {
            v1 = v1.Transform(matrix);
            v2 = v2.Transform(matrix);

            float angle = (v1.ToVector2() - v2.ToVector2()).Angle() + 90;
            Vector3 offset = new Vector2(width / 2, angle).ToCartesian().ToVector3();
            DrawTriangle(v1 + offset, v1 - offset, v2 + offset, color, Color.Transparent, Matrix.GetIdentity());
            DrawTriangle(v1 - offset, v2 - offset, v2 + offset, color, Color.Transparent, Matrix.GetIdentity());
        }
开发者ID:rubna,项目名称:3dEngine,代码行数:10,代码来源:DrawWrapper.cs

示例2: DrawPoint

        //, Color color2)
        public void DrawPoint(Vector3 v, Color color, float[,] matrix)
        {
            v = v.Transform(matrix);

            if (v.X > 0 && v.Y > 0 && v.X < ScreenSize.X && v.Y < ScreenSize.Y)
            {
                if (v.Z < zBuffer[(int)v.X, (int)v.Y] && v.Z > ZNear)
                {
                    screen[(int)v.X, (int)v.Y] = color;
                    zBuffer[(int)v.X, (int)v.Y] = v.Z;
                }
            }
        }
开发者ID:rubna,项目名称:3dEngine,代码行数:14,代码来源:DrawWrapper.cs

示例3: DrawTriangle

        public void DrawTriangle(Vector3 v1, Vector3 v2, Vector3 v3, Color frontFaceColor, Color backFaceColor, float[,] matrix)
        {
            v1 = v1.Transform(matrix);
            v2 = v2.Transform(matrix);
            v3 = v3.Transform(matrix);
            Vector3 normal = Vector3.Cross(v1 - v2, v1 - v3);
            normal.Normalize();

            //set color or return for culling
            Color color = frontFaceColor;
            if (normal.Z > 0)
                color = backFaceColor;
            if (color == Color.Transparent)
                return;
            if (EnableShading)
            {
                float shading = 0.5f + 0.5f * Math.Abs(normal.Z);
                color.R = (byte)(color.R * shading);
                color.G = (byte)(color.G * shading);
                color.B = (byte)(color.B * shading);
            }

            Vector2 min = new Vector2();
            Vector2 max = new Vector2();
            min.X = Math.Min(v1.X, Math.Min(v2.X, v3.X));
            min.Y = Math.Min(v1.Y, Math.Min(v2.Y, v3.Y));
            max.X = Math.Max(v1.X, Math.Max(v2.X, v3.X));
            max.Y = Math.Max(v1.Y, Math.Max(v2.Y, v3.Y));

            min = min.ClampVector2(Vector2.Zero, ScreenSize.ToVector2());
            max = max.ClampVector2(Vector2.Zero, ScreenSize.ToVector2());

            Vector3[] verts = new Vector3[3] { v1, v2, v3 };

            for (int yp = (int)min.Y; yp < (int)max.Y; yp++)
            {
                List<Vector3> intersections = new List<Vector3>();

                //voor alle lijnen van de triangle, vind alle intersecties (als het goed is altijd 2)
                for (int l = 0; l < 3; l++)
                {
                    Vector3 vert1, vert2;
                    vert1 = verts[l];
                    vert2 = verts[(l + 1) % 3];

                    float ymin, ymax;
                    ymin = Math.Min(vert1.Y, vert2.Y);
                    ymax = Math.Max(vert1.Y, vert2.Y);
                    if (yp > ymin && yp < ymax)//check of yp tussen de y-en van de vertices ligt, zo ja, intersectie
                    {
                        float xSlope = (vert2.X - vert1.X) / (vert2.Y - vert1.Y);
                        float xIntersect = vert1.X + xSlope * (yp - vert1.Y);

                        float zSlope = (vert2.Z - vert1.Z) / (vert2.Y - vert1.Y);
                        float zIntersect = vert1.Z + zSlope * (yp - vert1.Y);
                        intersections.Add(new Vector3((int)xIntersect, yp, zIntersect));
                    }
                }

                //vul scanline
                if (intersections.Count > 1)
                {
                    Vector3 pStart, pEnd;
                    if (intersections[0].X < intersections[1].X) { pStart = intersections[0]; pEnd = intersections[1]; }
                    else
                    { pStart = intersections[1]; pEnd = intersections[0]; }

                    //vul de rij met pixels
                    for (int xp = MathHelper.Clamp((int)pStart.X, 0, ScreenSize.X); xp < MathHelper.Clamp(pEnd.X, 0, ScreenSize.X); xp++)
                    {
                        float zSlope = (pEnd.Z - pStart.Z) / (pEnd.X - pStart.X);
                        float zCurrent = pStart.Z + zSlope * (xp - pStart.X);

                        //DrawPoint(new Vector3(xp, yp, zCurrent), color, Matrix.GetIdentity());
                        if (zCurrent < zBuffer[xp, yp] && zCurrent > ZNear)
                        {
                            screen[xp, yp] = color;
                            zBuffer[xp, yp] = zCurrent;
                        }
                    }
                }
            }
        }
开发者ID:rubna,项目名称:3dEngine,代码行数:83,代码来源:DrawWrapper.cs


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