Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

When you declare your corners as such:

    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
    };

It seems that you are adjusting the corners to be around X and Y and are treating (X, Y) as your origin and your OriginX and OriginY values are just the offsets.

That being said, I don't think this line within your EnableDebugDraw block is right, assuming this is your attempt at drawing the origin:

        GL.Vertex2(X + OriginX, Y + OriginY);

I believe your origin should simply be (X, Y) making your draw statement:

        GL.Vertex2(X, Y);
share|improve this answer
    
thanks, now I feel really dumb :D, would upvote if I had the reputation –  vinzBad Nov 20 '12 at 16:51
    
Sometimes it just takes a second set of eyes. :) –  SpartanDonut Nov 20 '12 at 20:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.