I am TOTALLY new to Gideros but have been researching this question for a couple days and haven't found an answer. Basically, I want to simulate the look of a cube with images on each face rotating around the x axis in response to touch gestures (the user would slide up on the cube to rotate the cube up to show what's currently on the bottom face and down on the cube to show what's currently on the top face).
A simplistic implementation would be to have a sprite for the front face and when the user slides scale the x-axis on that sprite down while scaling the x-axis on another sprite up, adjusting their locations as necessary to give the impression of one face rotating out of view while the other rotates into view. However, this ignores perspective; as the faces rotate in and out of view, the side angles need to change due to perspective. Basically, the sides should be parallelograms where the height and side angles change as the cube is rotated.
I thought it might be possible to do this using matrix transformations but the only skew transforms I see affect both sides identically (i.e. the shape could be skewed to "lean" left or "lean" right). If I'm trying to skew a rectangular shape, I need the left side to skew toward the right and the right side to skew toward the left.
Is there any way to do what I'm trying to describe?
Thanks in advance for any help or advice.
Comments
http://www.giderosmobile.com/forum/discussion/353/snippet-rotating-3d-cube
If it helps, I'll ONLY be rotating around the x-axis so I can get away with a pseudo-3D instead of needing to model a fully realistic 3D rotating cube.
also theoretically you could achieve similar result with transformation (skewing) but I have not seen any example to this
http://www.flashandmath.com/advanced/cube/index.html
I don't see any problems with this, having seen similar examples in Corona. Have fun.
- Ian
I've put this part of my project on temporary hold so I could try to get SOMETHING written and not get hung up too early on graphical flourishes. I'm hoping that by the time I'm ready to get back to this effect I'll have enough experience with Gideros and Lua that it will be a bit easier.
My intention would be to use this from Gideros under iOS via BhWax. However, it appears there is also an Android version so one might be able to build a plugin for that too.
BTW, I haven't started this project yet so I can't provide real details - it's just an idea ATM.
best regards
I'm at a loss for how performant it would be under Android's matrix of pain though… (-X Someone would have to test using @ar2rsawseen 's Android web view plugin. (I'd be very interested to hear the results!)
Best,
- Ian
Basically, I've modified the SceneManager so it can be housed within any Sprite instead of within the stage. While I discovered a lot of transitions aren't quite what I expected when run that way, the ones that were close enough to the type of transition I needed (such as flip) looked close enough to be promising. From there, I took the "FlipWithShade" transition and created four new transitions: RotateUpWithShade, RotateDownWithShade, RotateLeftWithShade, and RotateRightWithShade. These new transitions simultaneously scale scene1 and scene2 along the timeline in inverse proportions so that the two always add up to the parent scene's width or height. One scene is fixed at X=0 or Y=0 (depending on whether I'm rotating up/down or left/right) and the other is fixed to the opposite edge of the other scene.
Here's the code in case anyone else might find it useful. You'll note that I've added an extra parameter to the transitions, "parent." This is due to my modifications to SceneManager so I could house it inside another sprite. If you want to use these transitions in the standard SceneManager, just remove that parameter and replace the lines that calculate width/height with the standard ones that use application:getContentWidth() or application:getContentHeight().
BTW, I'm not totally satisfied with the shading effect... it seems a bit too strong when seen on a rotating cube as opposed to the standard FlipWithShade. I might either tone it down so it doesn't go all the way to 0 or maybe look into passing a factoring parameter to the transition so the level of shading can be adjusted.
function SceneManager.rotateLeftWithShade(parent, scene1, scene2, t)
local width = parent:getWidth()
local s = 1 - t
scene1:setScaleX(s)
scene1:setX(0)
scene1:setColorTransform(1 - t, 1 - t, 1 - t, 1)
scene2:setScaleX(t)
scene2:setX(width - t * width)
scene2:setColorTransform(t, t, t, 1)
end
function SceneManager.rotateRightWithShade(parent, scene1, scene2, t)
local width = parent:getWidth()
local s = 1 - t
scene1:setScaleX(s)
scene1:setX(t * width)
scene1:setColorTransform(1 - t, 1 - t, 1 - t, 1)
scene2:setScaleX(t)
scene2:setX(0)
scene2:setColorTransform(t, t, t, 1)
end
function SceneManager.rotateUpWithShade(parent, scene1, scene2, t)
local height = parent:getHeight()
local s = 1 - t
scene1:setScaleY(s)
scene1:setY(0)
scene1:setColorTransform(1 - t, 1 - t, 1 - t, 1)
scene2:setScaleY(t)
scene2:setY(height - t * height)
scene2:setColorTransform(t, t, t, 1)
end
function SceneManager.rotateDownWithShade(parent, scene1, scene2, t)
local height = parent:getHeight()
local s = 1 - t
scene1:setScaleY(s)
scene1:setY(t * height)
scene1:setColorTransform(1 - t, 1 - t, 1 - t, 1)
scene2:setScaleY(t)
scene2:setY(0)
scene2:setColorTransform(t, t, t, 1)
end