My (NVIDIA) cube map is not looking right and I believe it is because I am rendering the six faces wrong.
If the reflector is at “reflector_center” thats how I move the camera to render each of the six faces
glFrustum(-0.1,0.1,-0.1,0.1,0.1,1000);
glRotatef(90,0,1,0);//left face
glRotatef(-90.0,0,1,0);//right face
glRotatef(-90.0,1.0,0,0);//top face
glRotatef(90.0,1.0,0,0);//bottom face
glRotatef(180,0,1,0);//back face
gluLookAt(reflector_center[0],reflector_center[1],reflector_center[2],eye[0],eye[1],eye[2],up[0],up[1],up[2]);
Does anybody see anything wrong with these?
Thanks
You may want to play with the signs on the rotates, I haven’t tried this and can never figure these things out without a little bit of experimentation. Also you may want to arrange these into single reads.
glFrustum(-0.1,0.1,-0.1,0.1,0.1,1000);
glPushMatrix();
glRotatef(90,0,1,0);//left face
//draw & read here
glPopMatrix();
glPushMatrix();
glRotatef(-90.0,0,1,0);//right face
//draw & read here
glPopMatrix();
glPushMatrix();
glRotatef(-90.0,1.0,0,0);//top face
//draw & read here
glPopMatrix();
glPushMatrix();
glRotatef(90.0,1.0,0,0);//bottom face
//draw & read here
glPopMatrix();
glPushMatrix();
glRotatef(180,0,1,0);//back face
//draw & read here
glPopMatrix();
Also you don’t need the lookat for a cubemap. You only need a translate if you get the reflection set up correctly, the eye should be translated to the reflecting object.
I have looked at past posts on dynamic cube map and noticed that if the viewpoint change I am supposed to change the texture matrix to get it right. Can anybody explain why is that needed? And what exactly must be that transformation?
Thanks
How can I have this turning out correctly when producing the six views of the cube map? I guess I have also to translate and rotate the camera, but since the camera is now at the position of the reflector I dont know how to do rotations.
You can ignore the glTranslate calls as they don’t affect the cube mapping.
You need to do the inverse of the “camera” rotations on your texture matrix because the generation of the texture coords is based on world(?) coords, not on the object coords.
Because you NEVER rotate the view point (ie. you apply the inverse rotation of your camera to your MODELVIEW matrix) the coords that are automatically generated will be aligned with the viewpoint. So as you rotate the “camera” it’ll appear that the reflection is stationary to the viewpoint while the object is rotating.
So just before you draw your object(s) you do a call like…
Sorry, you don’t do the inverse of your “camera” rotations on your texture matrix. You do the actual camera rotations (the inverse is applied to the object and the inverse of the inverse is applied to the texture - ie. the actual rotations).
Thanks. I tried it but it doesnt work (get some twisted cube map).
Let me post again what I am doing in the main display: I am rotating the camera about a given point through
gluLookAt(…);
//Then rotate camera
glTranslatef(-eye[0]+ctrans_xy[0],-eye[1]+ctrans_xy[1],-eye[2]+ctrans_z);
glMultMatrixf(rot_inverse); glTranslatef(eye[0]-ctrans_xy[0],eye[1]-ctrans_xy[1],eye[2]-ctrans_z);
render_scene;
and I would like this rotation to show up correctly in the environment map. I am generating the cube map dynamically (every frame) so I could as well apply a transformation at the time I am rendering the cube map. But what should that transformation be?
Thanks