Skip to content
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

Implement shape transformations with matrix2d #771

Closed
parasyte opened this issue Feb 5, 2016 · 7 comments
Closed

Implement shape transformations with matrix2d #771

parasyte opened this issue Feb 5, 2016 · 7 comments
Milestone

Comments

@parasyte
Copy link
Collaborator

parasyte commented Feb 5, 2016

Issue was reported on the forum: https://groups.google.com/d/msg/melonjs/lXxOv__I0fA/Y9G3rSEiGAAJ

The shapes API does not allow rotation or scaling around an arbitrary center point. Using matrix2d will solve this.

Bonus: #601 can be fixed by setting the default matrix to identity for orthographic projections, and a pre-projected matrix for isometric and hexagonal projections.

@parasyte parasyte added this to the 3.1.0 milestone Feb 7, 2016
@obiot obiot modified the milestones: 4.0.0, 3.1.0 Apr 7, 2016
@obiot
Copy link
Member

obiot commented May 25, 2016

this thing should be as simple as something like this actually (pseudo-code) :

Shape.transform(Matrix2d mat) {
    for point in this.points {
        transform all the point of this shapes using the given matrix
        mat.transformPoint ( point ) ;
    }
} 

and that's all ?

@obiot
Copy link
Member

obiot commented May 25, 2016

        transformPoint : function(x, y, vec) {
            vec = vec || new me.Vector2d();
            vec.x = x * this.a + y * this.c + this.e;
            vec.y = x * this.b + y * this.d + this.f;
            return vec;
        },

@parasyte
Copy link
Collaborator Author

parasyte commented May 26, 2016

I thought for sure we already had that ... Because I implemented it specifically for WebGL:

transformVector : function (v) {
-->
this.matrix.transformVector(points[i]);

Strange thing is you renamed it, for some reason... That's not very nice from a semver point of view; usually we would go through a deprecation period for API breakage like that.

@obiot
Copy link
Member

obiot commented May 26, 2016

the function was private before I renamed it (@ignore tag) so does not really matter as nobody knew it was there, except you and me :)

@obiot
Copy link
Member

obiot commented May 26, 2016

actually, only you knew it was there :P

@obiot obiot closed this as completed May 26, 2016
@obiot obiot reopened this May 26, 2016
@parasyte
Copy link
Collaborator Author

FWIW, the function multiplies a matrix and vector together. So the previous name was more fitting, right? The only other method we have named transform is just an assignment operator.

@obiot
Copy link
Member

obiot commented May 26, 2016

sure I can modify it back to multiplyVector if you think it's a better fit. now transformVector also means that we apply this transformation matrix to the given vector, so both actually works for me,

obiot added a commit that referenced this issue Sep 5, 2016
also add a `transform` method for renderable, as they do inherit from
me.Rect/me.Polygon, and this was causing cohesion issue with the parent
API vs the object implementation,
obiot added a commit that referenced this issue Sep 5, 2016
@obiot obiot closed this as completed Sep 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants