GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


orthonormal by taby
1
 
// direction should already be normalized
vector_3 z_calc(dir_x, dir_y, dir_z);

vector_3 axis; 

if (fabsf(z_calc.x) <= fabsf(z_calc.y) && fabsf(z_calc.x) <= fabsf(z_calc.z)) 
    axis.set(1, 0, 0); 
else if (fabsf(z_calc.y) <= fabsf(z_calc.x) && fabsf(z_calc.y) <= fabsf(z_calc.z)) 
    axis.set(0, 1, 0); 
else 
    axis.set(0, 0, 1); 

vector_3 x_calc = z_calc.cross(axis);
x_calc.normalize();
vector_3 y_calc = z_calc.cross(x_calc);

float m[16];
m[0] = x_calc.x;
m[1] = x_calc.y;
m[2] = x_calc.z;
m[3] = 0.0f;
m[4] = y_calc.x;
m[5] = y_calc.y;
m[6] = y_calc.z;
m[7] = 0.0f;
m[8] = z_calc.x;
m[9] = z_calc.y;
m[10] = z_calc.z;
m[11] = 0.0f;
m[12] = 0.0f;
m[13] = 0.0f;
m[14] = 0.0f;
m[15] = 1.0f;

glMultMatrixf(m);