Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Mat4 RotationMatrix(float radians)
- {
- Mat4 result;
- // assuming column-major order (first index is column, second is row)
- result[0][0] = Math.Cos(radians);
- result[0][1] = -Math.Sin(radians);
- result[1][0] = Math.Sin(radians);
- result[1][1] = Math.Cos(radians);
- return result;
- }
- Mat4 MirrorXMatrix()
- {
- Mat4 result;
- result[0][0] = -1.0f;
- result[0][1] = 0.0f;
- result[1][0] = 0.0f;
- result[1][1] = 1.0f;
- return result;
- }
- Mat4 ScaleMatrix(float x, float y)
- {
- Mat4 result;
- result[0][0] = x;
- result[0][1] = 0;
- result[1][0] = 0;
- result[1][1] = y;
- return result;
- }
- int main()
- {
- float heading = 0.2f;
- float scaleX = 2.0f;
- float scaleY = 3.0f;
- // because the order of transformations goes right to left, this matrix will rotate, then mirror, then scale.
- Mat4 shipMatrix = ScaleMatrix(scaleX, scaleY) * MirrorXMatrix() * RotateMatrix(heading);
- // assume we have ship.Points or whatever
- for (int i = 0; i < ship.Points.Length; i++)
- {
- Vec2 transformedPoint = shipMatrix * ship.Points[i];
- // now do whatever with it
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement