How do I calculate localToContent() x,y values on distorted Snapshot?

I have created a newSnapshot with an image object added to the group.  The localToContent code correctly displays the X,Y of the SmallCircle in relation to the screen:

local screenWidth  = display.actualContentWidth  local screenHeight = display.actualContentHeight local backgroundGraphic = display.newImageRect( "backgroundGraphic",360,2378)  snapshot = display.newSnapshot( screenWidth \* 2 , screenHeight \* 2 ) snapshotGroup = snapshot.group snapshotGroup:insert( backgroundGraphic ) --add SmallCircle to snapshop group SmallCircle= display.newImage( "SmallCircle.png") snapshotGroup:insert( SmallCircle ) --Determine Screen Coordinates of SmallCircle (Returns correct screen coordinates) local sqCenterX1, sqCenterY1 = SmallCircle:localToContent( 0, 0 )

If I apply Quadrilateral Distortion on the snapshot, the localToContent code does not display the correct X,Y coordinates of the Small Circle.

--Quadrilateral Distortion w = screenWidth  \* .45 h = screenHeight \* .45 snapshot.path.x1 = w snapshot.path.y1 = h snapshot.path.x2 = -w snapshot.path.y2 = -h snapshot.path.x3 = w snapshot.path.y3 = -h snapshot.path.x4 = -w snapshot.path.y4 = h snapshot:invalidate() --Determine Screen Coordinates of SmallCircle (Incorrect coordinates returned) local sqCenterX1, sqCenterY1 = SmallCircle:localToContent( 0, 0 ) --Incorrectly returns the same x,y screen coordinates of the smallcircle without quad distortion. The distortion should change the coordinates as the small circle graphic in relation to the screen.

Can anyone suggest how to use localToContent to get accurate screen coordinates on a distorted group?  

I’ve read in other posts related to Mode7 that I need to perform a 3D transform to calculate the z-depth…but I don’t know how.

Thanks in advance.

Here is a cleaner version of the code:

local snapshot = display.newSnapshot( 640, 960 ) snapshot.x    = display.contentCenterX snapshot.y    = display.contentCenterY local snapshotGroup = snapshot.group local myImage = display.newImage( "grid.jpg" ) snapshotGroup:insert( myImage ) local screenWidth  = display.actualContentWidth  local screenHeight = display.actualContentHeight CameraAngle = .2 w = screenWidth  \* CameraAngle h = screenHeight \* CameraAngle snapshot.path.x1 = w snapshot.path.y1 = h snapshot.path.x2 = -w snapshot.path.y2 = -h snapshot.path.x3 = w snapshot.path.y3 = -h snapshot.path.x4 = -w snapshot.path.y4 = h snapshot:invalidate() redsquare= display.newImage( "redsquare.jpg") redsquare.x = 0 redsquare.y = 440 redsquare:toFront() snapshotGroup:insert( redsquare ) snapshot:invalidate() local sqCenterX1, sqCenterY1 = redsquare:localToContent( 0, 0 ) print(sqCenterX1..":"..sqCenterY1) 

When I distort the snapshot the redsquare should have new x,y screen coordinates when using localToContent().

Basically the localToContent() does not use the distortion value and bases the x,y coordinates on the flat (2D) angle.

Thanks again.

Here is an image:

https://www.dropbox.com/s/7ieymfbdqg5xo23/screen.jpg?dl=0

Desperately looking for a solution.  Am I not asking the question correctly?  Please help.

Hi @byron5,

I think you’re asking the correct question, but there isn’t an “easy” solution. I believe you’ll need to figure out the math calculation for this, but I’m not sure which formula(s) would be best for that. Have you searched online for solutions to math operations in regards to quadrilateral adjustments?

Brent

Thanks for the reply Brent.  If localToContent() was able to correctly determine the x,y screen coordinates of the object that is distorted in the snapshot then I have my solution.  

I am looking at a mode 7 solution that might assist…but at this stage I am stuck.

Please continue the thread here:

http://forums.coronalabs.com/topic/56022-incorrect-localtocontent-screen-coordinates-with-quad-distortion-on-snapshot-group/

Thanks

Rob

Here is a cleaner version of the code:

local snapshot = display.newSnapshot( 640, 960 ) snapshot.x    = display.contentCenterX snapshot.y    = display.contentCenterY local snapshotGroup = snapshot.group local myImage = display.newImage( "grid.jpg" ) snapshotGroup:insert( myImage ) local screenWidth  = display.actualContentWidth  local screenHeight = display.actualContentHeight CameraAngle = .2 w = screenWidth  \* CameraAngle h = screenHeight \* CameraAngle snapshot.path.x1 = w snapshot.path.y1 = h snapshot.path.x2 = -w snapshot.path.y2 = -h snapshot.path.x3 = w snapshot.path.y3 = -h snapshot.path.x4 = -w snapshot.path.y4 = h snapshot:invalidate() redsquare= display.newImage( "redsquare.jpg") redsquare.x = 0 redsquare.y = 440 redsquare:toFront() snapshotGroup:insert( redsquare ) snapshot:invalidate() local sqCenterX1, sqCenterY1 = redsquare:localToContent( 0, 0 ) print(sqCenterX1..":"..sqCenterY1) 

When I distort the snapshot the redsquare should have new x,y screen coordinates when using localToContent().

Basically the localToContent() does not use the distortion value and bases the x,y coordinates on the flat (2D) angle.

Thanks again.

Here is an image:

https://www.dropbox.com/s/7ieymfbdqg5xo23/screen.jpg?dl=0

Desperately looking for a solution.  Am I not asking the question correctly?  Please help.

Hi @byron5,

I think you’re asking the correct question, but there isn’t an “easy” solution. I believe you’ll need to figure out the math calculation for this, but I’m not sure which formula(s) would be best for that. Have you searched online for solutions to math operations in regards to quadrilateral adjustments?

Brent

Thanks for the reply Brent.  If localToContent() was able to correctly determine the x,y screen coordinates of the object that is distorted in the snapshot then I have my solution.  

I am looking at a mode 7 solution that might assist…but at this stage I am stuck.

Please continue the thread here:

http://forums.coronalabs.com/topic/56022-incorrect-localtocontent-screen-coordinates-with-quad-distortion-on-snapshot-group/

Thanks

Rob