如何在地形下移动相机进行反射?

时间:2015-11-19 15:30:49

标签: java opengl camera lwjgl

我试图渲染一些水的反射。

为了创造反射的幻觉,我需要将相机放在水下: enter image description here enter image description here (图片不是我画的)

因此,我需要在渲染场景之前将相机移到水下。我需要将相机向下移动相机到水面的距离乘以2,然后我需要反转相机的间距。

问题是我目前仅限于使用固定功能管道执行此操作,这意味着我必须使用glTranslatef()和glRotatef()调用来执行此操作。

这是我目前的实施:

public void createReflectionTexture(){
    EulerCamera c = Main.TerrainDemo.camera; //This is the camera
    float amtDown = -(2f * (c.y() - 300)); //Amount to move the camera down by. 300 is the height of the water.
    float amtPit = (-(c.pitch() * 2));//Pitch to invert the camera by
    glRotatef(-amtPit, 0, 0, 1); //I have tried both negative and positive values here, neither seem to work.
    glTranslatef(0, amtDown, 0);
    bindArrays();
    fbos.bindReflectionFrameBuffer();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    Main.TerrainDemo.renderVBOTerrain();
    fbos.unbindCurrentFrameBuffer();
    unBindArrays();
    glTranslatef(0, -amtDown, 0); /This puts things back to their original translation so I can keep on rendering other objects.
    glRotatef(amtPit, 0, 0, 1);
}

不幸的是,在我的游戏中,代码会创建一个完全混乱的图像,这显然不是正确的反映: enter image description here

如果我将飞机撞到水中然后将摄像机的音高调到0,它似乎会渲染出正确的物体。

折射纹理渲染完美。

如何正确地将相机移到水下以创建一个从上方看时看起来像反射的场景?

0 个答案:

没有答案