Void-voiD

Untitled

May 30th, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 19.85 KB | None | 0 0
  1. from math import sqrt, pi, cos, sin
  2. from mathutils import Matrix
  3. from pyglet import image
  4. from pyglet.gl import *
  5. from pyglet.window import key
  6. from pyglet.window import mouse
  7. from OpenGL.GLUT import *
  8. from numpy import array, cross
  9. import json
  10. import glfw
  11.  
  12.  
  13. window = pyglet.window.Window(1400, 1400, resizable = True, vsync = 0)
  14. window.set_minimum_size(144, 144)
  15. gl.glClearColor(0, 0.6, 0.8, 1)
  16. glutInit()
  17.  
  18. Width = 1000
  19. Height = 1000
  20. ratio = 1
  21. pos = array([0.0, 0.0, 0.0])
  22. rot = [0, 0, 0]
  23. isFramedMode = False
  24. Horizontal = 25
  25. Vertical = 25
  26. Points = [[array([0.0, 0.0, 0.0]) for i in range(Vertical)] for j in range(Horizontal)]
  27. heightOfParaboloid = 1
  28. P = 0.25
  29. Q = 0.5
  30. Changed = False
  31. border = array([[-0.4, -0.4, -0.4], [1.1, 1.1, 1.1]])
  32. figure = array([[-0.2, -sqrt(0.5) / 5.0, 0.4], [0.2, sqrt(0.5) / 5.0, 0.6]])
  33.  
  34. chess = image.load("wood5.bmp")
  35. texture = chess.get_texture()
  36.  
  37. ambient_color = (GLfloat * 4)()
  38. local_viewer = (GLfloat * 3)()
  39. two_side = (GLfloat * 1)()
  40. speed, vector, coordx, coordy, coordz, is_infinity_light, face, is_local, is_animated, is_lighted, is_textured, is_material = None, None, None, None, None, None, None, None, None, None, None, None
  41. ambient, diffuse, specular, shininess, emission = (GLfloat * 4)(), (GLfloat * 4)(), (GLfloat * 4)(), 0, (GLfloat * 4)()
  42. ids = glGenLists(1)
  43. is_started = 0
  44. to_draw = []
  45.  
  46.  
  47. def load():
  48.     with open('data.txt') as json_file:
  49.         global speed, vector, coordx, coordy, coordz, is_infinity_light, face, pname, ambient_color, local_viewer, two_side, parameters, is_local, is_animated, is_lighted, is_textured
  50.         global ambient, diffuse, specular, shininess, emission, is_material
  51.         result = json.load(json_file)
  52.         is_textured = result['is_textured']
  53.         is_lighted = result['is_lighted']
  54.         is_animated = result['is_animated']
  55.         speed = result['speed']
  56.         vector = array([speed, speed, speed])
  57.         coordx, coordy, coordz, is_infinity_light = result['light1'][0]['coordx'], result['light1'][0]['coordy'], \
  58.                                                     result['light1'][0]['coordz'], result['light1'][0][
  59.                                                         'is_infinity_light']
  60.         ambient_color[0], ambient_color[1], ambient_color[2], ambient_color[3] = result['light3'][0]["ambient_color"][
  61.                                                                                      0], \
  62.                                                                                  result['light3'][0]["ambient_color"][
  63.                                                                                      1], \
  64.                                                                                  result['light3'][0]["ambient_color"][
  65.                                                                                      2], \
  66.                                                                                  result['light3'][0]["ambient_color"][3]
  67.         is_local = result['light4'][0]["is_local"]
  68.         local_viewer[0], local_viewer[1], local_viewer[2] = result['light4'][0]["local_viewer"][0], \
  69.                                                             result['light4'][0]["local_viewer"][1], \
  70.                                                             result['light4'][0]["local_viewer"][2]
  71.         two_side[0] = result["light5"][0]["two_side"]
  72.         face = result["light6"][0]['face']
  73.         ambient[0], ambient[1], ambient[2], ambient[3] = result["ambient"][0], result["ambient"][1], result["ambient"][2], result["ambient"][3]
  74.         diffuse[0], diffuse[1], diffuse[2], diffuse[3] = result["diffuse"][0], result["diffuse"][1], result["diffuse"][2], result["diffuse"][3]
  75.         specular[0], specular[1], specular[2], specular[3] = result["specular"][0], result["specular"][1], result["specular"][2], result["specular"][3]
  76.         shininess = result["shininess"]
  77.         emission[0], emission[1], emission[2], emission[3] = result["emission"][0], result["emission"][1], result["emission"][2], result["emission"][3]
  78.         is_material = result["is_material"]
  79.  
  80.  
  81. def save():
  82.     global speed, coordx, coordy, coordz, is_infinity_light, face, pname, ambient_color, local_viewer, two_side, parameters, is_local, is_animated, is_lighted, is_textured
  83.     global ambient, diffuse, specular, shininess, emission, is_material
  84.     data = {}
  85.  
  86.     data["is_textured"] = is_textured
  87.     data['is_lighted'] = is_lighted
  88.     data['is_animated'] = is_animated
  89.     data['speed'] = speed
  90.     data['light1'] = []
  91.     data['light1'].append({
  92.         'coordx': coordx,
  93.         'coordy': coordy,
  94.         'coordz': coordz,
  95.         'is_infinity_light': is_infinity_light
  96.     })
  97.     data['light3'] = []
  98.     data['light3'].append({
  99.         'ambient_color': [ambient_color[0], ambient_color[1], ambient_color[2], ambient_color[3]]
  100.     })
  101.     data['light4'] = []
  102.     data['light4'].append({
  103.         'is_local': is_local,
  104.         'local_viewer': [local_viewer[0], local_viewer[1], local_viewer[2]]
  105.     })
  106.     data['light5'] = []
  107.     data['light5'].append({
  108.         'two_side': two_side[0]
  109.     })
  110.     data['light6'] = []
  111.     data['light6'].append({
  112.         'face': face,
  113.     })
  114.     data["ambient"] = [] * 4
  115.     data["ambient"][0], data["ambient"][1], data["ambient"][2], data["ambient"][3] = ambient[0], ambient[1], ambient[2], ambient[3]
  116.     data["diffuse"] = [] * 4
  117.     data["diffuse"][0], data["diffuse"][1], data["diffuse"][2], data["diffuse"][3] = diffuse[0], diffuse[1], diffuse[2], diffuse[3]
  118.     data["specular"] = [] * 4
  119.     data["specular"][0], data["specular"][1], data["specular"][2], data["specular"][3] = specular[0], specular[1], specular[2], specular[3]
  120.     data["shininess"] = shininess
  121.     data["emission"] = [] * 4
  122.     data["emission"][0], data["emission"][1], data["emission"][2], data["emission"][3] = emission[0], emission[1], emission[2], emission[3]
  123.     data["is_material"] = is_material
  124.     with open('data.txt', 'w') as outfile:
  125.         json.dump(data, outfile)
  126.  
  127.  
  128. load()
  129.  
  130.  
  131. def which(first, second, third, fourth):
  132.     glBegin(GL_LINE_LOOP)
  133.     glVertex3f(*first)
  134.     glVertex3f(*second)
  135.     glVertex3f(*third)
  136.     glVertex3f(*fourth)
  137.     glEnd()
  138.  
  139.  
  140. def baseCube():
  141.     lbf = [-0.5, -0.5, -0.5]
  142.     rbf = [0.5, -0.5, -0.5]
  143.     rtf = [0.5, 0.5, -0.5]
  144.     ltf = [-0.5, 0.5, -0.5]
  145.  
  146.     lbn = [-0.5, -0.5, 0.5]
  147.     rbn = [0.5, -0.5, 0.5]
  148.     rtn = [0.5, 0.5, 0.5]
  149.     ltn = [-0.5, 0.5, 0.5]
  150.  
  151.     # BOTTOM
  152.     which(lbn, rbn, rbf, lbf)
  153.  
  154.     # BACK
  155.     which(lbf, rbf, rtf, ltf)
  156.  
  157.     # LEFT
  158.     which(ltf, ltn, lbn, lbf)
  159.  
  160.     # RIGHT
  161.     which(rtn, rtf, rbf, rbn)
  162.  
  163.     # TOP
  164.     which(ltn, ltf, rtf, rtn)
  165.  
  166.     # FRONT
  167.     which(lbn, ltn, rtn, rbn)
  168.  
  169.  
  170. def sectorOfParaboloid(framed, i, j, top):
  171.     global heightOfParaboloid, Vertical, Horizontal, Points, position, to_draw
  172.  
  173.     # if framed:
  174.     #     glBegin(GL_LINE_LOOP)
  175.     # else:
  176.     #     glBegin(GL_POLYGON)
  177.     #     glColor3f(1, 1, 1)
  178.  
  179.     a = None
  180.     b = None
  181.     c = None
  182.     d = None
  183.  
  184.     if not top:
  185.         a = Points[i][j]
  186.         if j + 1 == Vertical:
  187.             b = Points[i][0]
  188.         else:
  189.             b = Points[i][j + 1]
  190.         if i == 0:
  191.             c = array([0, 0, 0])
  192.             d = array([0, 0, 0])
  193.         else:
  194.             if j + 1 == Vertical:
  195.                 c = Points[i - 1][0]
  196.             else:
  197.                 c = Points[i - 1][j + 1]
  198.             d = Points[i - 1][j]
  199.     else:
  200.         a = Points[i][j]
  201.         a[1] = heightOfParaboloid
  202.         if i == 0:
  203.             b = array([0, 0, 0])
  204.             c = array([0, 0, 0])
  205.             b[1] = heightOfParaboloid
  206.             c[1] = heightOfParaboloid
  207.         else:
  208.             b = Points[i - 1][j]
  209.             b[1] = heightOfParaboloid
  210.             if j + 1 == Vertical:
  211.                 c = Points[i - 1][0]
  212.                 c[1] = heightOfParaboloid
  213.             else:
  214.                 c = Points[i - 1][j + 1]
  215.                 c[1] = heightOfParaboloid
  216.         if j + 1 == Vertical:
  217.             d = Points[i][0]
  218.             d[1] = heightOfParaboloid
  219.         else:
  220.             d = Points[i][j + 1]
  221.             d[1] = heightOfParaboloid
  222.  
  223.     normal = cross(c - a, d - b)
  224.     x = normal[0] ** 2 + normal[1] ** 2 + normal[2] ** 2
  225.     if x != 1:
  226.         length = sqrt(x) * 1.0
  227.         if length > 0:
  228.             normal[0] /= length
  229.             normal[1] /= length
  230.             normal[2] /= length
  231.  
  232.     to_draw.extend([i * 1.0 / Horizontal, j * 1.0 / Vertical])
  233.     to_draw.extend(normal)
  234.     to_draw.extend(a)
  235.     if not top:
  236.         to_draw.extend([i * 1.0 / Horizontal, (j + 1 % Vertical) * 1.0 / Vertical])
  237.         to_draw.extend(normal)
  238.         to_draw.extend(b)
  239.         if i == 0:
  240.             to_draw.extend([0, 0])
  241.             to_draw.extend(normal)
  242.             to_draw.extend(c)
  243.             to_draw.extend([0, 0])
  244.             to_draw.extend(normal)
  245.             to_draw.extend(d)
  246.         else:
  247.             to_draw.extend([(i - 1) * 1.0 / Horizontal, (j + 1 % Vertical) * 1.0 / Vertical])
  248.             to_draw.extend(normal)
  249.             to_draw.extend(c)
  250.             to_draw.extend([(i - 1) * 1.0 / Horizontal, j * 1.0 / Vertical])
  251.             to_draw.extend(normal)
  252.             to_draw.extend(d)
  253.     else:
  254.         if i == 0:
  255.             to_draw.extend([0, 0])
  256.             to_draw.extend(normal)
  257.             to_draw.extend(b)
  258.             to_draw.extend([0, 0])
  259.             to_draw.extend(normal)
  260.             to_draw.extend(c)
  261.         else:
  262.             to_draw.extend([(i - 1) * 1.0 / Horizontal, j * 1.0 / Vertical])
  263.             to_draw.extend(normal)
  264.             to_draw.extend(b)
  265.             to_draw.extend([(i - 1) * 1.0 / Horizontal, (j + 1 % Vertical) * 1.0 / Vertical])
  266.             to_draw.extend(normal)
  267.             to_draw.extend(c)
  268.         to_draw.extend([i * 1.0 / Horizontal, (j + 1 % Vertical) * 1.0 / Vertical])
  269.         to_draw.extend(normal)
  270.         to_draw.extend(d)
  271.        
  272.  
  273.     # glNormal3f(*normal)
  274.     #
  275.     # glTexCoord2f(i * 1.0 / Horizontal, j * 1.0 / Vertical)
  276.     # glVertex3f(*a)
  277.     # if not top:
  278.     #     glTexCoord2f(i * 1.0 / Horizontal, (j + 1 % Vertical) * 1.0 / Vertical)
  279.     #     glVertex3f(*b)
  280.     #     if i == 0:
  281.     #         glTexCoord2f(0, 0)
  282.     #         glVertex3f(*c)
  283.     #     else:
  284.     #         glTexCoord2f((i - 1) * 1.0 / Horizontal, (j + 1 % Vertical) * 1.0 / Vertical)
  285.     #         glVertex3f(*c)
  286.     #         glTexCoord2f((i - 1) * 1.0 / Horizontal, j * 1.0 / Vertical)
  287.     #         glVertex3f(*d)
  288.     # else:
  289.     #     if i == 0:
  290.     #         glTexCoord2f(0, 0)
  291.     #         glVertex3f(*b)
  292.     #     else:
  293.     #         glTexCoord2f((i - 1) * 1.0 / Horizontal, j * 1.0 / Vertical)
  294.     #         glVertex3f(*b)
  295.     #
  296.     #         glTexCoord2f((i - 1) * 1.0 / Horizontal, (j + 1 % Vertical) * 1.0 / Vertical)
  297.     #         glVertex3f(*c)
  298.     #     glTexCoord2f(i * 1.0 / Horizontal, (j + 1 % Vertical) * 1.0 / Vertical)
  299.     #     glVertex3f(*d)
  300.  
  301.     # glEnd()
  302.  
  303.  
  304. def EllepticalParaboloid(framed):
  305.     global Points, Horizontal, Vertical, heightOfParaboloid
  306.     for i in range(Horizontal):
  307.         for j in range(Vertical):
  308.             sectorOfParaboloid(framed, i, j, False)
  309.  
  310.     for i in range(Horizontal):
  311.         for j in range(Vertical):
  312.             sectorOfParaboloid(framed, i, j, True)
  313.  
  314.  
  315. def resetPoints(dt):
  316.     global Points, P, Q, Vertical, Horizontal, heightOfParaboloid, vector, pos, border, figure, is_animated
  317.     Points = [[array([0.0, 0.0, 0.0]) for i in range(Vertical)] for j in range(Horizontal)]
  318.     stepy = float(heightOfParaboloid) / Horizontal
  319.     anglexz = 2 * pi / Vertical
  320.     curangle = 0
  321.     h = 0.0
  322.  
  323.     for i in range(Horizontal):
  324.         h += stepy
  325.         for j in range(Vertical):
  326.             Points[i][j][0] = sqrt(2 * Q * h) * cos(curangle)
  327.             Points[i][j][1] = h
  328.             Points[i][j][2] = sqrt(2 * P * h) * sin(curangle)
  329.             curangle += anglexz
  330.  
  331.     if is_animated:
  332.         if figure[0][0] > border[0][0] and figure[0][1] > border[0][1] and figure[0][2] > border[0][2] and figure[1][0] < border[1][0] and figure[1][1] < border[1][1] and figure[1][2] < border[1][2]:
  333.             pos += vector
  334.             figure += vector
  335.         else:
  336.             # print("-------\n", figure, "\n---\n", border, "\n---\n", vector, "\n-------")
  337.             if figure[0][0] < border[0][0] or figure[1][0] > border[1][0]:
  338.                 vector[0] *= -1
  339.             if figure[0][1] < border[0][1] or figure[1][1] > border[1][1]:
  340.                 vector[1] *= -1
  341.             if figure[0][2] < border[0][2] or figure[1][2] > border[1][2]:
  342.                 vector[2] *= -1
  343.             pos += vector
  344.             figure += vector
  345.  
  346.  
  347. @window.event
  348. def on_draw():
  349.     global Width, Height
  350.     global ratio
  351.     global isFramedMode, Changed
  352.     global Horizontal, Vertical, heightOfParaboloid, P, Q
  353.     global texture, chess
  354.     global coordx, coordy, coordz, is_infinity_light, ambient_color, local_viewer, two_side, face, is_local, is_lighted, is_textured
  355.     global ambient, diffuse, specular, shininess, emission, is_material
  356.     global ids, is_started, to_draw
  357.     window.clear()
  358.     if not is_started:
  359.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
  360.         glEnable(GL_DEPTH_TEST)
  361.  
  362.         if not is_textured:
  363.             glDisable(GL_TEXTURE_2D)
  364.  
  365.         if is_textured:
  366.             glEnable(texture.target)
  367.             glBindTexture(texture.target, texture.id)
  368.             glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, chess.width, chess.height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
  369.                          chess.get_data())
  370.             glEnable(GL_TEXTURE_2D)
  371.             glEnable(GL_NORMALIZE)
  372.  
  373.         if not is_lighted:
  374.             glDisable(GL_LIGHTING)
  375.  
  376.         if is_lighted:
  377.             glEnable(GL_LIGHTING)
  378.             glEnable(GL_LIGHT0)
  379.             if not is_material:
  380.                 glEnable(GL_COLOR_MATERIAL)
  381.             else:
  382.                 glDisable(GL_COLOR_MATERIAL)
  383.             glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
  384.             glLightiv(GL_LIGHT0, GL_POSITION, (GLint * 4)(coordx, coordy, coordz, is_infinity_light))
  385.  
  386.             glLightfv(GL_LIGHT0, GL_AMBIENT, (GLfloat * 4)(0, 0, 0, 1))
  387.             glLightfv(GL_LIGHT0, GL_DIFFUSE, (GLfloat * 4)(0.2, 0.2, 0.2, 1))
  388.             glLightfv(GL_LIGHT0, GL_SPECULAR, (GLfloat * 4)(0.2, 0.2, 0.2, 1))
  389.  
  390.             glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient_color)
  391.             if is_local:
  392.                 glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_viewer)
  393.             glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, two_side)
  394.  
  395.             if is_material:
  396.                 glMaterialfv(face, GL_AMBIENT, ambient)
  397.                 glMaterialfv(face, GL_DIFFUSE, diffuse)
  398.                 glMaterialfv(face, GL_SPECULAR, specular)
  399.                 glMaterialfv(face, GL_SHININESS, (GLfloat * 1)(shininess))
  400.                 glMaterialfv(face, GL_EMISSION, emission)
  401.             glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
  402.  
  403.         # ------------------------------------------------------------
  404.  
  405.         cx = 3
  406.         cy = 3
  407.         cz = 3
  408.  
  409.         p = float(-1) / float(cx)
  410.         q = float(-1) / float(cy)
  411.         r = float(-1) / float(cz)
  412.  
  413.         matrixShift = Matrix([(1, 0, 0, 0),
  414.                               (0, 1, 0, 0),
  415.                               (0, 0, 1, 0),
  416.                               (0.175, 0.175, 0.175, 1)])
  417.         matrixRatio = Matrix([(1 / ratio, 0, 0, 0),
  418.                               (0, 1, 0, 0),
  419.                               (0, 0, 1, 0),
  420.                               (0, 0, 0, 1)])
  421.         matrixPerspective = Matrix([(1, 0, 0, p),
  422.                                     (0, 1, 0, q),
  423.                                     (0, 1, 0, r),
  424.                                     (0, 0, 0, 1)])
  425.         matrixProjection = Matrix([(1, 0, 0, 0),
  426.                                    (0, 1, 0, 0),
  427.                                    (0, 0, 0, 0),
  428.                                    (0, 0, 0, 1)])
  429.         matrixFinal = matrixProjection @ matrixPerspective @ matrixShift @ matrixRatio
  430.         Matrix.transpose(matrixFinal)
  431.  
  432.         glMatrixMode(GL_PROJECTION)
  433.         value = (GLfloat * 16)()
  434.         for i in range(4):
  435.             for j in range(4):
  436.                 value[i * 4 + j] = matrixFinal[i][j]
  437.         glLoadMatrixf(value)
  438.  
  439.         EllepticalParaboloid(isFramedMode)
  440.  
  441.         glMatrixMode(GL_MODELVIEW)
  442.         glEnable(GL_CULL_FACE)
  443.         glFrontFace(GL_CW)
  444.  
  445.         glLoadIdentity()
  446.         glPushMatrix()
  447.         glScaled(0.2, 0.2, 0.2)
  448.         glTranslated(*pos)
  449.         glRotatef(rot[0], 1, 0, 0)
  450.         glRotatef(rot[1], 0, 1, 0)
  451.         glRotatef(rot[2], 0, 0, 1)
  452.  
  453.         glInterleavedArrays(GL_T2F_N3F_V3F, 0, (GLfloat * len(to_draw))(*to_draw))
  454.         glDrawArrays(GL_QUADS, 0, int(len(to_draw) / 12))
  455.         is_started = True
  456.     if is_started:
  457.         glDrawArrays(GL_QUADS, 0, int(len(to_draw) / 12))
  458.  
  459.     glMatrixMode(GL_MODELVIEW)
  460.  
  461.     glEnable(GL_CULL_FACE)
  462.     glFrontFace(GL_CW)
  463.  
  464.     glLoadIdentity()
  465.     glPushMatrix()
  466.     glScaled(1.5, 1.5, 1.5)
  467.     glTranslated(0.35, 0.35, 0.35)
  468.     glRotatef(30, 1, 0, 0)
  469.     glRotatef(-30, 0, 1, 0)
  470.     glRotatef(0, 0, 0, 1)
  471.     baseCube()
  472.     glPopMatrix()
  473.  
  474.  
  475. @window.event
  476. def on_resize(width, height):
  477.     global ratio
  478.     glViewport(0, 0, width, height)
  479.     ratio = width / height
  480.     resetPoints(0)
  481.  
  482.  
  483. @window.event
  484. def on_mouse_press(x, y, button, modifiers):
  485.     global isFramedMode
  486.     if button == mouse.LEFT:
  487.         isFramedMode = not isFramedMode
  488.     resetPoints(0)
  489.  
  490.  
  491. @window.event
  492. def on_key_press(symbol, modifiers):
  493.     global pos, rot, Horizontal, Vertical, Changed
  494.     global speed, vector, is_infinity_light, two_side, face, is_local, is_animated, is_lighted, is_textured, is_material
  495.     if symbol == key.S:
  496.         pos[1] -= 0.05
  497.     elif symbol == key.W:
  498.         pos[1] += 0.05
  499.     elif symbol == key.D:
  500.         pos[0] += 0.05
  501.     elif symbol == key.A:
  502.         pos[0] -= 0.05
  503.     elif symbol == key.UP:
  504.         pos[2] += 0.05
  505.     elif symbol == key.DOWN:
  506.         pos[2] -= 0.05
  507.  
  508.     elif symbol == key.Z:
  509.         rot[0] -= 5
  510.     elif symbol == key.X:
  511.         rot[0] += 5
  512.     elif symbol == key.C:
  513.         rot[1] -= 5
  514.     elif symbol == key.V:
  515.         rot[1] += 5
  516.     elif symbol == key.B:
  517.         rot[2] -= 5
  518.     elif symbol == key.N:
  519.         rot[2] += 5
  520.  
  521.     elif symbol == key.O:
  522.         Horizontal -= 1
  523.     elif symbol == key.P:
  524.         Horizontal += 1
  525.     elif symbol == key.K:
  526.         Vertical -= 1
  527.     elif symbol == key.L:
  528.         Vertical += 1
  529.  
  530.     elif symbol == key.Q:
  531.         save()
  532.     elif symbol == key.E:
  533.         load()
  534.  
  535.     elif symbol == key.R:
  536.         is_material = not is_material
  537.     elif symbol == key.T:
  538.         is_infinity_light = not is_infinity_light
  539.     elif symbol == key.U:
  540.         if two_side[0] == 0:
  541.             two_side[0] = 1
  542.         elif two_side[0] == 1:
  543.             two_side[0] = 0
  544.     elif symbol == key.I:
  545.         if face == GL_FRONT_AND_BACK:
  546.             face = GL_FRONT
  547.         elif face == GL_FRONT:
  548.             face = GL_BACK
  549.         elif face == GL_BACK:
  550.             face = GL_FRONT_AND_BACK
  551.     elif symbol == key.H:
  552.         is_local = not is_local
  553.     elif symbol == key.G:
  554.         is_animated = not is_animated
  555.     elif symbol == key.F:
  556.         is_lighted = not is_lighted
  557.     elif symbol == key.M:
  558.         is_textured = not is_textured
  559.  
  560.     resetPoints(0)
  561.  
  562.  
  563. glfw.init()
  564. lastTime = glfw.get_time()
  565. nbFrames = 0
  566. summa = 0
  567. count = 0.0
  568.  
  569.  
  570. def calc_fps(dt):
  571.     global lastTime, nbFrames, summa, count
  572.     currentTime = glfw.get_time()
  573.     nbFrames += 1
  574.     if currentTime - lastTime >= 1.0:
  575.         summa += nbFrames
  576.         count += 1.0
  577.         print(nbFrames, summa / count, count)
  578.         nbFrames = 0
  579.         lastTime += 1.0
  580.  
  581.  
  582. resetPoints(0)
  583. if is_animated:
  584.     pyglet.clock.schedule_interval(resetPoints, 1.0 / 60)
  585. pyglet.clock.schedule(calc_fps)
  586. pyglet.app.run()
Add Comment
Please, Sign In to add comment