# cubic environment mapping coordinates

I’m having some trouble with cubic env mapping that one of you must have come upon before, so I wanted to make sure that there wasn’t a really easy solution before making major changes.

Here goes:

In OpenGL, the default thing is to be looking down the z axis onto the x-y plane. As a result, the x-y plane is sortof a natural choice for the “ground”.

To keep this example simple, let’s suppose the ground is an infinite x-y plane, the viewer is at (0,0), and he can look around using gluLookAt(). I want to apply a cubic reflection map to this plane.

When OpenGL figures out the reflection vectors for the cubic environment map, it assumes y is up (not z) and that you are using a left handed coordinate system (who does this?).

Anyway, this causes a problem. When I rotate around my z axis (to look around me), the reflection on the infinite plane stays static, as if I was only looking in one direction. This is obviously incorrect. Additionally, when I look up and down, the reflection DOES move, but in this case it shouldn’t.

I know that these problems come from the fact that my coordinate system is different from what opengl expects it to be in the cubic environment map.

My question is, how do I fix this? I tried using the texture matrix to rotate the texture 90 degrees around the x axis and then scale z by -1. I also tried flipping which pictures I put on which faces of the env map. In hindsight, these things couldn’t have worked, because opengl is simply not moving the reflection when I rotate around the z axis.

Is there a way to fix this problem without me going through all of my vertices, normals, and texture coordinates and flipping y->z, z->-z or something terribly expensive like that?

Sorry this post was so long, but I wanted to make sure the question was clear.

Thanks,
Zeno

Reflection and normal map texgen operate in eye coordinates – x is to the right, y is up, and z is forward.

When you’re environment-mapping, you will need to rotate your reflection vector from eye space into world space (or cubemap space) using the texture matrix.

• Matt

Duh…thanks Matt.

To translate what Matt said to something more concrete, do something like this:

Matrix m;
glGetFloatv(GL_MODELVIEW_MATRIX, m);
glMatrixMode(GL_TEXTURE);