简体   繁体   中英

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). 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).

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).

A reflection is not a singular projection (what you call 3D to 2D). A reflection is a scaling of -1, in your desired case the scaling is glScalef(1, -1, 1) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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