Witam.
Piszę sobie kod rysujący różne figury przestrzenne. Teraz jestem na kostce. To kod:
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
class Cube():
def __init__(self):
self.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),
)
self.edges = (
(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 draw(self):
glBegin(GL_LINES)
for edge in self.edges:
for vertex in edge:
glVertex3fv(self.vertices[vertex])
glEnd()
def main():
pygame.init()
display = (1280, 720)
pygame.display.set_mode(display, DOUBLEBUF | OPENGL)
gluPerspective(45, (display[0]/display[1]), 0.1, 50)
glTranslatef(0, 0, -5)
glRotatef(0, 0, 0, 0)
cube1 = Cube
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == MOUSEBUTTONDOWN:
if event.button == 4:
glTranslatef(0, 0, 1)
if event.button == 5:
glTranslatef(0, 0, -1)
keystate = pygame.key.get_pressed()
if keystate[K_LEFT]:
glRotatef(5, 0, 5, 0)
if keystate[K_RIGHT]:
glRotatef(-5, 0, 5, 0)
if keystate[K_UP]:
glRotatef(5, 5, 0, 0)
if keystate[K_DOWN]:
glRotatef(-5, 5, 0, 0)
cube1.draw()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
pygame.display.flip()
pygame.time.wait(10)
main()
A to błąd:
Traceback (most recent call last):
File "[UTAJNIONO]", line 86, in <module>
main()
File "[UTAJNIONO]", line 81, in main
cube1.draw()
TypeError: draw() missing 1 required positional argument: 'self'
Process finished with exit code 1