Re: Pinch and Rotate
Ken, These are exactly the kinds of things I ran into as well. One thing that happens is that when rotating an image the image gets distorted and so we need the resizeQuality set to good or best but then it really slows down even further. Still looking -- Tom McGrath III http://lazyriver.on-rev.com 3mcgr...@comcast.net On Jan 24, 2012, at 2:35 AM, Ken Corey wrote: I hadn't tried that before. I tried it just now, and if anything it made the behaviour worse. This were even more jittery than before. By jittery I mean the items flash back and forth 10-20 pixels. If you move your fingers quickly, it's easy to get the image drawing in a wildly incorrect place, only settling down once the fingers move more slowly. I feel script-based multi-touch is a bit of a damp squib. The performance isn't that great, and without items (images or graphics) being able to rotate and scale, there's little reason to do it all at once. On 23/01/2012 23:19, Chris Sheffield wrote: Did you try setting acceleratedRendering to true and then setting the layerMode property of the image to dynamic? Might make a difference. Kind of guessing, though. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Pinch and Rotate
On 25/01/2012 15:54, Thomas McGrath III wrote: These are exactly the kinds of things I ran into as well. One thing that happens is that when rotating an image the image gets distorted and so we need the resizeQuality set to good or best but then it really slows down even further. Well, turns out I was a bit of a muppet about a few things... I'm still rather hazy about the 'lock' button. Apparently that needed to be checked, locking the image, and then the rotation is free. So the code works as is for images, presuming that you uncheck the tick box. As for the quality issues, what I'd suggest is that on the pinchStart event the quality of the image is saved during the pinch, the quality of the image is set to 'reduced' while pinching, and then in the pinchEnd the quality is set back to its previous value. That should keep the speed acceptable. As regarding rotation of a poly, there's a fun little function called 'revRotatePoly' that gives one an idea of what to do...but of course the coordinates of the graphic are truncated after the calculation. Do this more than a time or two, and the accumulated errors gang up on you. I'm playing with some code that does this properly, where the coordinates are stored into custom properties first, and *those* are used in the rotation calculation. It's not nearly ready to be shown yet, but I'll try to tie up the loose ends in the next day or two. None of this helps with the jitter, though. This could be caused by re-entry into the touchMove handler, though I thought I'd guarded against that. It's still creaky, but it's almost looking usable. -Ken ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Pinch and Rotate
On 25/01/2012 16:19, Ken Corey wrote: As for the quality issues, what I'd suggest is that on the pinchStart event the quality of the image is saved during the pinch, the quality of the image is set to 'reduced' while pinching, and then in the pinchEnd the quality is set back to its previous value. That should keep the speed acceptable. Gads. I really should read this before posting. Of course the quality should be set to 'normal'. There is no 'reduced'. -Ken ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Pinch and Rotate
Hi Ken Thomas, I am fighting the same battle, so please let me participate in your discussion. Ken wrote: As for the quality issues, what I'd suggest is that on the pinchStart event the quality of the image is saved during the pinch, the quality of the image is set to 'reduced' while pinching, and then in the pinchEnd the quality is set back to its previous value. That should keep the speed acceptable. I´ve tried this before reading your message, but it didn´t work. After ending the pinch and restoring the quality the image doesn´t improve it's quality on screen, even it appears as best quality. Did you try it ? Is there any way for updating the rendering quality after changing it by script ? I couldn´t find it. And also, I still cannot believe the RunRev people had not developed yet an integrated solution for pinching and zooming into livecode. It really seems a great lost of time trying to emulate an X-Code UI event this way ... __ Sergio Schvarstein sschvarst...@gmail.com __ ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Pinch and Rotate
On 25/01/2012 15:54, Thomas McGrath III wrote: These are exactly the kinds of things I ran into as well. One thing that happens is that when rotating an image the image gets distorted and so we need the resizeQuality set to good or best but then it really slows down even further. Okay, sorted things out...to a point. I'm deeply disturbed by the polys. There's got to be a better way. This version rotates the polys accurately (for some value of accurate), but now they cannot be resized (this is because I'm keeping a shadow set of point coordinates so as not to lose the fractions...and they don't get resized). If you reorder the code to resize and *then* rotate, it attempts to work, but the resizing destroys the shape of the poly. On the plus side, images are dropped down to a 'normal' resizeQuality for rotation, and then restored to the former quality on the other end, which seems to work okay. The jitter is still there (I think it's because I'm treating each finger move individually?) which is quite annoying. It still wouldn't be acceptable in real life. Perhaps the move locations need to be averaged for each move? Perhaps I'm making an error in the math. I'll give 2 gold stars to the person who figures out why it's jittery. At any rate here it is: http://its.ec/static/multitouchtest.livecode0.0.2.zip Enjoy all. -Ken ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Pinch and Rotate
Hiya Thomas, I've been meaning to take a stab at this, and your post got me off my duff. I've seen a few apps that do multitouch pinch to zoom *really* well. by that I mean that the pinch can accomplish 3 things at the same time: scale something rotate something move something The last one makes it feel really slick. Of course, if you only wanted to do one of those, no problem. I wanted to build and API with 3 main calls: pinchStart pinchMove dDistance, dAngle, dX, dY pinchEnd Start and End are for setup/cleanup, and pinchMove is where the work is done. I've created a sample script to demonstrate the concept: http://its.ec/static/multitouchtest.livecode.zip (I packaged it up this way because there is a image involved.) This works on my iPad. Jerky, but it works. On my Nexus One, the app is less impressive. Things can move, but when you try to rotate, the rotation is not uniform. Sometimes it rotates, sometimes it doesn't, sometimes it goes backwards. *shrug* It is possible to build a test harness for a desktop in just a few lines of code, but in this case I pulled them out for brevity. That means that if you've got an iPad it will work fairly well. My PC nor my Mac have multi-touch built in, so I don't know how they'd do. As always, there're flies in this particular ointment: 1) Images can't scale and rotate at the same time. In my demo, the image will rotate and move, but only when the angle of the image is zero will it scale...this will appear as pop of a larger image. A horrible work-around could be to use your main image as a template. Clone it, scale that, take a snapshot of it at the zoomed size and /then/ rotate that. Ugh. Any better way to skin this one? 2) Graphics can't be rotated natively. I found that only some graphics even report their points (rectangles, rounded rects, ovals, etc don't...so you can't rotate them). The horrible hacky way around that might be to try to implement the regular polygons using a Polygon, or even a Freehand Polygon. Maybe. Then, you could implement a rotation routine for such a Frankenstein poly. Blech. 3) It's jumpy, big time. Worse come to worse, you could try to build-in an averaging function, but I was quite surprised how jumpy it all is. 4) Not sure about the Android support. 5) Not even sure where'd you'd use this kind of thing because of uneven support. Can't use scaling with images. Can't use rotation with graphics. Both are painfully jerky. I'm quite a LiveCode newbie, so if anyone has constructive feedback on my code, or knows a more-runrev kinda way to do things I'd appreciate if you'd let me (or the list) know. Thanks, -Ken ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Pinch and Rotate
Ken, Did you try setting acceleratedRendering to true and then setting the layerMode property of the image to dynamic? Might make a difference. Kind of guessing, though. Chris On Jan 23, 2012, at 4:02 PM, Ken Corey wrote: Hiya Thomas, I've been meaning to take a stab at this, and your post got me off my duff. I've seen a few apps that do multitouch pinch to zoom *really* well. by that I mean that the pinch can accomplish 3 things at the same time: scale something rotate something move something The last one makes it feel really slick. Of course, if you only wanted to do one of those, no problem. I wanted to build and API with 3 main calls: pinchStart pinchMove dDistance, dAngle, dX, dY pinchEnd Start and End are for setup/cleanup, and pinchMove is where the work is done. I've created a sample script to demonstrate the concept: http://its.ec/static/multitouchtest.livecode.zip (I packaged it up this way because there is a image involved.) This works on my iPad. Jerky, but it works. On my Nexus One, the app is less impressive. Things can move, but when you try to rotate, the rotation is not uniform. Sometimes it rotates, sometimes it doesn't, sometimes it goes backwards. *shrug* It is possible to build a test harness for a desktop in just a few lines of code, but in this case I pulled them out for brevity. That means that if you've got an iPad it will work fairly well. My PC nor my Mac have multi-touch built in, so I don't know how they'd do. As always, there're flies in this particular ointment: 1) Images can't scale and rotate at the same time. In my demo, the image will rotate and move, but only when the angle of the image is zero will it scale...this will appear as pop of a larger image. A horrible work-around could be to use your main image as a template. Clone it, scale that, take a snapshot of it at the zoomed size and /then/ rotate that. Ugh. Any better way to skin this one? 2) Graphics can't be rotated natively. I found that only some graphics even report their points (rectangles, rounded rects, ovals, etc don't...so you can't rotate them). The horrible hacky way around that might be to try to implement the regular polygons using a Polygon, or even a Freehand Polygon. Maybe. Then, you could implement a rotation routine for such a Frankenstein poly. Blech. 3) It's jumpy, big time. Worse come to worse, you could try to build-in an averaging function, but I was quite surprised how jumpy it all is. 4) Not sure about the Android support. 5) Not even sure where'd you'd use this kind of thing because of uneven support. Can't use scaling with images. Can't use rotation with graphics. Both are painfully jerky. I'm quite a LiveCode newbie, so if anyone has constructive feedback on my code, or knows a more-runrev kinda way to do things I'd appreciate if you'd let me (or the list) know. Thanks, -Ken ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Pinch and Rotate
I hadn't tried that before. I tried it just now, and if anything it made the behaviour worse. This were even more jittery than before. By jittery I mean the items flash back and forth 10-20 pixels. If you move your fingers quickly, it's easy to get the image drawing in a wildly incorrect place, only settling down once the fingers move more slowly. I feel script-based multi-touch is a bit of a damp squib. The performance isn't that great, and without items (images or graphics) being able to rotate and scale, there's little reason to do it all at once. On 23/01/2012 23:19, Chris Sheffield wrote: Did you try setting acceleratedRendering to true and then setting the layerMode property of the image to dynamic? Might make a difference. Kind of guessing, though. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Pinch and Rotate
I also added a resizeQuality to the on touchMove handler: set the resizeQuality of image square to best -- Tom McGrath III http://lazyriver.on-rev.com 3mcgr...@comcast.net On Jan 22, 2012, at 1:57 PM, Thomas McGrath III wrote: I was playing around with the Pinch to Zoom an object lesson at: http://lessons.runrev.com/s/lessons/m/4069/l/11509-how-do-i-implement-a-multi-touch-pinch-motion And I wanted to add rotate to it as well so that I could pinch and rotate at the same time. I ran into a big wall (called Math I think) in trying to rotate based on how far from the original start point and wether I was rotating left or right. My solution works for the most part but it is not optimal or very clean and wanted to invite others to take a stab at it: I stated with the Pinch lesson stack and changed the GRAPHIC to an IMAGE and then modified the script to come up with this solution. This script goes into the card script and the card has an image named square on it. I edited it and added the rotateimage handler; local sTouchArray, sFRAMEWIDTH, sFRAMEHEIGHT on touchStart pId, pX, pY put the width of image square into sFRAMEWIDTH put the height of image square into sFRAMEHEIGHT end touchStart on touchEnd pId delete variable sTouchArray[pId] end touchEnd on touchMove pId, pX, pY set the resizeQuality of image square to best if sTouchArray[pId][startloc] is empty then put (pX comma pY) into sTouchArray[pId][startloc] end if put (pX comma pY) into sTouchArray[pId][currentloc] if the number of lines of the keys of sTouchArray is 2 then # First lets get the data out of the array put line 1 of the keys of sTouchArray into tPointOne put line 2 of the keys of sTouchArray into tPointTwo # First lets calculate the size of the picture base on the distance # between the two touch points put sTouchArray[tPointOne][startloc] into tStartLoc1 put sTouchArray[tPointTwo][startloc] into tStartLoc2 put sTouchArray[tPointOne][currentLoc] into tCurrentLoc1 if tStartLoc1 is not empty and tStartLoc2 is not empty then put resizeDistance(tStartLoc1, tStartLoc2) into tStartDistance put resizeDistance(sTouchArray[tPointOne][currentloc], sTouchArray[tPointTwo][currentloc]) into tCurrentDistance resizeimage tStartDistance, tCurrentDistance if item 2 of tStartLoc1 item 2 of tCurrentLoc1 then rotateimage left, item 2 of tStartLoc1, item 2 of tCurrentLoc1 else rotateimage right, item 2 of tStartLoc1, item 2 of tCurrentLoc1 end if end if end if end touchMove function resizeDistance pLoc1, pLoc2 local dy, dx, tDistance put item 2 of pLoc1 - item 2 of pLoc2 into dy put item 1 of pLoc1 - item 1 of pLoc2 into dx put sqrt((dy*dy) + (dx*dx)) into tDistance return tDistance end resizeDistance on rotateimage pAngle pStart pNew if pAngle contains left then put pStart - pNew into tDistance set the angle of image square to tDistance else put pNew - pStart into tDistance set the angle of image square to (- tDistance) end if unlock screen end rotateimage on resizeimage pStartDistance, pNewDistance # Work out the percentage change between the old and new image put round((pNewDistance / pStartDistance) * 100) into tPercentage # Store the original location of the image put the loc of image square into tLoc # Calculate the new width and height set the width of image square to round(sFRAMEWIDTH * (tPercentage / 100)) set the height of image square to round(sFRAMEHEIGHT * (tPercentage / 100)) set the loc of image square to tLoc unlock screen end resize image -- Tom McGrath III http://lazyriver.on-rev.com 3mcgr...@comcast.net ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Pinch and Rotate
Many thanks Thomas. This is a big help. Did you do any experiments with doing pinch to zoom and scrolling? I am wondering the relationship between the scroller messages and the touch messages. We have three properties that are of interest: canCancelTouches, delayTouches and scrollingEnabled. After reading the documentation for the live code scroller that makes specific reference to apples documentation of their scroller implementation, it appears that live code did not implement the section of the apple implementation that allows the scroller to control the resizing of the underlying content. Further reinforced by the fact that there are lessons for how to do object resizing managing the multiple touches. Can anyone confirm that my understanding is correct? Thanks Mike On 2012-01-22, at 2:07 PM, Thomas McGrath III wrote: I also added a resizeQuality to the on touchMove handler: set the resizeQuality of image square to best -- Tom McGrath III http://lazyriver.on-rev.com 3mcgr...@comcast.net On Jan 22, 2012, at 1:57 PM, Thomas McGrath III wrote: I was playing around with the Pinch to Zoom an object lesson at: http://lessons.runrev.com/s/lessons/m/4069/l/11509-how-do-i-implement-a-multi-touch-pinch-motion And I wanted to add rotate to it as well so that I could pinch and rotate at the same time. I ran into a big wall (called Math I think) in trying to rotate based on how far from the original start point and wether I was rotating left or right. My solution works for the most part but it is not optimal or very clean and wanted to invite others to take a stab at it: I stated with the Pinch lesson stack and changed the GRAPHIC to an IMAGE and then modified the script to come up with this solution. This script goes into the card script and the card has an image named square on it. I edited it and added the rotateimage handler; local sTouchArray, sFRAMEWIDTH, sFRAMEHEIGHT on touchStart pId, pX, pY put the width of image square into sFRAMEWIDTH put the height of image square into sFRAMEHEIGHT end touchStart on touchEnd pId delete variable sTouchArray[pId] end touchEnd on touchMove pId, pX, pY set the resizeQuality of image square to best if sTouchArray[pId][startloc] is empty then put (pX comma pY) into sTouchArray[pId][startloc] end if put (pX comma pY) into sTouchArray[pId][currentloc] if the number of lines of the keys of sTouchArray is 2 then # First lets get the data out of the array put line 1 of the keys of sTouchArray into tPointOne put line 2 of the keys of sTouchArray into tPointTwo # First lets calculate the size of the picture base on the distance # between the two touch points put sTouchArray[tPointOne][startloc] into tStartLoc1 put sTouchArray[tPointTwo][startloc] into tStartLoc2 put sTouchArray[tPointOne][currentLoc] into tCurrentLoc1 if tStartLoc1 is not empty and tStartLoc2 is not empty then put resizeDistance(tStartLoc1, tStartLoc2) into tStartDistance put resizeDistance(sTouchArray[tPointOne][currentloc], sTouchArray[tPointTwo][currentloc]) into tCurrentDistance resizeimage tStartDistance, tCurrentDistance if item 2 of tStartLoc1 item 2 of tCurrentLoc1 then rotateimage left, item 2 of tStartLoc1, item 2 of tCurrentLoc1 else rotateimage right, item 2 of tStartLoc1, item 2 of tCurrentLoc1 end if end if end if end touchMove function resizeDistance pLoc1, pLoc2 local dy, dx, tDistance put item 2 of pLoc1 - item 2 of pLoc2 into dy put item 1 of pLoc1 - item 1 of pLoc2 into dx put sqrt((dy*dy) + (dx*dx)) into tDistance return tDistance end resizeDistance on rotateimage pAngle pStart pNew if pAngle contains left then put pStart - pNew into tDistance set the angle of image square to tDistance else put pNew - pStart into tDistance set the angle of image square to (- tDistance) end if unlock screen end rotateimage on resizeimage pStartDistance, pNewDistance # Work out the percentage change between the old and new image put round((pNewDistance / pStartDistance) * 100) into tPercentage # Store the original location of the image put the loc of image square into tLoc # Calculate the new width and height set the width of image square to round(sFRAMEWIDTH * (tPercentage / 100)) set the height of image square to round(sFRAMEHEIGHT * (tPercentage / 100)) set the loc of image square to tLoc unlock screen end resize image -- Tom McGrath III http://lazyriver.on-rev.com 3mcgr...@comcast.net ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: