Beispiel #1
0
        public virtual void Draw()
        {
            if (_hidden || this.a == 0.0f)
            {
                return;
            }
            Picture p = null;

            if (tex == null)
            {
                if (!this.resource.TryGetValue(this.filename, out p))
                {
                    return;
                }
                else
                {
                    this.width  = p.width;
                    this.height = p.height;
                    tex         = p.texture;
                }
            }
            // 頂点の色;テクスチャを貼るポリゴンは白色にしておく
            int color = new Color4(this.a, 1.0f, 1.0f, 1.0f).ToArgb();
            int w     = 1;
            var cv    = new TransformedColoredTexturedVertex[4] {
                // 左上の頂点
                new TransformedColoredTexturedVertex()
                {
                    Position           = new Vector4(x, y, z, w),
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = rec.X / width, Y = rec.Y / height
                    },
                },
                // 右上の頂点
                new TransformedColoredTexturedVertex()
                {
                    Position           = new Vector4(x + rec.Width, y, z, w),
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = (rec.X + rec.Width) / width, Y = rec.Y / height
                    },
                },
                // 左下の頂点
                new TransformedColoredTexturedVertex()
                {
                    Position           = new Vector4(x, y + rec.Height, z, w),
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = rec.X / width, Y = (rec.Y + rec.Height) / height
                    },
                },
                // 右下の頂点
                new TransformedColoredTexturedVertex()
                {
                    Position           = new Vector4(x + rec.Width, y + rec.Height, z, w),
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = (rec.X + rec.Width) / width, Y = (rec.Y + rec.Height) / height
                    },
                }
            };
            Matrix m = Matrix.Transformation2D((!this.special ? new Vector2(this.x + width / 2f, this.y + height / 2f) : new Vector2(this.x + width / 20f, this.y + height / 20f)), 0f, scale, new Vector2(this.x + width / 2f, this.y + height / 2f), this.r, new Vector2(0, 0));

            for (int i = 0; i < cv.Length; i++)
            {
                cv[i].Position = Vector4.Transform(cv[i].Position, m);
            }
            Matrix tm = _sprite.Transform;

            //_sprite.Transform = m;

            if (drawwithsprite)
            {
                _sprite.Draw(tex, new Vector3(0, 0, 0), new Vector3(this.x, this.y, this.z), new Color4(this.a, 1.0f, 1.0f, 1.0f));
            }
            else
            {
                if (tex != null)
                {
                    this._device.SetTexture(0, tex);
                    this._device.VertexFormat = TransformedColoredTexturedVertex.Format;
                    this._device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv);
                }
            }
            //_sprite.Transform = tm;
        }
Beispiel #2
0
        private void DrawBlackCube()
        {
            this.rotation += (float)Math.PI / 360;
            Matrix rotate    = Matrix.RotationYawPitchRoll((float)Math.PI / 4, (float)Math.PI / 4 + rotation, (float)Math.PI / 4 + rotation);
            Matrix translate = Matrix.Identity;

            Matrix.Translation(350, 250, -300, out translate);
            rotate = Matrix.Multiply(rotate, translate);
            Vector4[] transformed = new Vector4[8];
            for (int i = 0; i < 8; i++)
            {
                transformed[i] = Vector4.Transform(box[i], rotate);
            }
            int max = 0;

            for (int i = 1; i < 8; i++)
            {
                if (transformed[max].Z <= transformed[i].Z)
                {
                    max = i;
                }
            }
            for (int i = 0; i < 8; i++)
            {
                transformed[i].Z = 0.5f;
            }

            int color = new Color4(1.0f, 1, 1, 1).ToArgb();

            TransformedColoredTexturedVertex[] cv0 = new TransformedColoredTexturedVertex[4]
            {
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[6],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[7],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[3],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[5],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
            };
            TransformedColoredTexturedVertex[] cv1 = new TransformedColoredTexturedVertex[4]
            {
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[7],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[4],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[5],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[1],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
            };
            TransformedColoredTexturedVertex[] cv2 = new TransformedColoredTexturedVertex[4]
            {
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[4],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[2],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[1],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[0],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
            };
            TransformedColoredTexturedVertex[] cv3 = new TransformedColoredTexturedVertex[4]
            {
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[2],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[6],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[0],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[3],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
            };
            TransformedColoredTexturedVertex[] cv4 = new TransformedColoredTexturedVertex[4]
            {
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[1],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[0],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[5],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[3],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
            };
            TransformedColoredTexturedVertex[] cv5 = new TransformedColoredTexturedVertex[4]
            {
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[7],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[6],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[4],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[2],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = 0, Y = 0
                    },
                },
            };



            this.device.SetTexture(0, black.Texture);
            switch (max)
            {
            case 0:
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv2);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv3);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv4);
                break;

            case 1:
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv1);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv2);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv4);
                break;

            case 2:
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv2);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv3);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv5);
                break;

            case 3:
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv0);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv3);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv4);
                break;

            case 4:
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv1);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv2);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv5);
                break;

            case 5:
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv0);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv1);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv4);
                break;

            case 6:
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv0);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv3);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv5);
                break;

            case 7:
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv0);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv1);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv5);
                break;
            }
        }
