Help with transformations....

Monkey Forums/Monkey Programming/Help with transformations....

NoOdle(Posted 2011) [#1]
I have never used transformations before so I figured it was time to pull my finger out and tackle it head on.

Below is some code I wrote to test transformations. If you run it you will see what it does; Left and Right keys moves the layer and Space rotates the layer. This all works fine and I'm quite pleased with the results, the children all rotate and scale and translate with the parent.

I would like to improve the transformations further. At the moment the layers rotate around the origin 0, 0 but I would like them to rotate around the anchorPointX, anchorPointY variable. These are in the range of 0 - 1 so 0.5 would be the centre. Layers have the size of the screen and an anchor point set as 0.5, so what I would like to achieve is all the children to rotate around the size * anchorPoint rather that the origin 0, 0.

I have tried fiddling to see if I can achieve anything close to what I'm after but I'm stuck. If anyone can point me in the right direction or even modify the code to take into account a Nodes anchor point, this would be great!




Thanks guys!


NoOdle(Posted 2011) [#2]
Urgh, something is definitely not right with the code, I added in some extra controls to make sure that the parent - child relationship was working ok. As you can see by running the code below and using w/a/s/d to move the circle and z/x to rotate it, the rectangle does not orbit the circle as expected.




NoOdle(Posted 2011) [#3]
Ok ignore the previous post, It seems the order of transformation was wrong, now using TRS and the orbiting is now working as expected.

Still the original problem of rotating around the size * anchorPoint. More fiddling required.... can anyone see what I would need to change?




NoOdle(Posted 2011) [#4]
Well it took a while but I think I've cracked it. For anyone that is interested below is the code.

up / down / left / right moves layer
+ / - scales layer
< / > rotates the layer

w / a / s / d moves test object + children
1 / 2 scales test object + children
z / x rotates test object + children


I would like to thank Warpy, his transform_mouse example in bananas helped me to understand what I was doing wrong!





AdamRedwoods(Posted 2011) [#5]
More reference for the Transform command:

http://www.monkeycoder.co.nz/Community/posts.php?topic=1098&


NoOdle(Posted 2011) [#6]
Aha thanks Adam, I was struggling to figure that out from the documentation! :)


Gianmichele(Posted 2014) [#7]
WOW Thanks! This is exactly what I was looking for :)