Why do I have to divide the origin of a quad by 4 instead of 2?
- by vinzBad
I'm currently transitioning from C#/XNA to C#/OpenTK but I'm getting stuck at the basics.
So I have this Sprite-Class:
public static bool EnableDebugDraw = true;
public float X;
public float Y;
public float OriginX = 0;
public float OriginY = 0;
public float Width = 0.1f;
public float Height = 0.1f;
public Color TintColor = Color.Red;
float _layerDepth = 0f;
public void Render()
{
Vector2[] corners =
{
new Vector2(X-OriginX,Y-OriginY), //top left
new Vector2(X +Width -OriginX,Y-OriginY),//top right
new Vector2(X +Width-OriginX,Y+Height-OriginY),//bottom rigth
new Vector2(X-OriginX,Y+Height-OriginY)//bottom left
};
GL.Color3(TintColor);
GL.Begin(BeginMode.Quads);
{
for (int i = 0; i < 4; i++) GL.Vertex3(corners[i].X,corners[i].Y,_layerDepth);
}
GL.End();
if (EnableDebugDraw)
{
GL.Color3(Color.Violet);
GL.PointSize(3);
GL.Begin(BeginMode.Points);
{
for (int i = 0; i < 4; i++) GL.Vertex2(corners[i]);
}
GL.End();
GL.Color3(Color.Green);
GL.Begin(BeginMode.Points);
GL.Vertex2(X + OriginX, Y + OriginY);
GL.End();
}
With the following setup I try to set the origin of the quad to the middle of the quad.
_sprite.OriginX = _sprite.Width / 2;
_sprite.OriginY = _sprite.Height / 2;
but this sets the origin to the upper right corner of the quad, so i have to
_sprite.OriginX = _sprite.Width / 4;
_sprite.OriginY = _sprite.Height / 4;
However this is not the intended behaviour, could you advise me how I fix this?