I’ve got a sphere in the middle of a skybox, and I’m using cubemapping to reflect the skybox on the sphere. Because the environment is static i don’t use dynamic cubemapping, instead I just create the cubemap once at startup to speed things up.
I was using glRotatef to spin around the sphere on the y axis, and to make the sphere reflect correctly I just performed the opposite rotation on the texture matrix. However now I want to use gluLookAt to fly all around the sphere and I’m having difficulty making the cubemapped sphere reflect properly. I think creating the cubemap dynamically will work, but this would definitely cause slowdown. Is there anyway to manipulate the texture matrix and avoid dynamic cubemap creation?
If the environment is not changing, you definitely don’t need to update the cube map. These functions (in glh_convenience.h) can be used to achieve the results you’re looking for. You need the texture matrix to be the inverse of the camera’s lookat.
// inverse of camera_lookat
inline matrix4f object_lookat(const vec3f & from, const vec3f & to, const vec3f & Up)
{
vec3f look = to - from;
look.normalize();
vec3f up(Up);
up -= look * look.dot(up);
up.normalize();
quaternionf r(vec3f(0,0,-1), vec3f(0,1,0), look, up);
matrix4f m;
r.get_value(m);
m.set_translate(from);
return m;