/** @brief scales the matrix m and stores it in r @param r the result matrix @param m the target matrix @param sx the scale factor for the X dimension @param sy the scale factor for the Y dimension @param sz the scale factor for the Z dimension */ void scaleMM(float *r,float *m, float sx, float sy, float sz){ float scaleMatrix[16] = {sx,0 ,0 ,0, 0 ,sy,0 ,0, 0 ,0 ,sz,0, 0 ,0 ,0 ,1}; multiplyMM(r, m, scaleMatrix); }
/** @brief Translates the matrix m and stores it in matrix R @param r the result matrix @param m the target matrix @param x the x translation @param y the y translation @param z the z translation */ void translateMM(float *r,float *m, float x, float y, float z){ float translationMatrix[16] = {1,0,0,0, 0,1,0,0, 0,0,1,0, x,y,z,1}; multiplyMM(r, m, translationMatrix); }
void setup_viewport(int width, int height) { glViewport(0, 0, width, height); // Setup our screen width and height for normal sprite translation. orthoM(mtrxProjection, 0, 0, width, 0, height, 0, 50); // Set the camera position (View matrix) setLookAtM(mtrxView, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0); // Calculate the projection and view transformation multiplyMM(mtrxProjectionAndView, mtrxProjection, mtrxView); }
static void rotateM(float* m, int mOffset,float a, float x, float y, float z) { float rm[16]; setRotateM(rm, 0, a, x, y, z); float rem[16]; multiplyMM(rem, 0, m, 0, rm, 0); for(int i=0;i<16;i++) { m[i]=rem[i]; } }
/** @brief performs a axis angle rotation around the arbitrary axis (_x,_y,_z) @param r the result matrix @param m the target matrix @param angle the angle (in degrees) to rotate @param _x the x component of the vector to use as a axis @param _y the y component of the vector to use as a axis @param _z the z component of the vector to use as a axis */ void rotateMM(float *r,float *m, float angle, float _x, float _y, float _z){ float s = sin(to_rad(angle)); float c = cos(to_rad(angle)); float magnitude = sqrt(_x*_x + _y*_y + _z*_z); float x = _x / magnitude; float y = _y / magnitude; float z = _z / magnitude; float rotationMatrix[16] = {c+(x*x)*(1-c),y*x*(1-c)+z*s, z*x*(1-c) - y*s,0, y*x*(1-c)-z*s,c+(y*y)*(1-c), z*y*(1-c) + x*s,0, z*x*(1-c)+y*s,y*z*(1-c)-x*s, c+z*z*(1-c) ,0, 0,0,0,1}; multiplyMM(r, m, rotationMatrix); return; }
static void scaleM(float* m, int mOffset, float x, float y, float z) { float sm[16]; setIdentityM(sm, 0); sm[0] = x; sm[5] = y; sm[10] = z; sm[15] = 1; float tm[16]; multiplyMM(tm,0,m,0,sm,0); for(int i=0;i<16;i++) { m[i]=tm[i]; } }//