Итак, я пытаюсь узнать об основополагающем трехмерном моделировании в python, но я изо всех сил пытаюсь понять, как расположены вершины и ребра и что делают числа, которые я передаю. Вот пример:
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
"""
- A Cube has 8 Nodes/Verticies
- 12 Lines/connections
- 6 Sides
"""
vertices = (
(1, -1, -1),
(1, 1, -1),
(-1, 1, -1),
(-1, -1, -1),
(1, -1, 1),
(1, 1, 1),
(-1, -1, 1),
(-1, 1, 1)
)
edges = ( #Contains vertexes/nodes
(0, 1),
(0, 3),
(0, 4),
(2, 1),
(2, 3),
(2, 7),
(6, 3),
(6, 4),
(6, 7),
(5, 1),
(5, 4),
(5, 7)
)
def Cube():
glBegin(GL_LINES)
for edge in edges:
for vertex in edge:
glVertex3fv(vertices[vertex]) #Draws vertex's in position given according to vertices array
glEnd()
def main():
pygame.init()
display = (800, 600)
pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
gluPerspective(35, (display[0]/display[1]), 0.1, 50.0) #FOV, aspect ratio. clipping plane
glTranslatef(0.0, 0.0, -5) #X,Y,Z -5 to zoom out on z axis
glRotatef(20, 0, 0, 0) #Degrees, x,y,z
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
glRotatef(1, 3, 1, 1)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) #Clears the screen
Cube()
pygame.display.flip() #Cant use update
pygame.time.wait(10)
main()
pygame.quit()
quit()
Я сделал это после замечательного урока от sentdex Open GL и Python . Однако мне трудно понять, почему он вводит числа, которые он делает для вершин. Если бы кто-нибудь мог объяснить систему нумерации, это было бы очень важно! Спасибо!