4
« on: September 16, 2018, 11:10:19 pm »
can anybody tell me how I create a custom drawable shape?
SetPoint does not exists and the GetPoint and GetPointCount are not implemented in base
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SFML.Graphics;
using SFML.System;
namespace SFMLTest.Library.GraphicsHelpers
{
public class RectShape : Shape, Drawable
{
public Vector2f Offset { get; set; } = new Vector2f(0, 0);
public RectShape(float x, float y, float w, float z) : base()
{
//This method does not exist?
SetPoint(0, x);
SetPoint(1, y);
SetPoint(2, x + w);
SetPoint(3, y + h);
}
//WTF do i do in these methods? can't call base because its abstract
public override uint GetPointCount()
{
}
public override Vector2f GetPoint(uint index)
{
}
}
}
ok so I came up with
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SFML.Graphics;
using SFML.System;
namespace SFMLTest.GraphicsHelpers
{
public class RectShape : Drawable
{
protected Vertex[] vertices;
protected Transform transform;
public Vector2f Pos { get; set; } = new Vector2f(0,0);
public Vector2f Size { get; set; } = new Vector2f(0,0);
public Vector2f Scale { get; set; } = new Vector2f(1,1);
public Vector2f Origin { get; set; } = new Vector2f(0,0);
public float Angle { get; set; } = 0.0f;
public Color Color { get; set; } = Color.White;
public RectShape() : base()
{
vertices = new Vertex[4];
}
void Drawable.Draw(RenderTarget target, RenderStates states)
{
float x1 = Pos.X;
float y1 = Pos.Y;
float x2 = Pos.X + Size.X;
float y2 = Pos.X + Size.Y;
transform.Scale (Scale, Origin);
transform.Rotate(Angle, Origin);
vertices[0].Position = transform.TransformPoint(x1, y1);
vertices[1].Position = transform.TransformPoint(x1, y2);
vertices[2].Position = transform.TransformPoint(x2, y2);
vertices[3].Position = transform.TransformPoint(x2, y1);
vertices[0].Color = Color;
vertices[1].Color = Color;
vertices[2].Color = Color;
vertices[3].Color = Color;
target.Draw(vertices, PrimitiveType.Quads);
}
public uint GetPointCount()
{
return (uint)vertices.Length;
}
public Vector2f GetPoint(uint index)
{
return vertices[index].Position;
}
}
}
however the vertices seems to always be 0,0 even though I apply the properties