It is not possible to deduce X and Y stretch factors to reach your goal, they simply do not exist.
One solution is to first rotate your object so that its main axes coincide with the main X and Y axes, then apply the squash/stretch transformation, then rotate the object back to its original orientation.
In terms of matrices, this would be the matrices involved, where SQ ≤ 1
is the squash factor, ST ≥ 1
is the stretch factor, and vx
and vy
are the normalised directions of motion (ie. you can get vx
and vy
by normalising your direction vector):
| vx -vy | | SQ 0 | | vx vy |
| vy vx | | 0 ST | | -vy vx |
The product of these matrices is:
| SQ*vx²+ST*vy² (SQ-ST)*vx*vy |
| (SQ-ST)*vx*vy SQ*vy²+ST*vx² |
It is not a trivial matrix but you can probably inject it into your framework. Otherwise, you can still apply the three transformations (inverse rotation - scale - rotation) separately.