Я пытаюсь отобразить сферу без использования функции gluSphere(). Но этот код не отображает ни одной сферы. Я не могу выяснить, где именно ошибка.
import sys
import math
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import pygame
user_theta = 0
user_height = 0
def draw(radius,lats,longs) :
for i in range(0,lats):
lat0 = math.pi*(-0.5 + (i-1)/lats)
z0 = math.sin(lat0)
zr0 = math.cos(lat0)
lat1 = math.pi*(-0.5 + i/lats)
z1 = math.sin(lat1)
zr1 = math.cos(lat1)
glColor3f(0.0,0.0,1.0)
glBegin(GL_QUAD_STRIP)
for j in range(0,longs):
lng = 2*math.pi*(j-1)/longs
x= math.cos(lng)
y = math.sin(lng)
glNormal3f(x * zr0, y * zr0, z0)
glVertex3f(x * zr0, y * zr0, z0)
glNormal3f(x * zr1, y * zr1, z1)
glVertex3f(x * zr1, y * zr1, z1)
glEnd()
glFlush()
def display() :
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glColor3f(1.0, 1.0, 1.0)
glShadeModel(GL_SMOOTH)
draw(1.0, 10, 10)
glutSwapBuffers()
def computeLocation():
x = 2 * math.cos(user_theta)
y = 2 * math.sin(user_theta)
z = user_height
d = math.sqrt(x * x + y * y + z * z)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
#glFrustum(-d * 0.5, d * 0.5, -d * 0.5, d * 0.5, d - 1.1, d + 1.1)
#gluLookAt(x, y, z, 0, 0, 0, 0, 0, 1)
gluOrtho2D(0.0, 640.0, 0.0, 480.0)
def init():
glClearColor(0.0, 0.0, 0.0, 0.0)
computeLocation()
glutInit(sys.argv)
glutInitDisplayMode (GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB)
glutInitWindowSize (500, 500)
glutInitWindowPosition (100, 100)
glutCreateWindow ('ROBOT')
init ()
glutDisplayFunc(display)
##glutReshapeFunc(reshape)
##glutKeyboardFunc(keyboard)
glutMainLoop()