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:: Add Line Numbers


rotation code by taby
//!?

float yaw;

if(fabs(dir_x) < 0.000001 && fabs(dir_z) < 0.000001) // epsilon is some small number
    yaw = 0.0f;
else
    yaw = atan2(dir_x,dir_z);

float pitch = -atan2(dir_y,sqrt(dir_x*dir_x+dir_z*dir_z));

// * Convert to degrees here *
glRotatef(yaw*180.0f/3.14f, 0.0f, 1.0f, 0.0f);
glRotatef(pitch*180.0f/3.14f, 1.0f, 0.0f, 0.0f);