Beispiel #3
0
        private void DrawMovieCube()
        {
            float asp = (float)this.Height / this.Width;

            this.rotation += (float)Math.PI / 360;
            Matrix rotate    = Matrix.RotationYawPitchRoll((float)Math.PI / 4, (float)Math.PI / 4 + rotation, (float)Math.PI / 4 + rotation);
            Matrix translate = Matrix.Identity;

            Matrix.Translation(350, 250, -300, out translate);
            rotate = Matrix.Multiply(rotate, translate);
            Vector4[] transformed = new Vector4[8];
            for (int i = 0; i < 8; i++)
            {
                transformed[i] = Vector4.Transform(box[i], rotate);
            }
            int max = 0;

            for (int i = 1; i < 8; i++)
            {
                if (transformed[max].Z <= transformed[i].Z)
                {
                    max = i;
                }
            }
            for (int i = 0; i < 8; i++)
            {
                transformed[i].Z = 0.5f;
            }
            int   top = movie.TrimmingData.Top, left = movie.TrimmingData.Left, right = movie.TrimmingData.Right, bottom = movie.TrimmingData.Bottom;
            float maxu = movie.MaxU, maxv = movie.MaxV;
            float alpha = movie.Alpha;
            int   color = new Color4(1.0f, alpha, alpha, alpha).ToArgb();

            TransformedColoredTexturedVertex[] cv0 = new TransformedColoredTexturedVertex[4]
            {
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[6],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[0], Y = (float)(top > 0?top:0) / this.Height * maxv / asp
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[7],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[0] + this.h, Y = (float)(top > 0?top:0) / this.Height * maxv / asp
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[3],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[0], Y = (float)(top > 0?top:0) / this.Height * maxv + this.h / asp
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[5],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[0] + this.h, Y = (float)(top > 0?top:0) / this.Height * maxv + this.h / asp
                    },
                },
            };
            TransformedColoredTexturedVertex[] cv1 = new TransformedColoredTexturedVertex[4]
            {
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[7],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[1], Y = (float)(top > 0?top:0) / this.Height * maxv / asp
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[4],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[1] + this.h, Y = (float)(top > 0?top:0) / this.Height * maxv / asp
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[5],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[1], Y = (float)(top > 0?top:0) / this.Height * maxv + this.h / asp
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[1],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[1] + this.h, Y = (float)(top > 0?top:0) / this.Height * maxv + this.h / asp
                    },
                },
            };
            TransformedColoredTexturedVertex[] cv2 = new TransformedColoredTexturedVertex[4]
            {
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[4],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[2], Y = (float)(top > 0?top:0) / this.Height * maxv / asp
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[2],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[2] + this.h, Y = (float)(top > 0?top:0) / this.Height * maxv / asp
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[1],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[2], Y = (float)(top > 0?top:0) / this.Height * maxv + this.h / asp
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[0],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[2] + this.h, Y = (float)(top > 0?top:0) / this.Height * maxv + this.h / asp
                    },
                },
            };
            TransformedColoredTexturedVertex[] cv3 = new TransformedColoredTexturedVertex[4]
            {
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[2],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[3], Y = (float)(top > 0?top:0) / this.Height * maxv / asp
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[6],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[3] + this.h, Y = (float)(top > 0?top:0) / this.Height * maxv / asp
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[0],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[3], Y = (float)(top > 0?top:0) / this.Height * maxv + this.h / asp
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[3],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[3] + this.h, Y = (float)(top > 0?top:0) / this.Height * maxv + this.h / asp
                    },
                },
            };
            TransformedColoredTexturedVertex[] cv4 = new TransformedColoredTexturedVertex[4]
            {
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[1],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[4], Y = (float)(top > 0?top:0) / this.Height * maxv / asp
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[0],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[4] + this.h, Y = (float)(top > 0?top:0) / this.Height * maxv / asp
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[5],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[4], Y = (float)(top > 0?top:0) / this.Height * maxv + this.h / asp
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[3],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[4] + this.h, Y = (float)(top > 0?top:0) / this.Height * maxv + this.h / asp
                    },
                },
            };
            TransformedColoredTexturedVertex[] cv5 = new TransformedColoredTexturedVertex[4]
            {
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[7],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[5], Y = (float)(top > 0?top:0) / this.Height * maxv / asp
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[6],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[5] + this.h, Y = (float)(top > 0?top:0) / this.Height * maxv / asp
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[4],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[5], Y = (float)(top > 0?top:0) / this.Height * maxv + this.h / asp
                    },
                },
                new TransformedColoredTexturedVertex()
                {
                    Position           = transformed[2],
                    Color              = color,
                    TextureCoordinates = new Vector2()
                    {
                        X = startx[5] + this.h, Y = (float)(top > 0?top:0) / this.Height * maxv + this.h / asp
                    },
                },
            };



            this.device.SetTexture(0, movie.Texture);
            switch (max)
            {
            case 0:
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv2);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv3);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv4);
                break;

            case 1:
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv1);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv2);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv4);
                break;

            case 2:
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv2);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv3);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv5);
                break;

            case 3:
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv0);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv3);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv4);
                break;

            case 4:
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv1);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv2);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv5);
                break;

            case 5:
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv0);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv1);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv4);
                break;

            case 6:
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv0);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv3);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv5);
                break;

            case 7:
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv0);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv1);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, cv5);
                break;
            }
        }
