Displaying my cubemaps in world space, rather than eye

Sage
Posts: 1,199
Joined: 2004.10
Post: #1
This might be hard to describe eloquently, but here goes:

My cubemaps appear to be displayed in eye space. E.g., the cubemaps display as if the cube were always following the rotation of the camera. An example -- I'll cook up some screenshots if anybody wants -- would be if you had a cubemap with blue sky and green ground. You position the camera level with the sphere, looking horizontally, and you see blue on top and green on bottom. That's great.

But, then you position the camera *over* the sphere, and look straight down. I'm seeing blue on top, green on bottom again. Which is wrong, since I'd expect to see blue only, since blue's on top of the cubemap and I should be seeing that reflected. This is why I think the cubemap is being calculated in eye space, as opposed to world.

What I'm assuming is that I need to swizzle the texture matrix to get the cubemap to be calculate in world space as opposed to eye. My... guess... would be to take the rotational component of my camera's modelview matrix, invert it, and assign that to the texture matrix.

Is this the right way?

Thanks,
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #2
Turns out, that's exactly what I needed to do.

Code:
glMatrixMode( GL_TEXTURE );
glLoadMatrixf( world()->activeCamera()->modelview().rotation().inverse().mat );
glMatrixMode( GL_MODELVIEW );

Voila.

See, all the cubemap demos I'd looked over were of the simple "here's a cubemapped teapot", with a fixed camera. The mouse just rotated the teapot. I read over an NVIDIA article on cobemaps from '99 and it described how you could convert to world space in the texture matrix.
Quote this message in a reply
Post Reply