Cubemapping and gluLookAt()

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;

}

// inverse of object_lookat
inline matrix4f camera_lookat(const vec3f & eye, const vec3f & lookpoint, const vec3f & Up)
{
vec3f look = lookpoint - eye;
look.normalize();
vec3f up(Up);
up -= look * look.dot(up);
up.normalize();

matrix4f t;
t.set_translate(-eye);

quaternionf r(vec3f(0,0,-1), vec3f(0,1,0), look, up);
r.invert();
matrix4f rm;
r.get_value(rm);
return rm*t;	  

}

Thanks -
Cass

ahhh… was having the same problem. Thanks for solving it, Cass.

btw, are you Cass Everitt from nvidia?

Thanks alot, cass.
It’s late tongiht, I’ll try implementing it tomorrow

I’m glad that helped.

Dakeyras - yes, I’m Cass Everitt from NVIDIA.

Thanks -
Cass

Ah cool. Double thanks then, for providing glh to us needy souls =). BTW, is there any documentation available for glh?

Sorry - no documentation. I know that limits its usefulness to others.

Cass