コード例 #1
0
        public override void MapVertices()
        {
            vertices = new List <CustomVertex>();

            for (int i = 0; i < triangles.Length - 2; i += 3)
            {
                CustomVertex v  = new CustomVertex();
                CustomVertex v1 = new CustomVertex();
                CustomVertex v2 = new CustomVertex();

                var index  = triangles[i];
                var index1 = triangles[i + 1];
                var index2 = triangles[i + 2];

                v.Position  = points[points.Length - 1 - index];
                v1.Position = points[points.Length - 1 - index1];
                v2.Position = points[points.Length - 1 - index2];

                Vector3 normal = getVertexNormal(new Vector3(v.Position.X, v.Position.Y, v.Position.Z),
                                                 new Vector3(v1.Position.X, v1.Position.Y, v1.Position.Z),
                                                 new Vector3(v2.Position.X, v2.Position.Y, v2.Position.Z));

                v.Normal  = normal;
                v1.Normal = normal;
                v2.Normal = normal;

                vertices.Add(v);
                vertices.Add(v1);
                vertices.Add(v2);
            }
        }
コード例 #2
0
        public virtual void MapVertices()
        {
            vertices = new List <CustomVertex>();

            for (int i = 0; i < triangles.Length; i += 3)
            {
                CustomVertex v  = new CustomVertex();
                CustomVertex v1 = new CustomVertex();
                CustomVertex v2 = new CustomVertex();

                v.Position  = origin + points[triangles[i]];
                v1.Position = origin + points[triangles[i + 1]];
                v2.Position = origin + points[triangles[i + 2]];

                Vector3 normal = Vector3.Zero;

                normal = getVertexNormal(new Vector3(v.Position.X, v.Position.Y, v.Position.Z),
                                         new Vector3(v1.Position.X, v1.Position.Y, v1.Position.Z),
                                         new Vector3(v2.Position.X, v2.Position.Y, v2.Position.Z));

                v.Normal  = normal;
                v1.Normal = normal;
                v2.Normal = normal;

                vertices.Add(v);
                vertices.Add(v1);
                vertices.Add(v2);
            }
        }
コード例 #3
0
        public override void MapVertices()
        {
            /*
             *
             * I could say I will refactor this later, but that is a big fat lie
             *
             */

            var points = MapPoints();

            vertices = new List <CustomVertex>();

            for (int y = 0; y < points.Count; y++)
            {
                for (int x = 0; x < points[y].Count; x++)
                {
                    CustomVertex v  = new CustomVertex();
                    CustomVertex v1 = new CustomVertex();
                    CustomVertex v2 = new CustomVertex();

                    v.Position  = points[y][x];
                    v1.Position = points[y][(x + 1) % points[y].Count];
                    v2.Position = new Vector4(0, points[y][x].Y, 0, 1);

                    Vector3 normal = getVertexNormal(new Vector3(v2.Position.X, v2.Position.Y, v2.Position.Z),
                                                     new Vector3(v1.Position.X, v1.Position.Y, v1.Position.Z),
                                                     new Vector3(v.Position.X, v.Position.Y, v.Position.Z));

                    if (y == 1)
                    {
                        normal *= -1;
                    }

                    v.Normal  = normal;
                    v1.Normal = normal;
                    v2.Normal = normal;
                    if (y == 0)
                    {
                        vertices.Add(v2);
                        vertices.Add(v1);
                        vertices.Add(v);
                    }
                    else
                    {
                        vertices.Add(v);
                        vertices.Add(v1);
                        vertices.Add(v2);
                    }

                    if (y < 1)
                    {
                        CustomVertex v3 = new CustomVertex();
                        CustomVertex v4 = new CustomVertex();
                        CustomVertex v5 = new CustomVertex();

                        v3.Position = points[y][x];
                        v4.Position = points[y + 1][x];
                        v5.Position = points[y][(x + 1) % points[y].Count];

                        normal = getVertexNormal(new Vector3(v5.Position.X, v5.Position.Y, v5.Position.Z),
                                                 new Vector3(v4.Position.X, v4.Position.Y, v4.Position.Z),
                                                 new Vector3(v3.Position.X, v3.Position.Y, v3.Position.Z));
                        v3.Normal = normal;
                        v4.Normal = normal;
                        v5.Normal = normal;

                        vertices.Add(v5);
                        vertices.Add(v4);
                        vertices.Add(v3);
                    }
                    if (y >= 1)
                    {
                        CustomVertex v3 = new CustomVertex();
                        CustomVertex v4 = new CustomVertex();
                        CustomVertex v5 = new CustomVertex();

                        v3.Position = origin + points[y][(x + 1) % points[y].Count];
                        v4.Position = origin + points[y - 1][(x + 1) % points[y].Count];
                        v5.Position = origin + points[y][x];

                        normal = getVertexNormal(new Vector3(v5.Position.X, v5.Position.Y, v5.Position.Z),
                                                 new Vector3(v4.Position.X, v4.Position.Y, v4.Position.Z),
                                                 new Vector3(v3.Position.X, v3.Position.Y, v3.Position.Z));
                        v3.Normal = normal;
                        v4.Normal = normal;
                        v5.Normal = normal;

                        vertices.Add(v5);
                        vertices.Add(v4);
                        vertices.Add(v3);
                    }
                }
            }
        }
