To keep it really simple, and since you’re just rotating around the y-axis, we can dispence with the matrices and do something like
x’ = x cos(angle) + z sin(angle);
y’ = y;
z’ = -x sin(angle) + z cos(angle);
This gives you a point rotated around the y-axis by some angle, centered about the world-space origin. If you want to locate the origin of rotation somewhere else, just add something to the rotated point, like an initial point (x0,y0,z0).
x’ = x0 + x cos(angle) + z sin(angle);
y’ = y0 + y;
z’ = z0 - x sin(angle) + z cos(angle);
This is the same result you’d get with the matrices. Here’s the equivalent matrix form, with the corresponding opengl calls in order:
glTranslatef(x0,y0,z0); glRotatef(angle,0,1,0); glVertex3f(x,y,z);
( x' ) ( 1 0 0 x0 ) ( cos(angle) 0 sin(angle) 0 ) ( x )
( y' ) ( 0 1 0 y0 ) ( 0 1 0 0 ) ( y )
( z' ) = ( 0 0 1 z0 ) (-sin(angle) 0 cos(angle) 0 ) ( z )
( 1 ) ( 0 0 0 1 ) ( 0 0 0 1 ) ( 1 ).
Same result, and a lot easier to work with
If you’d like some good reading on this stuff, google for “linear algebra”. And look at the redbook appendices. There you’ll find all the opengl transformation matrices and their inverses.
To get the distance between 2 spheres, take the distance between the sphere origins, then subtract the sum of the 2 radii from the result.
d = |origin1 - origin2| - radius1 - radius2.
If d == 0, the spheres touch; if d < 0, they intersect.