New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed transformation matrix #42

Merged
merged 1 commit into from May 1, 2015

Conversation

Projects
None yet
2 participants
@kr41
Contributor

kr41 commented May 1, 2015

Here is how to test the fix. Add to the source/Dgame/test/main.d these lines:

    Shape s1 = new Shape(Geometry.Quad, [Vertex(0, 0), Vertex(100, 0), Vertex(100, 100), Vertex(0, 100)]);
    s1.setColor(Color4b.Green);
    s1.setCenter(50, 50);
    s1.setRotation(45);
    s1.setPosition(240, 320);

    Shape s2 = new Shape(Geometry.Quad, [Vertex(0, 0), Vertex(50, 0), Vertex(50, 50), Vertex(0, 50)]);
    s2.setColor(Color4b.Blue);
    s2.setCenter(25, 25);
    s2.setPosition(240, 320);

    Shape s3 = new Shape(10, Vector2f(0, 0));
    s3.setColor(Color4b.Red);
    s3.setRotation(90);
    s3.setPosition(240, 320);

// within render loop

        wnd.draw(s1);
        wnd.draw(s2);
        wnd.draw(s3);

Without the fix you will get this. Shapes should be at the center of the window, but they actually not.
before

With the fix you will get this.
after

@Dgame

This comment has been minimized.

Owner

Dgame commented May 1, 2015

Nice one. I'll merge it and then locally test.

Dgame added a commit that referenced this pull request May 1, 2015

Merge pull request #42 from kr41/master
Fixed transformation matrix

@Dgame Dgame merged commit 5a3a2c4 into Dgame:master May 1, 2015

@Dgame

This comment has been minimized.

Owner

Dgame commented May 1, 2015

Sadly it seems that there is something wrong now. If a Sprite has a center (to rotate it) I cannot set the 'real' position (upper left corner) anymore. Only the position where the center is placed.

@kr41

This comment has been minimized.

Contributor

kr41 commented May 1, 2015

IMHO, that is right behavior. For instance, I have a sprite of tank. It has its center (as a game object, not just image). It rotates around this center. And the center also represents its position.

@Dgame

This comment has been minimized.

Owner

Dgame commented May 1, 2015

You could try to implement your desired behaviour with a switch: *.enable CenterPositioning(true) or somewhat like that (maybe as property). But I think that should not be the default behaviour, because it would confuse people.

@Dgame

This comment has been minimized.

Owner

Dgame commented May 1, 2015

Maybe it is correct behaviour, but not for anyone. ;) The normal positioning (in e.g. SDL, SFML) is the upper left corner.

@kr41

This comment has been minimized.

Contributor

kr41 commented May 1, 2015

Hmm, I was confused and decided, that it was a bug.

@Dgame

This comment has been minimized.

Owner

Dgame commented May 1, 2015

I'm sorry. ;) But did you ever tried SFML for instance? AFAIK there is the upper left corner the default position (at least the last time I did worked with it). And in every book I read it is described that way. Therefore we should stay with this behaviour, to not confuse people coming from SFML or the game dev.

@Dgame

This comment has been minimized.

Owner

Dgame commented May 1, 2015

But it is up to you to cover both ways, if you want. ;)

@kr41

This comment has been minimized.

Contributor

kr41 commented May 1, 2015

Ok, I will think how to implement it.

@Dgame

This comment has been minimized.

Owner

Dgame commented May 1, 2015

Should be easy:

  • a property useCenterAsPosition or useCenterPositioning (think of something appropriate)
  • if that property is true, choose your behaviour, otherwise (the default) use the current behaviour.

If I think about it, a method would be smarter, to notify the transformation immediately. Of course a getter method should be there too then.

@Dgame

This comment has been minimized.

Owner

Dgame commented May 1, 2015

@kr41 What did you think about the following, I think that would be a more "smooth" design and wouldn't feel like a hack as 'useCenterPositioning' may feel like.

  • setRotationCenter: would be the current setCenter method. This name should be more suitable, as it makes clear, that it is only for rotation (as it is currently).
  • setOrigin: default, the position is the upper left corner, but with a call to setOrigin that would change for positioning and rotation (so it would be superior to setRotationCenter or would call it internally).
@kr41

This comment has been minimized.

Contributor

kr41 commented May 1, 2015

I was going to implement it in the same way :)

@Dgame

This comment has been minimized.

Owner

Dgame commented May 1, 2015

OK, then I'll leave it to you. I look forward to the result. :)

@Dgame

This comment has been minimized.

Owner

Dgame commented May 2, 2015

@kr41 Made you progress? ;) I would love to see how you would solve this and how it differs from my imagination.

@Dgame

This comment has been minimized.

Owner

Dgame commented May 3, 2015

Should be done by 2984813

@kr41

This comment has been minimized.

Contributor

kr41 commented May 4, 2015

Hi. Unfortunately, I ran out of my vacation and don't have enough of free time to hack around the project. So, I will fiddle with it in future, but it won't be so active, as it was on the last week.

@Dgame

This comment has been minimized.

Owner

Dgame commented May 4, 2015

Hi, that is really unfortunate, it was fun. But it's enough if you report bugs/features from time to time and I fix/implement them. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment