Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

2D translation question.  RSS feed

Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best way to relate my question is by scenario:

You have an application that draws an image on a screen. Let's say that image is just a big box. You select the point directly on the top left corner of the box. Let's say that point ON THE SCREEN is 100, 100 to make it easy. The user then moves that image to the right and zooms it. No rotation was involved. He then selects the same spot on the box...very top left. Of course since the box moved the screen coordinates are no longer 100, 100. Let's say they are now 120, 90.

How can you translate the 120, 90 back to what it would have been (100, 100) if the user had not panned and zoomed the image?

The code to move the image after the user pans and zooms looks like this. Note that the mState object also holds the X/Y coordinate the user touched on.

What is the formula that needs to be applied to that point to get it back to what it would have been pre-translation and scale in this code?

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!