Esempio n. 1
0
        public override void draw()
        {
            texture ??= new Texture(bitmap);
            preDraw();

            float   aspectRatio = (float)bitmap.Width / bitmap.Height;
            Vector3 size        = new Vector3(height * aspectRatio, height, 1);

            vertexList = new VertexList()
            {
                vertices = new List <Vertex> {
                    new Vertex {
                        point    = new Vector3(-0.5f, -0.5f, pos.Z),
                        color    = color,
                        texCoord = new Vector2(0, 1)
                    },
                    new Vertex {
                        point    = new Vector3(-0.5f, 0.5f, pos.Z),
                        color    = color,
                        texCoord = new Vector2(0, 0)
                    },
                    new Vertex {
                        point    = new Vector3(0.5f, -0.5f, pos.Z),
                        color    = color,
                        texCoord = new Vector2(1, 1)
                    },
                    new Vertex {
                        point    = new Vector3(0.5f, 0.5f, pos.Z),
                        color    = color,
                        texCoord = new Vector2(1, 0)
                    }
                },
                indices = new List <uint> {
                    0, 1, 2,
                    2, 3, 1
                }
            };

            transformationMatrix = Matrix4.Identity
                                   * Matrix4.CreateScale(size.ToOpenTKVector3());

            switch (anchor)
            {
            case Anchor.Left:
                transformationMatrix *= Matrix4.CreateTranslation(size.X / 2, 0, 0);
                break;

            case Anchor.Right:
                transformationMatrix *= Matrix4.CreateTranslation(-size.X / 2, 0, 0);
                break;
            }

            transformationMatrix *= Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(rotationDegrees))
                                    * Matrix4.CreateTranslation(pos.ToOpenTKVector3());

            draw(PrimitiveType.Triangles);
        }