I need help. I have added pinch and zoom and drag for images to my ebook app, but I cannot figure out the trigonometry and Lua/Corona code to prevent the user from moving an image off the screen.
Because I allow the user to rotate while pinching/zooming, I cannot simply check corners of the image to figure out if part is on screen.
I have tried maintaining minimum distances between screen center and object center, but that fails because the object can zoom, and if large enough, the minimum distance trick means the user cannot see part of the enlarged object. Since objects are rectangular and not square, it is tricky to calculate the distances, since to do it right means tracking distances that are elliptical!
I tried physics briefly, to see if I could maintain a collision, but that didn’t go anywhere.
I tried using the object.path to find the corners, but I could set them but not find them, for either an image or a rectangle.
I’ve tried to get a Separating Axis Theorem working, based on others’ code. Not yet.
I was unable to use physics. I thought to create two shapes and only allow moves that kept a collision active, but that hasn’t worked either.
SPECIFIC ISSUES:
- Cannot get object.path to report corners, e.g. myobj.path.x2 reports the same point as myobj.path.x1
Help?