Ejemplo n.º 1
0
        // I/F
        public VertexSource <VertexPositionNormal, ushort> CreateVertexSource()
        {
            var   source     = new VertexSource <VertexPositionNormal, ushort>();
            var   quadrangle = new Quadrangle();
            float s          = Size * 0.5f;

            // REFERENCE: 立方体頂点計算アルゴリズムは XNA の Primitive3D サンプル コードより。

            Vector3[] normals =
            {
                new Vector3(0,   0,  1),
                new Vector3(0,   0, -1),
                new Vector3(1,   0,  0),
                new Vector3(-1,  0,  0),
                new Vector3(0,   1,  0),
                new Vector3(0,  -1,  0),
            };

            foreach (var normal in normals)
            {
                var side1 = new Vector3(normal.Y, normal.Z, normal.X);
                var side2 = Vector3.Cross(normal, side1);

                quadrangle.Position0 = (normal - side1 - side2) * s;
                quadrangle.Position1 = (normal - side1 + side2) * s;
                quadrangle.Position2 = (normal + side1 + side2) * s;
                quadrangle.Position3 = (normal + side1 - side2) * s;
                quadrangle.Normal    = normal;
                quadrangle.Make(source);
            }

            return(source);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// VertexSource へ頂点データを設定します。
        /// </summary>
        /// <param name="source">頂点データが設定される VertexSource。</param>
        public void Make(VertexSource <VertexPositionNormalColor, ushort> source)
        {
            MakeIndices(source);

            source.AddVertex(new VertexPositionNormalColor(Position0, Normal, Color));
            source.AddVertex(new VertexPositionNormalColor(Position1, Normal, Color));
            source.AddVertex(new VertexPositionNormalColor(Position2, Normal, Color));
            source.AddVertex(new VertexPositionNormalColor(Position3, Normal, Color));
        }
Ejemplo n.º 3
0
 void MakeIndices <TVertex>(VertexSource <TVertex, ushort> source)
     where TVertex : struct
 {
     source.AddIndex((ushort)(source.CurrentVertex + 0));
     source.AddIndex((ushort)(source.CurrentVertex + 1));
     source.AddIndex((ushort)(source.CurrentVertex + 2));
     source.AddIndex((ushort)(source.CurrentVertex + 0));
     source.AddIndex((ushort)(source.CurrentVertex + 2));
     source.AddIndex((ushort)(source.CurrentVertex + 3));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// VertexSource へ頂点データを設定します。
        /// </summary>
        /// <param name="source">頂点データが設定される VertexSource。</param>
        public void Make(VertexSource <VertexPositionNormal, ushort> source)
        {
            var quad = new Quadrangle();

            for (int i = 0; i < normals.Length; i++)
            {
                ResolvePositionNormal(ref quad, ref normals[i]);
                quad.Make(source);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// VertexSource へ頂点データを設定します。
        /// </summary>
        /// <param name="source">頂点データが設定される VertexSource。</param>
        public void Make(VertexSource <VertexPositionNormalColor, ushort> source)
        {
            source.AddIndex((ushort)(source.CurrentVertex + 0));
            source.AddIndex((ushort)(source.CurrentVertex + 1));
            source.AddIndex((ushort)(source.CurrentVertex + 2));
            source.AddIndex((ushort)(source.CurrentVertex + 0));
            source.AddIndex((ushort)(source.CurrentVertex + 2));
            source.AddIndex((ushort)(source.CurrentVertex + 3));

            source.AddVertex(new VertexPositionNormalColor(Position0, Normal, Color));
            source.AddVertex(new VertexPositionNormalColor(Position1, Normal, Color));
            source.AddVertex(new VertexPositionNormalColor(Position2, Normal, Color));
            source.AddVertex(new VertexPositionNormalColor(Position3, Normal, Color));
        }
        // I/F
        public VertexSource <VertexPositionNormalColor, ushort> CreateVertexSource()
        {
            var   source = new VertexSource <VertexPositionNormalColor, ushort>();
            var   maker  = new ColoredQuadrangle();
            float s      = Size * 0.5f;

            // REFERENCE: 立方体頂点計算アルゴリズムは XNA の Primitive3D サンプル コードより。

            Vector3[] normals =
            {
                new Vector3(0,   0,  1),
                new Vector3(0,   0, -1),
                new Vector3(1,   0,  0),
                new Vector3(-1,  0,  0),
                new Vector3(0,   1,  0),
                new Vector3(0,  -1,  0),
            };

            Color[] colors =
            {
                NorthSurfaceColor,
                SouthSurfaceColor,
                WestSurfaceColor,
                EastSurfaceColor,
                TopSurfaceColor,
                BottomSurfaceColor
            };

            for (int i = 0; i < normals.Length; i++)
            {
                var normal = normals[i];
                var side1  = new Vector3(normal.Y, normal.Z, normal.X);
                var side2  = Vector3.Cross(normal, side1);

                maker.Position0 = (normal - side1 - side2) * s;
                maker.Position1 = (normal - side1 + side2) * s;
                maker.Position2 = (normal + side1 + side2) * s;
                maker.Position3 = (normal + side1 - side2) * s;
                maker.Normal    = normal;
                maker.Color     = colors[i];
                maker.Make(source);
            }

            return(source);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 指定された VertexSource から GeometricPrimitive を生成します。
        /// </summary>
        /// <typeparam name="TVertex">頂点構造体の型。</typeparam>
        /// <typeparam name="TIndex">インデックスの型。</typeparam>
        /// <param name="graphicsDevice">GraphicsDevice。</param>
        /// <param name="source">VertexSource。</param>
        /// <returns>生成された GeometricPrimitive。</returns>
        public static GeometricPrimitive Create <TVertex, TIndex>(GraphicsDevice graphicsDevice, VertexSource <TVertex, TIndex> source)
            where TVertex : struct
            where TIndex : struct
        {
            var vertices = source.Vertices.ToArray();
            var indices  = source.Indices.ToArray();

            return(Create(graphicsDevice, vertices, indices));
        }