Close range 3d display messed up

前端 未结 1 817
灰色年华
灰色年华 2021-01-25 18:44

I copied a code of YouTube, about displaying 3d cubes on a screen in Python, without the use of external modules (like PyOpenGL). It works fine, but the moment you go between tw

1条回答
  •  暖寄归人
    2021-01-25 19:23

    The application does not correctly draw the geometry, when apart of a faces (primitive, side of a cube) is behind and the other part in front of the eye position. That happens if the transformed z coordinate (vert_list += [(x,y,z)]) is positive for the some vertices and negative for negative for some other vertices that form primitive (face).

    You can test that behavior with ease, if you skip all the faces, where at least one z coordinate is negative (behind the eye):

    while True:
        # [...]
    
        for obj in objects:
            # [...]
    
            for f in range(len(obj.faces)):
                face = obj.faces[f]
    
                #on_screen = False
                #for i in face:
                #    x,y = screen_coords[i]
                #    if vert_list[i][2]>0 and x>0 and x0 and y0 and x0 and y0 for i in face])
    
                if on_screen:
                    # [...]
    


    The issue can be solved by clipping the geometry at hypothetical near plane. See Viewing frustum:

    while True:
        # [...]
    
        for obj in objects:
            # [...]
    
            for f in range(len(obj.faces)):
                face = obj.faces[f]
    
                on_screen = False
                for i in face:
                    x,y = screen_coords[i]
                    if vert_list[i][2]>0 and x>0 and x0 and y

    0 讨论(0)
提交回复
热议问题