Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualirreversible

Posted 21 March 2013 - 11:24 PM

The solution is to translate the rotation pivot to the origin, rotate and then translate back (in short, you're missing a sign in your code).

 

For instance assume you have a unit square (width and height = 1) centered on the origin (eg its far corners are [-0.5, -0.5] and [+0.5, +0.5]) and you want to rotate it around its upper left corner ([-0.5, 0.5]): you would first translate the cube's origin to this pivot, eg subtract [-0.5, +0.5] from all vertex coordinates, then rotate them and finally undo the translation by adding [-0.5, +0.5] to all vertices.

 

As for scaling - consider the following order: scale, translate, rotate, translate back. Store your rectangle in a "rest position" and calculate its transformed vertices from scratch every time it's scaled or rotated.


#1irreversible

Posted 21 March 2013 - 11:23 PM

The solution is to translate the rotation pivot to the origin, rotate and then translate back (in short, you're missing a sign in your code).

 

For instance assume you have a unit square (width and height = 1) centered on the origin (eg its far corners are [-0.5, -0.5] and [+0.5, +0.5]) and you want to rotate it around its upper left corner ([-0.5, 0.5]): you would first translate the cube's origin to this pivot, eg add [-0.5, +0.5] to all vertex coordinates, then rotate them and finally undo the translation by adding -[-0.5, +0.5] or [+0.5, -0.5] to all vertices.

 

As for scaling - consider the following order: scale, translate, rotate, translate back. Store your rectangle in a "rest position" and calculate its transformed vertices from scratch every time it's scaled or rotated.


PARTNERS