Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: non uniform scale and then rotation creates squashed sprite.

  1. #1
    Intern Newbie
    Join Date
    Aug 2012
    Posts
    48

    non uniform scale and then rotation creates squashed sprite.

    I am drawing a sprite and when it's a square and I rotate it, there's no problem. When I do a non uniform scale such as stretch the height 2x the width then rotate. The sprite will seem to get squished when it is rotated.

    I am using the vectormath library; this is rotation code with all the intermediate functions also documented
    Code :
    static inline void vmathM4MakeRotationZ( VmathMatrix4 *result, float radians )
    {
        float s, c;
        s = sinf( radians );
        c = cosf( radians );
        vmathV4MakeFromElems( &result->col0, c, s, 0.0f, 0.0f );
        vmathV4MakeFromElems( &result->col1, -s, c, 0.0f, 0.0f );
        vmathV4MakeZAxis( &result->col2 );
        vmathV4MakeWAxis( &result->col3 );
    }
     
    static inline void vmathV4MakeFromElems(VmathVector4 *result, float _x,
                                            float _y, float _z, float _w) {
        result->x = _x;
        result->y = _y;
        result->z = _z;
        result->w = _w;
    }
     
    static inline void vmathV4MakeZAxis(VmathVector4 *result) {
        vmathV4MakeFromElems(result, 0.0f, 0.0f, 1.0f, 0.0f);
    }

    Why does a non uniform scale cause such an issue and how can I solve it?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,519
    If you're trying to scale the sprite, the matrices should be multiplied with the rotation on the left and the scale on the right.

  3. #3
    Intern Newbie
    Join Date
    Aug 2012
    Posts
    48
    Quote Originally Posted by GClements View Post
    If you're trying to scale the sprite, the matrices should be multiplied with the rotation on the left and the scale on the right.
    changing the multiplication order for my scale and rotation it now rotates properly but if I translate after rotating it seems to offset the origin of the quad.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •