I have a function in my program which rotates a point (x_p, y_p, z_p) around another point (x_m, y_m, z_m) by the angles w_nx and w_ny.
The new coordinates are stored in global variables x_n, y_n, and z_n. Rotation around the y-axis (so changing value of w_nx - so that the y - values are not harmed) is working correctly, but as soon as I do a rotation around the x- or z- axis (changing the value of w_ny) the coordinates aren't accurate any more. I commented on the line I think my fault is in, but I can't figure out what's wrong with that code.
void rotate(float x_m, float y_m, float z_m, float x_p, float y_p, float z_p, float w_nx ,float w_ny) { float z_b = z_p - z_m; float x_b = x_p - x_m; float y_b = y_p - y_m; float length_ = sqrt((z_b*z_b)+(x_b*x_b)+(y_b*y_b)); float w_bx = asin(z_b/sqrt((x_b*x_b)+(z_b*z_b))) + w_nx; float w_by = asin(x_b/sqrt((x_b*x_b)+(y_b*y_b))) + w_ny; //<- there must be that fault x_n = cos(w_bx)*sin(w_by)*length_+x_m; z_n = sin(w_bx)*sin(w_by)*length_+z_m; y_n = cos(w_by)*length_+y_m; }
glrotatef, but it only turns the drawing, not the coordinates of the vertexes, and i need to rotate the coordinates in order to check for collisions!