简体   繁体   English

创建反射Opengl

[英]Creating a Reflection Opengl

I am attempting to reflect onto the XZ plane a rotating cube (so ultimately this is a 3D to 2D projection). 我试图将一个旋转的立方体反射到XZ平面上(所以最终这是3D到2D的投影)。 However, the points with which my cube is projected onto the XZ plane overlap, as expected due to the fact that the cube is 3D and there are points with the same X values, but different y values (2 points are projected onto the same point). 但是,将我的立方体投影到XZ平面上的点是重叠的,这是预期的,这是由于立方体是3D且存在具有相同X值但y值不同的点(将2个点投影到同一点上) )。

My question is, how can I project only the points on my cube that are visible to the plane I want to project onto? 我的问题是,我如何只投影立方体上要投影到的平面可见的点?

glLoadIdentity();

        glEnable(GL_DEPTH_TEST);
        glCullFace(GL_BACK);

        glTranslatef(0.0f, 0.0f, -5.0f);

        GLfloat matrix[16] = {1.0, 0.0, 0.0, 0.0, 
                              0.0, 0.0, 0.0, 0.0, 
                              0.0, 0.0, 1.0, 0.0, 
                              0.0, 0.0, 0.0, 1.0};

        glPushMatrix();
            glRotatef(angle, 1.0f, 1.0f, 1.0f);

            glBegin(GL_TRIANGLES);
                DrawCube();     
            glEnd();
        glPopMatrix();

        glPushMatrix();
            glTranslatef(0.0f, -1.0f, 0.0f);
            glMultMatrixf(matrix);
            glRotatef(angle, 1.0f, 1.0f, 1.0f);

            glBegin(GL_TRIANGLES);
                DrawCube();
            glEnd();
        glPopMatrix();

reflect onto the XZ plane a rotating cube (so ultimately this is a 3D to 2D projection). 将旋转的立方体反射到XZ平面上(因此最终这是3D到2D的投影)。

A reflection is not a singular projection (what you call 3D to 2D). 反射不是奇异的投影(您将3D称为2D)。 A reflection is a scaling of -1, in your desired case the scaling is glScalef(1, -1, 1) . 反射的缩放比例为-1,在您需要的情况下,缩放比例为glScalef(1, -1, 1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM