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


dir to glRotate by taby
1
 

// 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)
    yaw = 0.0f;
else
    yaw = atan2f(dir_x, dir_z);

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

// to help convert radians to degrees
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);