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

Inverse Matrix #35

Closed
Unreal852 opened this issue Oct 7, 2020 · 2 comments
Closed

Inverse Matrix #35

Unreal852 opened this issue Oct 7, 2020 · 2 comments

Comments

@Unreal852
Copy link

Unreal852 commented Oct 7, 2020

Is it possible to invert matrix ? ( C# lib ). Actually i'm drawing rectangles, and using Translate and Scale to allow Pan & Zoom. Thats working, but i can't calculate mouse position because the rectangles positions changed via the Matrix translate but there is no way to also translate mouse pos (or i didn't find how).

@jingwood
Copy link
Owner

I have added an example code to do the hit-test using an inverse transformation.
You may have to create a completed transformation system to draw objects and perform the hit-test for every objects.

I think an common method is to make objects have transform property and its inverse. e.g.:

  • Object
    • Local position
    • Transform (Matrix3x3)
    • Inverse Transform (Matrix3x3)

To draw the object:

g.setTransform(obj.Transform);
g.drawRect(...);

To hit-test point:

var transformedPoint = obj.InverseTransform.TransformPoint(p);
bool isHitted = rect.ContainsPoint(transformedPoint);

I have also added two new APIs SetTransform and GetTransform to set and get a transform into Direct2D context.
You can get a transform during drawing object and calculate the inverse for hit-test.
The Direct2D receives a 3x2 matrix which can be simply converted from a 3x3 matrix.

Here is the example code

@Unreal852
Copy link
Author

Working like a charm ! Thanks

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

No branches or pull requests

2 participants