Transformation of an object

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Peppe

Okay, I will try to be clear. I am delving into the 2D transformation. I know that the transformation of any 2D object consists of a Base and an origin vector ( or position). The thing I can’t figure out is: if one of the “X and Y axes” of the transformation base is multiplied by a scalar and then it is added to the position of the object, the object moves (example: position + transform.x * 15), but I also know that each of the axes of the base represents the rotation and scaling of the object. This confuses me not a little and I ask why if one of the two axes is implemented for movement like the example above (for this purpose shouldn’t there only be the 2d Transform Origin vector?) in a given direction, shouldn’t it(X or Y axis) just rotate or scale the object?

:bust_in_silhouette: Reply From: omggomb

“X” and “Y” are directions. So if you add that direction to your origin your object has now moved along that direction. If you multiply that direction by 15 it has moved 15 units in the given direction.

The rotation and scale is encoded in the basis itself, not the “axes” you are referring to. The “axes” are just the columns (or rows, depending on the way basis is stored in memory) of basis.
The vectors that these columns form, “X” and “Y” are the global directions x and y, but transformed by the rotation and scale of the basis. For rotation and scale transforms these vectors are of length 1.

If you define the x axis to be forward, you can use this information to make the object move in the direction it is facing. Consider the following example:

  1. The object is spawned with zero transormations, this means that the
    object’s x axis and the global x axis are aligned.
  2. Now the object is rotated 90 degrees counter clockwise. Now the object’s x axis is aligned with the global y axis. So if you want to make the object move forward (meaning along its local x axis), you don’t add the vector (1, 0) but (0, 1) to the objects position. You defined (1, 0) to be forward, but since the object is rotated, its local x axis now points in the (0, 1) direction.
  3. Now consider this for an arbitrary rotation, for this you need to know in which global direction your object’s local x axis points. This is exactly what basis.x gives you.basis.y points to the left of your object, so you’d add that to it’s position if you wanted to make your object move left instead of forward.