Exemplo n.º 1
0
        /// <summary>
        /// 指定の法線の面の頂点データを作成します。
        /// </summary>
        /// <param name="source">対応する面の VertexSource。</param>
        /// <param name="normal">面の法線。</param>
        void InitializeSurface(SurfaceVertexSource source, Vector3 normal)
        {
            var   quadrangle = new Quadrangle();
            float s          = Size * 0.5f;

            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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 面の頂点データを InterBlockMeshPart の頂点データへ設定します。
        /// </summary>
        /// <param name="meshPartVS">
        /// InterBlockMeshPart の頂点データを保持する VertexSource。
        /// </param>
        /// <param name="surfaceVS">
        /// 面の頂点データを提供する VertexSource。
        /// </param>
        /// <param name="transform">
        /// 頂点の設定前に適用する変換行列。
        /// </param>
        static void AddSurfaceVertices(MeshPartVertexSource meshPartVS, SurfaceVertexSource surfaceVS, ref Matrix transform)
        {
            var startIndex   = meshPartVS.Vertices.Count;
            var vertexSource = surfaceVS;

            foreach (var index in vertexSource.Indices)
            {
                meshPartVS.Indices.Add((ushort)(startIndex + index));
            }
            for (int i = 0; i < vertexSource.Vertices.Count; i++)
            {
                var     cubeVertex = vertexSource.Vertices[i];
                Vector3 transformedVertexPosition;
                Vector3.Transform(ref cubeVertex.Position, ref transform, out transformedVertexPosition);
                meshPartVS.Vertices.Add(new VertexPositionNormal(transformedVertexPosition, cubeVertex.Normal));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// インスタンスを生成します。
        /// </summary>
        /// <param name="size">辺のサイズ。</param>
        public CubeSurfaceVertexSource(float size)
        {
            Size = size;

            Surfaces = new SurfaceVertexSource[6];

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

            for (int i = 0; i < 6; i++)
            {
                Surfaces[i] = new SurfaceVertexSource();
                InitializeSurface(Surfaces[i], normals[i]);
            }
        }