# Path: PyOpenGLng/HighLevelApi/PrimitiveVertexArray.py
# class TriangleVertexArray(GlVertexArrayObject):
# 
#     """ Base class to draw primitives as triangles. """
# 
#     # Fixme: 3d
# 
#     ##############################################
# 
#     def __init__(self, items=None):
# 
#         super(TriangleVertexArray, self).__init__()
# 
#         self._number_of_items = 0
#         self._positions_buffer = GlArrayBuffer()
#         self._normals_buffer = GlArrayBuffer()
#         self._colours_buffer = GlArrayBuffer()
# 
#         if items is not None:
#             self.set(*items)
# 
#     ##############################################
# 
#     def set(self, positions, normals, colours):
# 
#         """ Set the vertex array from an iterable of triangles. """
# 
#         self._number_of_items = positions.shape[0]
# 
#         # Fixme:
#         #  - set from high level primitive: slow
#         #  - set from Numpy array: fast but check for mistake
# 
#         # vertex = np.zeros((self._number_of_objects, 3), dtype='f') # dtype=np.float
# 
#         self._positions_buffer.set(positions)
#         self._normals_buffer.set(normals)
#         self._colours_buffer.set(colours)
# 
#     ##############################################
# 
#     def bind_to_shader(self, shader_program_interface):
# 
#         """ Bind the vertex array to the shader program interface attribute.
#         """
# 
#         # Fixme: we cannot reuse the vbo
# 
#         self.bind()
#         shader_program_interface.position.bind_to_buffer(self._positions_buffer)
#         shader_program_interface.normal.bind_to_buffer(self._normals_buffer)
#         shader_program_interface.colour.bind_to_buffer(self._colours_buffer)
#         self.unbind()
# 
#     ##############################################
# 
#     def draw(self):
# 
#         """ Draw the vertex array as lines. """
# 
#         self.bind()
#         GL.glDrawArrays(GL.GL_TRIANGLES, 0, 3*self._number_of_items)
#         self.unbind()


import math
import numpy as np
from .PrimitiveVertexArray import TriangleVertexArray
        for inclination in np.arange(0., 2*math.pi, inclination_step):
            next_inclination = inclination + inclination_step
            next_azymuth = azymuth + azymuth_step
            vertex1 = torus_to_cartesian(radius, section_radius, inclination, azymuth)
            vertex2 = torus_to_cartesian(radius, section_radius, next_inclination, azymuth)
            vertex3 = torus_to_cartesian(radius, section_radius, inclination, next_azymuth)
            vertex4 = torus_to_cartesian(radius, section_radius, next_inclination, next_azymuth)
            vertexes.append(vertex1)
            vertexes.append(vertex2)
            vertexes.append(vertex3)
            vertexes.append(vertex3)
            vertexes.append(vertex2)
            vertexes.append(vertex4)

    positions = np.array(vertexes, dtype=np.float32)

    return positions, compute_normals(positions)

####################################################################################################

def torus(radius):

    # Fixme: scale!

    positions, normals = unit_torus()

    colour = (1, 0, 0, 1)
    colours = np.zeros((positions.shape[0], 4), dtype=np.float32)
    colours[...] = colour


# Path: PyOpenGLng/HighLevelApi/PrimitiveVertexArray.py
# class TriangleVertexArray(GlVertexArrayObject):
# 
#     """ Base class to draw primitives as triangles. """
# 
#     # Fixme: 3d
# 
#     ##############################################
# 
#     def __init__(self, items=None):
# 
#         super(TriangleVertexArray, self).__init__()
# 
#         self._number_of_items = 0
#         self._positions_buffer = GlArrayBuffer()
#         self._normals_buffer = GlArrayBuffer()
#         self._colours_buffer = GlArrayBuffer()
# 
#         if items is not None:
#             self.set(*items)
# 
#     ##############################################
# 
#     def set(self, positions, normals, colours):
# 
#         """ Set the vertex array from an iterable of triangles. """
# 
#         self._number_of_items = positions.shape[0]
# 
#         # Fixme:
#         #  - set from high level primitive: slow
#         #  - set from Numpy array: fast but check for mistake
# 
#         # vertex = np.zeros((self._number_of_objects, 3), dtype='f') # dtype=np.float
# 
#         self._positions_buffer.set(positions)
#         self._normals_buffer.set(normals)
#         self._colours_buffer.set(colours)
# 
#     ##############################################
# 
#     def bind_to_shader(self, shader_program_interface):
# 
#         """ Bind the vertex array to the shader program interface attribute.
#         """
# 
#         # Fixme: we cannot reuse the vbo
# 
#         self.bind()
#         shader_program_interface.position.bind_to_buffer(self._positions_buffer)
#         shader_program_interface.normal.bind_to_buffer(self._normals_buffer)
#         shader_program_interface.colour.bind_to_buffer(self._colours_buffer)
#         self.unbind()
# 
#     ##############################################
# 
#     def draw(self):
# 
#         """ Draw the vertex array as lines. """
# 
#         self.bind()
#         GL.glDrawArrays(GL.GL_TRIANGLES, 0, 3*self._number_of_items)
#         self.unbind()


# Path: PyOpenGLng/HighLevelApi/Solids.py
import math
import numpy as np
from .PrimitiveVertexArray import TriangleVertexArray

        for inclination in np.arange(0., 2*math.pi, inclination_step):
            next_inclination = inclination + inclination_step
            next_azymuth = azymuth + azymuth_step
            vertex1 = torus_to_cartesian(radius, section_radius, inclination, azymuth)
            vertex2 = torus_to_cartesian(radius, section_radius, next_inclination, azymuth)
            vertex3 = torus_to_cartesian(radius, section_radius, inclination, next_azymuth)
            vertex4 = torus_to_cartesian(radius, section_radius, next_inclination, next_azymuth)
            vertexes.append(vertex1)
            vertexes.append(vertex2)
            vertexes.append(vertex3)
            vertexes.append(vertex3)
            vertexes.append(vertex2)
            vertexes.append(vertex4)

    positions = np.array(vertexes, dtype=np.float32)

    return positions, compute_normals(positions)

####################################################################################################

def torus(radius):

    # Fixme: scale!

    positions, normals = unit_torus()

    colour = (1, 0, 0, 1)
    colours = np.zeros((positions.shape[0], 4), dtype=np.float32)
    colours[...] = colour


    return TriangleVertexArray((positions, normals, colours))