New Paste :: Recent Pastes:: Add Line Numbers
look at vector by taby
// jyk from gamedev.net: // x,y,z are direction vector components float yaw = 0.0f; if(fabsf(dir_x) < 0.000001 && fabsf(dir_z) < 0.000001) // epsilon is some small number yaw = 0.0f; else yaw = atan2f(dir_x, dir_z); float pitch = -atan2f(dir_y, sqrt(dir_x*dir_x+dir_z*dir_z)); // division is a necessary (but not overused) evil static const float rad_to_deg_mul = 180.0f/3.14f; // * Convert to degrees here * glRotatef(yaw*rad_to_deg_mul, 0.0f, 1.0f, 0.0f); glRotatef(pitch*rad_to_deg_mul, 1.0f, 0.0f, 0.0f);