使用pyopengl,我試圖創建一個圓柱體。圓柱體的頂部不是圓形的,而底部如下面鏈接的圖像所示。我想知道如何解決這個問題,如果它的方式,我已經編碼或只是我做的方式不適用於pyopengl。我正在使用Pygame 1.9.2,Python 3.5和PyOpenGL-3.1.0。pyopengl - 創建一個沒有使用gluCylinder函數的圓柱體
https://i.stack.imgur.com/KYPLY.jpg
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
def securityCamera(radius,halflength,slices):
glBegin(GL_TRIANGLES)
for i in range(1,slices+1):
angleSize=(2*math.pi)/slices
theta=i*angleSize
nextTheta=(i+1)*angleSize
glColor3fv((0/256,0/256,0/256))
glVertex3f(radius*math.cos(nextTheta), halflength, radius*math.cos(nextTheta))
glVertex3f(radius*math.cos(theta), halflength, radius*math.sin(theta))
glVertex3f(0.0, halflength, 0.0)
glVertex3f(radius*math.cos(nextTheta), -halflength, radius*math.sin(nextTheta))
glVertex3f(radius*math.cos(theta), -halflength, radius*math.sin(theta))
glVertex3f(0.0, -halflength, 0.0)
glEnd()
glBegin(GL_QUADS)
for i in range(1,slices+1):
angleSize=(2*math.pi)/slices
theta=i*angleSize
nextTheta=(i+1)*angleSize
glColor3fv((256/256,256/256,256/256))
glVertex3f(radius*math.cos(theta), halflength, radius*math.sin(theta))
glVertex3f(radius*math.cos(nextTheta), halflength, radius*math.cos(nextTheta))
glVertex3f(radius*math.cos(theta), -halflength, radius*math.sin(theta))
glVertex3f(radius*math.cos(nextTheta), -halflength, radius*math.sin(nextTheta))
glEnd()