コード例 #4
0
        public override void MapVertices()
        {
            var points = MapPoints();

            vertices = new List <CustomVertex>();

            for (int x = 0; x < points.Count - 1; x++)
            {
                for (int y = 0; y < points[x].Count - 1; y++)
                {
                    CustomVertex v  = new CustomVertex();
                    CustomVertex v1 = new CustomVertex();
                    CustomVertex v2 = new CustomVertex();

                    CustomVertex v3 = new CustomVertex();
                    CustomVertex v4 = new CustomVertex();
                    CustomVertex v5 = new CustomVertex();

                    v.Position  = origin + points[x][y];
                    v1.Position = origin + points[x + 1][y];
                    v2.Position = origin + points[x][y + 1];
                    v3.Position = origin + points[x + 1][y + 1];

                    normal = getVertexNormal(new Vector3(v2.Position.X, v2.Position.Y, v2.Position.Z),
                                             new Vector3(v1.Position.X, v1.Position.Y, v1.Position.Z),
                                             new Vector3(v.Position.X, v.Position.Y, v.Position.Z));
                    originalNormal = Vector3.Transform(normal, Matrix.CreateRotationX(MathHelper.ToRadians(90)));

                    v.Normal  = normal;
                    v1.Normal = normal;
                    v2.Normal = normal;

                    vertices.Add(v2);
                    vertices.Add(v1);
                    vertices.Add(v);

                    v4 = v1;
                    v5 = v2;

                    v3.Normal = getVertexNormal(new Vector3(v4.Position.X, v4.Position.Y, v4.Position.Z),
                                                new Vector3(v5.Position.X, v5.Position.Y, v5.Position.Z),
                                                new Vector3(v3.Position.X, v3.Position.Y, v3.Position.Z));
                    v4.Normal = v3.Normal;
                    v5.Normal = v3.Normal;

                    vertices.Add(v3);
                    vertices.Add(v4);
                    vertices.Add(v5);


                    //  Backface
                    float offset = 0.001f;
                    v.Position.Y  += offset;
                    v1.Position.Y += offset;
                    v2.Position.Y += offset;
                    v3.Position.Y += offset;
                    v4.Position.Y += offset;
                    v5.Position.Y += offset;

                    v.Normal = getVertexNormal(new Vector3(v.Position.X, v.Position.Y, v.Position.Z),
                                               new Vector3(v1.Position.X, v1.Position.Y, v1.Position.Z),
                                               new Vector3(v2.Position.X, v2.Position.Y, v2.Position.Z));
                    v1.Normal = v.Normal;
                    v2.Normal = v.Normal;

                    v3.Normal = getVertexNormal(v3.Position, v5.Position, v4.Position);
                    v4.Normal = v3.Normal;
                    v5.Normal = v3.Normal;

                    vertices.Add(v);
                    vertices.Add(v1);
                    vertices.Add(v2);

                    vertices.Add(v5);
                    vertices.Add(v4);
                    vertices.Add(v3);
                }
            }
        }