I need to skew a 2d polygon shape in arbitrary direction (2d). Doing it in X axis looks like this:
float skewAngle;
glm::mat4 skewMatrix;
skewMatrix[1][0] = glm::tan(glm::radians(skewAngle));
Y-axis:
skewMatrix[0][1] = glm::tan(glm::radians(skewAngle));
I need to skew in both X and Y direction at the same time,where the direction is given by an angle between 0 - 360 (-+). In some graphics programs it is also called "Skew Axis". I was trying something like this:
Let's say I want to skew the shape in direction given by 160 degrees.(zero degrees - shearing along X axis)
float skewAxisAngle = 160.0f;
float skewAngle = glm::radians(skewAxisAngle);
Then I rotate my unit direction vector,which faces x-axis by default, with skewAngle. glm::vec2 rotatedDirection = (glm::rotate(glm::vec2(1.0f, 0.0f), skewAngle));
Normalize to stay always in range [0-1]:
rotatedDirection = glm::normalize(rotatedDirection ) ;
Then I applied the direction as weight component wise to X and Y skews:
skewMatrix[1][0] = rotatedDirection.x * glm::tan(glm::radians(skewAngle));
skewMatrix[0][1] = rotatedDirection.y * glm::tan(glm::radians(skewAngle));
The result seems to be working,but only for square angles.For angles like the above,the result looks wrong. My frame of reference is Adobe After Effects.
Correct:
Wrong:
If I understand your needs right, then look at the formula below from the book (Nikulin Computer Geometry...).
It describes complex transformation of skew along axis (o,V)
- base point and direction vector. T is translation matrix, R with tilda - rotation matrix.