Beispiel #4
0
        public void Draw(PictureObject po)
        {
            float zure  = 0 * po.Scale.X;
            float press = 0.8f;
            float alpha = 0.4f;
            int   w     = 1;
            float z     = 0.5f;

            Vector4[] positions = new Vector4[4];
            positions[0] = new Vector4(po.Position.X - po.Width / 2, po.Position.Y - po.Height / 2, z, w);
            positions[1] = new Vector4(po.Position.X + po.rec.Width - po.Width / 2, po.Position.Y - po.Height / 2, z, w);
            positions[2] = new Vector4(po.Position.X - po.Width / 2, po.Position.Y + po.rec.Height - po.Height / 2, z, w);
            positions[3] = new Vector4(po.Position.X + po.rec.Width - po.Width / 2, po.Position.Y + po.rec.Height - po.Height / 2, z, w);
            Matrix m = Matrix.Transformation2D(new Vector2(po.Position.X, po.Position.Y), 0f, po.Scale, new Vector2(po.Position.X, po.Position.Y), po.Rotation, new Vector2(0, 0));

            for (int i = 0; i < positions.Length; i++)
            {
                positions[i] = Vector4.Transform(positions[i], m);
            }
            var cv = new TransformedColoredTexturedVertex[6] {
                // 左上の頂点
                new TransformedColoredTexturedVertex()
                {
                    Position           = new Vector4(positions[0].X - zure, (positions[2].Y - positions[0].Y) * press + positions[2].Y, z, w),
                    Color              = new Color4(0, 1, 1, 1).ToArgb(),
                    TextureCoordinates = new Vector2()
                    {
                        X = po.rec.X / po.Width, Y = po.rec.Y / po.Height
                    },
                },
                // 右上の頂点
                new TransformedColoredTexturedVertex()
                {
                    Position           = new Vector4(positions[1].X + zure, (positions[2].Y - positions[0].Y) * press + positions[2].Y, z, w),
                    Color              = new Color4(0, 1, 1, 1).ToArgb(),
                    TextureCoordinates = new Vector2()
                    {
                        X = (po.rec.X + po.rec.Width) / po.Width, Y = po.rec.Y / po.Height
                    },
                },
                // 左真ん中の頂点
                new TransformedColoredTexturedVertex()
                {
                    Position           = new Vector4(positions[0].X - zure / 2, (positions[2].Y - positions[0].Y) * press / 2 + positions[2].Y, z, w),
                    Color              = new Color4(0, 1, 1, 1).ToArgb(),
                    TextureCoordinates = new Vector2()
                    {
                        X = po.rec.X / po.Width, Y = (po.rec.Y + po.rec.Height) / po.Height / 2
                    },
                },
                // 右真ん中の頂点
                new TransformedColoredTexturedVertex()
                {
                    Position           = new Vector4(positions[1].X + zure / 2, (positions[2].Y - positions[0].Y) * press / 2 + positions[2].Y, z, w),
                    Color              = new Color4(0, 1, 1, 1).ToArgb(),
                    TextureCoordinates = new Vector2()
                    {
                        X = (po.rec.X + po.rec.Width) / po.Width, Y = (po.rec.Y + po.rec.Height) / po.Height / 2
                    },
                },
                // 左下の頂点
                new TransformedColoredTexturedVertex()
                {
                    Position           = new Vector4(positions[2].X, positions[2].Y, z, w),
                    Color              = new Color4(alpha, 1, 1, 1).ToArgb(),
                    TextureCoordinates = new Vector2()
                    {
                        X = po.rec.X / po.Width, Y = (po.rec.Y + po.rec.Height) / po.Height
                    },
                },
                // 右下の頂点
                new TransformedColoredTexturedVertex()
                {
                    Position           = new Vector4(positions[3].X, positions[3].Y, z, w),
                    Color              = new Color4(alpha, 1, 1, 1).ToArgb(),
                    TextureCoordinates = new Vector2()
                    {
                        X = (po.rec.X + po.rec.Width) / po.Width, Y = (po.rec.Y + po.rec.Height) / po.Height
                    },
                }
            };
            Texture t = po.Texture;

            if (t != null)
            {
                this.device.SetTexture(0, t);
                this.device.VertexFormat = TransformedColoredTexturedVertex.Format;
                this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 4, cv);
            }
        }