Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: glrotatef and my matrix::rotate

  1. #1
    Newbie Newbie
    Join Date
    Dec 2013

    glrotatef and my matrix::rotate

    hi all,

    i want to obtain a mousellok effect.

    using fixed opengl function, this can be made doing


    using my matrix class, the result is not as above:

    mat4 cammtx;

    because camera not still holding the y axis

    why can i achieve the same glRotate behaviour with my matrix::rotate implementation?

    here is my rotate function (input vector is not normalized, i know, but i pass only unit vectors)

    void rotate(float* mr,float* m,float angle,float x,float y,float z)
    float a=angle*PI_OVER_180;
    float m2[16] = {0};

    float c=cos(a);
    float s=sin(a);

    float xx=x*x,

    m2[0] = xx+(1.0f-xx)*c;
    m2[4] = (1.0f-c)*x*y-s*z;
    m2[8] = (1.0f-c)*x*z+s*y;
    m2[3] = 0.0f;

    m2[1] = (1.0f-c)*y*x+s*z;
    m2[5] = yy+(1.0f-yy)*c;
    m2[9] = (1.0f-c)*y*z-s*x;
    m2[7] = 0.0f;

    m2[2] = (1.0f-c)*z*x-s*y;
    m2[6] = (1.0f-c)*z*y+s*x;
    m2[10] = zz+(1.0f-zz)*c;
    m2[11] = 0.0f;

    m2[12] = 0;
    m2[13] = 0;
    m2[14] = 0;
    m2[15] = 1.0f;


    float* multiply(float* c,float* aa,float* bb)
    for(int i = 0; i < 4; i++)
    c[i*4] = bb[i*4] * aa[0] + bb[i*4+1] * aa[4] + bb[i*4+2] * aa[8] + bb[i*4+3] * aa[12];
    c[i*4+1] = bb[i*4] * aa[1] + bb[i*4+1] * aa[5] + bb[i*4+2] * aa[9] + bb[i*4+3] * aa[13];
    c[i*4+2] = bb[i*4] * aa[2] + bb[i*4+1] * aa[6] + bb[i*4+2] * aa[10] + bb[i*4+3] * aa[14];
    c[i*4+3] = bb[i*4] * aa[3] + bb[i*4+1] * aa[7] + bb[i*4+2] * aa[11] + bb[i*4+3] * aa[15];
    return c;

    thank you for your time

    Last edited by elemich; 12-13-2013 at 09:14 AM.

  2. #2
    Intern Contributor
    Join Date
    Jul 2013
    hi elemich,
    It might not be my business to ask why, but ..
    The functions (or something eqvivalent) are present in both glu and glm (Opengl-mathematics) and there is nothing that prevents you from using it.
    I'm not in for checking your code. It's not particular GL but appear in a lot of places all related to 3d graphics.
    You get your question through, but what is "a mousellok effect".
    "because camera not still holding the y axis" .. is not understood either.

    Sooner or later you want to solve matrix-equations (find the inverse matrix). By that time you'll know how glm works and have no problem taking advantage of it ..
    Last edited by CarstenT; 12-14-2013 at 01:47 AM.

Posting Permissions

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