Skip to main content
gamedev.net
🔒 Locked

Rotating Cube Maps

Started by JonW 2 replies 450+ views
Original Post
JonW
JonW
Hi, I''m using cube mapping to reflect the skybox on a water surface. It works OK, but the reflection rotates with the camera, so if there is a mountain behind the camera it will reflect in the water in front of the player, but if the camera rotates 90 degrees to the left, the mountain will still be reflected in front of it, instead of to the right of it. Here is my code:
//use cube environment mapping 
glPushMatrix();

	sky->getCubemap()->Bind();

	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);
	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);
	glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);

	glMatrixMode(GL_TEXTURE);
	glPushMatrix();

		glEnable(GL_TEXTURE_CUBE_MAP_EXT);
		glEnable(GL_TEXTURE_GEN_S);
		glEnable(GL_TEXTURE_GEN_T);
		glEnable(GL_TEXTURE_GEN_R);
		glEnable(GL_NORMALIZE);

		drawHeightmap();

	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);

glPopMatrix();
 
I believe I need to be rotating the texture matrix by the camera''s current rotation (I am using gluLookAt, so I''m not sure how to do this) after the second call to glPushMatrix. Its just a guess though. Any ideas? The water heightmap is rotating properly, its just the skybox reflection that won''t move. Thanks!
JonW
JonW
Thanks!

How can I find the camera''s rotation if I am using gluLookAt? Maybe I have to pry it out of the modelview matrix?
JonW
JonW
Nevermind. I figured it out:


GLfloat M[16];
GLfloat T[16];
glMatrixMode(GL_TEXTURE);
glGetFloatv( GL_TEXTURE_MATRIX, T );
glMatrixMode(GL_MODELVIEW);
glGetFloatv( GL_MODELVIEW_MATRIX, M );

GLfloat U[3][3];
GLfloat UInverse[3][3];

U[0][0] = M[0];
U[1][0] = M[1];
U[2][0] = M[2];
U[0][1] = M[4];
U[1][1] = M[5];
U[2][1] = M[6];
U[0][2] = M[8];
U[1][2] = M[9];
U[2][2] = M[10];

InvertMatrix(U, UInverse);

T[0] = UInverse[0][0];
T[1] = UInverse[1][0];
T[2] = UInverse[2][0];
T[4] = UInverse[0][1];
T[5] = UInverse[1][1];
T[6] = UInverse[2][1];
T[8] = UInverse[0][2];
T[9] = UInverse[1][2];
T[10] = UInverse[2][2];

glMatrixMode(GL_TEXTURE);

glLoadMatrixf( T );

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.