使用 python 在 OpenGL 中仅渲染立方体内的一部分球体?

Render only a part of the sphere inside the cube in OpenGL using python?

我只想渲染它在立方体内部的部分,类似于图 2 中所示的部分

我当前渲染球体的代码在这里

def Sphere(ball):
    glPushMatrix()
    sphere = gluNewQuadric()
    glTranslatef(ball.pos.x,ball.pos.y,ball.pos.z) #Move to the place
    glColor3fv((1,0,0)) #Put color
    gluSphere(sphere, ball.radius, 16, 8) #Draw sphere
    glPopMatrix()

您可以使用 glClipPlane 定义剪辑窗格。例如:

glEnable(GL_CLIP_PLANE0)
glClipPlane(GL_CLIP_PLANE0, [1, 0, 0, distance])

glEnable(GL_CLIP_PLANE1)
glClipPlane(GL_CLIP_PLANE1, [0, 1, 0, distance])

# [...]

另见